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 ); - } -}