forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasFilter.php
More file actions
93 lines (74 loc) · 2.69 KB
/
hasFilter.php
File metadata and controls
93 lines (74 loc) · 2.69 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Test the has_filter method of WP_Hook
*
* @group hooks
* @covers WP_Hook::has_filter
*/
class Tests_Hooks_HasFilter extends WP_UnitTestCase {
/**
* @ticket 64186
*/
public function test_has_filter_with_function() {
$callback = '__return_null';
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$priority_a = 1;
$priority_b = 10;
$accepted_args = 2;
$hook->add_filter( $hook_name, $callback, $priority_a, $accepted_args );
$hook->add_filter( $hook_name, $callback, $priority_b, $accepted_args );
$this->assertSame( $priority_a, $hook->has_filter( $hook_name, $callback ) );
$this->assertTrue( $hook->has_filter( $hook_name, $callback, $priority_a ) );
$this->assertTrue( $hook->has_filter( $hook_name, $callback, $priority_b ) );
$hook->remove_filter( $hook_name, $callback, $priority_a );
$this->assertSame( $priority_b, $hook->has_filter( $hook_name, $callback ) );
}
public function test_has_filter_with_object() {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$priority = 1;
$accepted_args = 2;
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
$this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
}
public function test_has_filter_with_static_method() {
$callback = array( 'MockAction', 'action' );
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$priority = 1;
$accepted_args = 2;
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
$this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
}
public function test_has_filter_without_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$priority = 1;
$accepted_args = 2;
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
$this->assertTrue( $hook->has_filter() );
}
public function test_not_has_filter_without_callback() {
$hook = new WP_Hook();
$this->assertFalse( $hook->has_filter() );
}
public function test_not_has_filter_with_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$this->assertFalse( $hook->has_filter( $hook_name, $callback ) );
}
public function test_has_filter_with_wrong_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$hook_name = __FUNCTION__;
$priority = 1;
$accepted_args = 2;
$hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
$this->assertFalse( $hook->has_filter( $hook_name, '__return_false' ) );
}
}