Completed
Push — renovate/copy-webpack-plugin-7... ( 1bd716...8ac6ba )
by
unknown
312:57 queued 302:49
created

HookManagerTest::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
// We live in the namespace of the test autoloader to avoid many use statements.
9
namespace Automattic\Jetpack\Autoloader\jpCurrent;
10
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * Provides unit tests for the methods in the Hook_Manager class.
15
 */
16
class HookManagerTest extends TestCase {
17
18
	/**
19
	 * The hook manager we're testing.
20
	 *
21
	 * @var Hook_Manager
22
	 */
23
	private $hook_manager;
24
25
	/**
26
	 * Setup runs before each test.
27
	 *
28
	 * @before
29
	 */
30
	public function set_up() {
31
		$this->hook_manager = new Hook_Manager();
32
	}
33
34
	/**
35
	 * Teardown runs after each test.
36
	 *
37
	 * @after
38
	 */
39
	public function tear_down() {
40
		cleanup_test_wordpress_data();
41
	}
42
43
	/**
44
	 * Tests that the hook manager can add actions.
45
	 */
46 View Code Duplication
	public function test_adds_action() {
47
		$callable = function () {};
48
49
		$this->hook_manager->add_action( 'test', $callable, 11, 12 );
50
51
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
52
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
53
	}
54
55
	/**
56
	 * Tests that the hook manager can add filters.
57
	 */
58 View Code Duplication
	public function test_adds_filters() {
59
		$callable = function () {};
60
61
		$this->hook_manager->add_filter( 'test', $callable, 11, 12 );
62
63
		$this->assertFalse( test_has_filter( 'test', $callable, 10, 12 ) );
64
		$this->assertTrue( test_has_filter( 'test', $callable, 11, 12 ) );
65
	}
66
67
	/**
68
	 * Tests that the hook manager removes hooks on reset.
69
	 */
70
	public function test_resets() {
71
		$callable = function () {};
72
73
		$this->hook_manager->add_filter( 'test', $callable );
74
75
		$this->assertTrue( test_has_filter( 'test', $callable ) );
76
77
		$this->hook_manager->reset();
78
79
		$this->assertFalse( test_has_filter( 'test', $callable ) );
80
	}
81
}
82