Completed
Push — add/e2e-tests-firefox-ci ( 70703c...afc926 )
by Bernhard
85:28 queued 77:03
created

Test_Hook_Manager::set_up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
/**
3
 * The hook manager test suite.
4
 *
5
 * @package automattic/jetpack-autoloader
6
 */
7
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Provides unit tests for the methods in the Hook_Manager class.
12
 */
13
class Test_Hook_Manager extends TestCase {
14
15
	/**
16
	 * The hook manager we're testing.
17
	 *
18
	 * @var Hook_Manager
19
	 */
20
	private $hook_manager;
21
22
	/**
23
	 * Setup runs before each test.
24
	 *
25
	 * @before
26
	 */
27
	public function set_up() {
28
		$this->hook_manager = new Hook_Manager();
29
	}
30
31
	/**
32
	 * Teardown runs after each test.
33
	 *
34
	 * @after
35
	 */
36
	public function tear_down() {
37
		cleanup_test_wordpress_data();
38
	}
39
40
	/**
41
	 * Tests that the hook manager can add actions.
42
	 */
43 View Code Duplication
	public function test_adds_action() {
44
		$callable = function () {};
45
46
		$this->hook_manager->add_action( 'test', $callable, 11, 12 );
47
48
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
49
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
50
	}
51
52
	/**
53
	 * Tests that the hook manager can add filters.
54
	 */
55 View Code Duplication
	public function test_adds_filters() {
56
		$callable = function () {};
57
58
		$this->hook_manager->add_filter( 'test', $callable, 11, 12 );
59
60
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
61
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
62
	}
63
64
	/**
65
	 * Tests that the hook manager removes hooks on reset.
66
	 */
67
	public function test_resets() {
68
		$callable = function () {};
69
70
		$this->hook_manager->add_filter( 'test', $callable );
71
72
		$this->assertTrue( test_has_filter( 'test', $callable ) );
73
74
		$this->hook_manager->reset();
75
76
		$this->assertFalse( test_has_filter( 'test', $callable ) );
77
	}
78
}
79