-
Notifications
You must be signed in to change notification settings - Fork 3
/
PluginFiltersTest.php
123 lines (91 loc) · 3.22 KB
/
PluginFiltersTest.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
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Tests\Unit;
use Codice\Plugins\Filter;
use Tests\TestCase;
class PluginFiltersTest extends TestCase
{
public function testSingleFilter()
{
Filter::register('test.hook', 'test_filter', function($value) {
return $value;
});
$output = Filter::call('test.hook', 'test');
$this->assertEquals('test', $output);
}
public function testMultipleFilters()
{
Filter::register('test.hook1', 'first_filter', function($value) {
return str_replace('test', 'hello', $value);
}, 1);
Filter::register('test.hook1', 'second_filter', function($value) {
return $value = $value . ', world!';
}, 2);
Filter::register('test.hook1', 'third_filter', function($value) {
return strtoupper($value);
}, 3);
$output = Filter::call('test.hook1', 'test');
$this->assertEquals('HELLO, WORLD!', $output);
}
public function testSortingFilters()
{
Filter::register('test.hook2', 'second_filter', function($value) {
return 'foobar';
}, 4);
Filter::register('test.hook2', 'first_filter', function($value) {
return strtolower($value);
}, 1);
$output = Filter::call('test.hook2', 'test');
$this->assertEquals('foobar', $output);
}
public function testDuplicatedFilterNames()
{
Filter::register('test.hook4', 'filter', function($value) {
return strtolower($value);
});
Filter::register('test.hook4', 'filter', function($value) {
return strrev($value);
});
$output = Filter::call('test.hook4', 'tEsT');
$this->assertEquals('TsEt', $output);
}
public function testFilterNameUniquenessPerHook()
{
Filter::register('test.hook5', 'filter', function($value) {
return strtolower($value);
});
Filter::register('test.hook6', 'filter', function($value) {
return strtoupper($value);
});
$firstOutput = Filter::call('test.hook5', 'tEsT');
$secondOutput = Filter::call('test.hook6', 'tEsT');
$this->assertEquals('test', $firstOutput);
$this->assertEquals('TEST', $secondOutput);
}
public function testCallingHookWithNoFilters()
{
$output = Filter::call('test.hook7', 'test value');
$this->assertEquals('test value', $output);
}
public function testDeregisteringFilters()
{
Filter::register('test.hook8', 'first_filter', function($value) {
return strrev($value);
});
Filter::register('test.hook8', 'second_filter', function($value) {
return strtoupper($value);
});
Filter::deregister('test.hook8', 'second_filter');
$output = Filter::call('test.hook8', 'test');
$this->assertEquals('tset', $output);
}
public function testFiltersWithParameters()
{
Filter::register('test.hook9', 'first_filter', function($value, $parameters) {
return $value . $parameters['one'];
});
$output = Filter::call('test.hook9', 'test', [
'one' => 'ABC',
]);
$this->assertEquals('testABC', $output);
}
}