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
83 lines (64 loc) · 2.31 KB
/
hasFilter.php
File metadata and controls
83 lines (64 loc) · 2.31 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
<?php
/**
* Test the has_filter method of WP_Hook
*
* @group hooks
*/
class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_has_filter_with_function() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
}
public function test_has_filter_with_object() {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
}
public function test_has_filter_with_static_method() {
$callback = array( 'MockAction', 'action' );
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$this->assertEquals( $priority, $hook->has_filter( $tag, $callback ) );
}
public function test_has_filter_without_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $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();
$tag = __FUNCTION__;
$this->assertFalse( $hook->has_filter( $tag, $callback ) );
}
public function test_has_filter_with_wrong_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$this->assertFalse( $hook->has_filter( $tag, '__return_false' ) );
}
}