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
This commit is contained in:
parent
5bcee9e939
commit
4e3e98698f
|
@ -42,6 +42,11 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
||||||
$_SERVER['REMOTE_ADDR'] = '';
|
$_SERVER['REMOTE_ADDR'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
remove_filter( 'query', array( $this, '_block_comments' ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reply as a privilged user (administrator)
|
* Reply as a privilged user (administrator)
|
||||||
* Expects test to pass
|
* Expects test to pass
|
||||||
|
@ -220,7 +225,6 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
||||||
public function _block_comments( $sql ) {
|
public function _block_comments( $sql ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
if ( false !== strpos( $sql, $wpdb->comments ) && 0 === stripos( trim ( $sql ), 'INSERT INTO') ) {
|
if ( false !== strpos( $sql, $wpdb->comments ) && 0 === stripos( trim ( $sql ), 'INSERT INTO') ) {
|
||||||
remove_filter( 'query', array( $this, '_block_comments' ) );
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
|
|
Loading…
Reference in New Issue