mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Plugins: Convert apply_filters() into a proper variadic function.
This makes its signature more correct by implementing the spread operator, and adjusts the internal logic correspondingly without affecting performance. Props jrf, SergeyBiryukov, davidbaumwald, mauriac, johnbillion Fixes #53218 git-svn-id: https://develop.svn.wordpress.org/trunk@52952 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -215,6 +215,49 @@ class Tests_Filters extends WP_UnitTestCase {
|
||||
$this->assertFalse( has_filter( $tag ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 53218
|
||||
*/
|
||||
public function test_filter_with_ref_value() {
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
|
||||
add_action( $tag, array( $a, 'filter' ) );
|
||||
|
||||
$filtered = apply_filters( $tag, $ref );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][0], $obj );
|
||||
$this->assertSame( $filtered, $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertNotEmpty( $args[0][0]->foo );
|
||||
$this->assertNotEmpty( $filtered->foo );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 53218
|
||||
*/
|
||||
public function test_filter_with_ref_argument() {
|
||||
$obj = new stdClass();
|
||||
$ref = &$obj;
|
||||
$a = new MockAction();
|
||||
$tag = __FUNCTION__;
|
||||
$val = 'Hello';
|
||||
|
||||
add_action( $tag, array( $a, 'filter' ), 10, 2 );
|
||||
|
||||
apply_filters( $tag, $val, $ref );
|
||||
|
||||
$args = $a->get_args();
|
||||
$this->assertSame( $args[0][1], $obj );
|
||||
// Just in case we don't trust assertSame().
|
||||
$obj->foo = true;
|
||||
$this->assertNotEmpty( $args[0][1]->foo );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 9886
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user