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
This commit is contained in:
Sergey Biryukov 2022-07-31 16:41:53 +00:00
parent ebd66f9aed
commit cd7a7924cb
2 changed files with 36 additions and 46 deletions

View File

@ -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 );
}
/**

View File

@ -1,46 +0,0 @@
<?php
/**
* Test do_action() and related functions
*
* @group hooks
*/
class Tests_Actions_Closures extends WP_UnitTestCase {
/**
* @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 );
}
}