From cd7a7924cb79b170630963b7d6a8d3fecc8487cf Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 31 Jul 2022 16:41:53 +0000 Subject: [PATCH] Tests: Move the test for actions using closures to the general action tests file. This was previously moved to a separate file to be excluded when running the tests on PHP 5.2.x. Now that WordPress supports PHP 5.6.x or later, this can be moved back with the other action tests. Follow-up to [299/tests], [301/tests], [862/tests], [866/tests], [963/tests]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@53806 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/actions.php | 36 +++++++++++++++++++ tests/phpunit/tests/actions/closures.php | 46 ------------------------ 2 files changed, 36 insertions(+), 46 deletions(-) delete mode 100644 tests/phpunit/tests/actions/closures.php diff --git a/tests/phpunit/tests/actions.php b/tests/phpunit/tests/actions.php index b628964d70..e3cfa48ed2 100644 --- a/tests/phpunit/tests/actions.php +++ b/tests/phpunit/tests/actions.php @@ -351,7 +351,43 @@ class Tests_Actions extends WP_UnitTestCase { $args = $a->get_args(); $this->assertSame( $args[1][0], $context2 ); + } + /** + * @ticket 10493 + * + * @covers ::add_action + * @covers ::has_action + * @covers ::do_action + */ + public function test_action_closure() { + $hook_name = 'test_action_closure'; + $closure = static function( $a, $b ) { + $GLOBALS[ $a ] = $b; + }; + add_action( $hook_name, $closure, 10, 2 ); + + $this->assertSame( 10, has_action( $hook_name, $closure ) ); + + $context = array( 'val1', 'val2' ); + do_action( $hook_name, $context[0], $context[1] ); + + $this->assertSame( $GLOBALS[ $context[0] ], $context[1] ); + + $hook_name2 = 'test_action_closure_2'; + $closure2 = static function() { + $GLOBALS['closure_no_args'] = true; + }; + add_action( $hook_name2, $closure2 ); + + $this->assertSame( 10, has_action( $hook_name2, $closure2 ) ); + + do_action( $hook_name2 ); + + $this->assertTrue( $GLOBALS['closure_no_args'] ); + + remove_action( $hook_name, $closure ); + remove_action( $hook_name2, $closure2 ); } /** diff --git a/tests/phpunit/tests/actions/closures.php b/tests/phpunit/tests/actions/closures.php deleted file mode 100644 index f56471c967..0000000000 --- a/tests/phpunit/tests/actions/closures.php +++ /dev/null @@ -1,46 +0,0 @@ -assertSame( 10, has_action( $hook_name, $closure ) ); - - $context = array( 'val1', 'val2' ); - do_action( $hook_name, $context[0], $context[1] ); - - $this->assertSame( $GLOBALS[ $context[0] ], $context[1] ); - - $hook_name2 = 'test_action_closure_2'; - $closure2 = static function() { - $GLOBALS['closure_no_args'] = true; - }; - add_action( $hook_name2, $closure2 ); - - $this->assertSame( 10, has_action( $hook_name2, $closure2 ) ); - - do_action( $hook_name2 ); - - $this->assertTrue( $GLOBALS['closure_no_args'] ); - - remove_action( $hook_name, $closure ); - remove_action( $hook_name2, $closure2 ); - } -}