|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SMW\Notifications\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\DataTypeRegistry; |
|
6
|
|
|
use SMW\DIWikiPage; |
|
7
|
|
|
use SMW\Notifications\HookRegistry; |
|
8
|
|
|
use SMW\PropertyRegistry; |
|
9
|
|
|
use SMW\SemanticData; |
|
10
|
|
|
use SMW\SQLStore\CompositePropertyTableDiffIterator; |
|
11
|
|
|
use SMWSQLStore3; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @covers \SMW\Notifications\HookRegistry |
|
15
|
|
|
* @group semantic-notifications |
|
16
|
|
|
* |
|
17
|
|
|
* @license GNU GPL v2+ |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author mwjames |
|
21
|
|
|
*/ |
|
22
|
|
|
class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
|
23
|
|
|
|
|
24
|
|
|
public function testRegister() { |
|
25
|
|
|
|
|
26
|
|
|
$instance = new HookRegistry(); |
|
27
|
|
|
$instance->register(); |
|
28
|
|
|
|
|
29
|
|
|
$this->doTestRegisteredSMWPropertyInitProperties( $instance ); |
|
30
|
|
|
$this->doTestRegisteredSMWDataTypeInitTypes( $instance ); |
|
31
|
|
|
$this->doTestRegisteredUserGetDefaultOptions( $instance ); |
|
32
|
|
|
$this->doTestRegisteredBeforeCreateEchoEvent( $instance ); |
|
33
|
|
|
$this->doTestRegisteredEchoGetBundleRules( $instance ); |
|
34
|
|
|
$this->doTestRegisteredEchoGetDefaultNotifiedUsers( $instance ); |
|
35
|
|
|
$this->doTestRegisteredSMWSQLStoreAfterDataUpdateComplete( $instance ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function doTestRegisteredSMWPropertyInitProperties( $instance ) { |
|
39
|
|
|
|
|
40
|
|
|
$handler = 'SMW::Property::initProperties'; |
|
41
|
|
|
|
|
42
|
|
|
$propertyRegistry = $this->getMockBuilder( PropertyRegistry::class ) |
|
43
|
|
|
->disableOriginalConstructor() |
|
44
|
|
|
->getMock(); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertTrue( |
|
47
|
|
|
$instance->isRegistered( $handler ) |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertThatHookIsExcutable( |
|
51
|
|
|
$instance->getHandlerFor( $handler ), |
|
52
|
|
|
array( $propertyRegistry ) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function doTestRegisteredSMWDataTypeInitTypes( $instance ) { |
|
57
|
|
|
|
|
58
|
|
|
$handler = 'SMW::DataType::initTypes'; |
|
59
|
|
|
|
|
60
|
|
|
$dataTypeRegistry = $this->getMockBuilder( DataTypeRegistry::class ) |
|
61
|
|
|
->disableOriginalConstructor() |
|
62
|
|
|
->getMock(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertTrue( |
|
65
|
|
|
$instance->isRegistered( $handler ) |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertThatHookIsExcutable( |
|
69
|
|
|
$instance->getHandlerFor( $handler ), |
|
70
|
|
|
array( $dataTypeRegistry ) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function doTestRegisteredUserGetDefaultOptions( $instance ) { |
|
75
|
|
|
|
|
76
|
|
|
$handler = 'UserGetDefaultOptions'; |
|
77
|
|
|
|
|
78
|
|
|
$this->assertTrue( |
|
79
|
|
|
$instance->isRegistered( $handler ) |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$defaultOptions = array(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertThatHookIsExcutable( |
|
85
|
|
|
$instance->getHandlerFor( $handler ), |
|
86
|
|
|
array( &$defaultOptions ) |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertNotEmpty( |
|
90
|
|
|
$defaultOptions |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function doTestRegisteredBeforeCreateEchoEvent( $instance ) { |
|
95
|
|
|
|
|
96
|
|
|
$handler = 'BeforeCreateEchoEvent'; |
|
97
|
|
|
|
|
98
|
|
|
$this->assertTrue( |
|
99
|
|
|
$instance->isRegistered( $handler ) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$notifications = array(); |
|
103
|
|
|
$notificationCategories = array(); |
|
104
|
|
|
$icons = array(); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertThatHookIsExcutable( |
|
107
|
|
|
$instance->getHandlerFor( $handler ), |
|
108
|
|
|
array( &$notifications, &$notificationCategories, &$icons ) |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertNotEmpty( |
|
112
|
|
|
$notifications |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
$this->assertNotEmpty( |
|
116
|
|
|
$notificationCategories |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertNotEmpty( |
|
120
|
|
|
$icons |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function doTestRegisteredEchoGetBundleRules( $instance ) { |
|
125
|
|
|
|
|
126
|
|
|
$handler = 'EchoGetBundleRules'; |
|
127
|
|
|
|
|
128
|
|
|
$this->assertTrue( |
|
129
|
|
|
$instance->isRegistered( $handler ) |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
$echoEvent = $this->getMockBuilder( \EchoEvent::class ) |
|
133
|
|
|
->disableOriginalConstructor() |
|
134
|
|
|
->getMock(); |
|
135
|
|
|
|
|
136
|
|
|
$bundleString = ''; |
|
137
|
|
|
|
|
138
|
|
|
$this->assertThatHookIsExcutable( |
|
139
|
|
|
$instance->getHandlerFor( $handler ), |
|
140
|
|
|
array( $echoEvent, &$bundleString ) |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function doTestRegisteredEchoGetDefaultNotifiedUsers( $instance ) { |
|
145
|
|
|
|
|
146
|
|
|
$handler = 'EchoGetDefaultNotifiedUsers'; |
|
147
|
|
|
|
|
148
|
|
|
$this->assertTrue( |
|
149
|
|
|
$instance->isRegistered( $handler ) |
|
150
|
|
|
); |
|
151
|
|
|
|
|
152
|
|
|
$echoEvent = $this->getMockBuilder( \EchoEvent::class ) |
|
153
|
|
|
->disableOriginalConstructor() |
|
154
|
|
|
->getMock(); |
|
155
|
|
|
|
|
156
|
|
|
$users = array(); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertThatHookIsExcutable( |
|
159
|
|
|
$instance->getHandlerFor( $handler ), |
|
160
|
|
|
array( $echoEvent, &$users ) |
|
161
|
|
|
); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function doTestRegisteredSMWSQLStoreAfterDataUpdateComplete( $instance ) { |
|
165
|
|
|
|
|
166
|
|
|
$handler = 'SMW::SQLStore::AfterDataUpdateComplete'; |
|
167
|
|
|
|
|
168
|
|
|
$this->assertTrue( |
|
169
|
|
|
$instance->isRegistered( $handler ) |
|
170
|
|
|
); |
|
171
|
|
|
|
|
172
|
|
|
$subject = $this->getMockBuilder( DIWikiPage::class ) |
|
173
|
|
|
->disableOriginalConstructor() |
|
174
|
|
|
->getMock(); |
|
175
|
|
|
|
|
176
|
|
|
$store = $this->getMockBuilder( SMWSQLStore3::class ) |
|
177
|
|
|
->disableOriginalConstructor() |
|
178
|
|
|
->getMock(); |
|
179
|
|
|
|
|
180
|
|
|
$semanticData = $this->getMockBuilder( SemanticData::class ) |
|
181
|
|
|
->disableOriginalConstructor() |
|
182
|
|
|
->getMock(); |
|
183
|
|
|
|
|
184
|
|
|
$semanticData->expects( $this->once() ) |
|
185
|
|
|
->method( 'getSubject' ) |
|
186
|
|
|
->will( $this->returnValue( $subject ) ); |
|
187
|
|
|
|
|
188
|
|
|
$compositePropertyTableDiffIterator = $this->getMockBuilder( CompositePropertyTableDiffIterator::class ) |
|
189
|
|
|
->disableOriginalConstructor() |
|
190
|
|
|
->getMock(); |
|
191
|
|
|
|
|
192
|
|
|
$this->assertThatHookIsExcutable( |
|
193
|
|
|
$instance->getHandlerFor( $handler ), |
|
194
|
|
|
array( $store, $semanticData, $compositePropertyTableDiffIterator ) |
|
195
|
|
|
); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
|
199
|
|
|
$this->assertInternalType( |
|
200
|
|
|
'boolean', |
|
201
|
|
|
call_user_func_array( $handler, $arguments ) |
|
202
|
|
|
); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|