-
Notifications
You must be signed in to change notification settings - Fork 3
/
PluginActionsTest.php
111 lines (83 loc) · 2.62 KB
/
PluginActionsTest.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Tests\Unit;
use Codice\Plugins\Action;
use Tests\TestCase;
class PluginActionsTest extends TestCase
{
public function testSingleAction()
{
Action::register('test.hook', 'test_action', function() {
echo 'test';
});
$output = $this->getCallOutput('test.hook');
$this->assertEquals('test', $output);
}
public function testSortingActions()
{
Action::register('test.hook2', 'second_action', function() {
echo 'bar';
}, 4);
Action::register('test.hook2', 'first_action', function() {
echo 'foo';
}, 1);
$output = $this->getCallOutput('test.hook2');
$this->assertEquals('foobar', $output);
}
public function testDuplicatedActionNames()
{
Action::register('test.hook4', 'action', function() {
echo '1';
});
Action::register('test.hook4', 'action', function() {
echo '2';
});
$output = $this->getCallOutput('test.hook4');
$this->assertEquals('2', $output);
}
public function testActionNameUniquenessPerHook()
{
Action::register('test.hook5', 'action', function() {
echo 'foo';
});
Action::register('test.hook6', 'action', function() {
echo 'bar';
});
$firstOutput = $this->getCallOutput('test.hook5');
$secondOutput = $this->getCallOutput('test.hook6');
$this->assertEquals('foo', $firstOutput);
$this->assertEquals('bar', $secondOutput);
}
public function testCallingHookWithNoActions()
{
$output = $this->getCallOutput('test.hook7');
$this->assertEquals('', $output);
}
public function testDeregisteringActions()
{
Action::register('test.hook8', 'first_action', function() {
echo 'foo';
});
Action::register('test.hook8', 'second_action', function() {
echo 'bar';
});
Action::deregister('test.hook8', 'second_action');
$output = $this->getCallOutput('test.hook8');
$this->assertEquals('foo', $output);
}
public function testActionsWithParameters()
{
Action::register('test.hook9', 'first_action', function($parameters) {
echo $parameters['one'];
});
$output = $this->getCallOutput('test.hook9', [
'one' => 'foo',
]);
$this->assertEquals('foo', $output);
}
private function getCallOutput($hook, array $parameters = [])
{
ob_start();
Action::call($hook, $parameters);
return ob_get_clean();
}
}