forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosures.php
More file actions
46 lines (36 loc) · 989 Bytes
/
closures.php
File metadata and controls
46 lines (36 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?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
*/
function test_action_closure() {
$tag = 'test_action_closure';
$closure = static function( $a, $b ) {
$GLOBALS[ $a ] = $b;
};
add_action( $tag, $closure, 10, 2 );
$this->assertSame( 10, has_action( $tag, $closure ) );
$context = array( 'val1', 'val2' );
do_action( $tag, $context[0], $context[1] );
$this->assertSame( $GLOBALS[ $context[0] ], $context[1] );
$tag2 = 'test_action_closure_2';
$closure2 = static function() {
$GLOBALS['closure_no_args'] = true;
};
add_action( $tag2, $closure2 );
$this->assertSame( 10, has_action( $tag2, $closure2 ) );
do_action( $tag2 );
$this->assertTrue( $GLOBALS['closure_no_args'] );
remove_action( $tag, $closure );
remove_action( $tag2, $closure2 );
}
}