From 4e3e98698f1518381aaf1a76498f31122ab65d79 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 25 Jan 2015 03:38:10 +0000 Subject: [PATCH] In `Tests_Ajax_ReplytoComment::test_blocked_comment()`, don't stop blocking comments until test is complete. The test uses the `_block_comments()` method to prevent comment inserts from happening. Since [31263], failed comment inserts lead to the comment content's being stripped of invalid characters and inserted again. By immediately unhooking itself after first being run, `_block_comments()` was causing the INSERT block to work only for the first attempt, while the second attempt was going through, causing the test to fail. As a fix, we move the `remove_filter()` call to the class's `tearDown()` method - sufficient for cleanup, but late enough that *all* comment inserts will be blocked for the test method in question. See #21212. Since [31263], comment INSERT queries that were pseudo-bl git-svn-id: https://develop.svn.wordpress.org/trunk@31277 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/ajax/ReplytoComment.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/ajax/ReplytoComment.php b/tests/phpunit/tests/ajax/ReplytoComment.php index 7935bc28da..2b5b404c9a 100644 --- a/tests/phpunit/tests/ajax/ReplytoComment.php +++ b/tests/phpunit/tests/ajax/ReplytoComment.php @@ -42,6 +42,11 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase { $_SERVER['REMOTE_ADDR'] = ''; } + public function tearDown() { + parent::tearDown(); + remove_filter( 'query', array( $this, '_block_comments' ) ); + } + /** * Reply as a privilged user (administrator) * Expects test to pass @@ -220,7 +225,6 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase { public function _block_comments( $sql ) { global $wpdb; if ( false !== strpos( $sql, $wpdb->comments ) && 0 === stripos( trim ( $sql ), 'INSERT INTO') ) { - remove_filter( 'query', array( $this, '_block_comments' ) ); return ''; } return $sql;