1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL\Tests; |
4
|
|
|
|
5
|
|
|
use SIL\HookRegistry; |
6
|
|
|
use Title; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SIL\HookRegistry |
10
|
|
|
* @group semantic-interlanguage-links |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $cache; |
20
|
|
|
private $store; |
21
|
|
|
private $cacheKeyProvider; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->getMockForAbstractClass(); |
29
|
|
|
|
30
|
|
|
$this->cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMockForAbstractClass(); |
33
|
|
|
|
34
|
|
|
$this->cacheKeyProvider = $this->getMockBuilder( '\SIL\CacheKeyProvider' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMockForAbstractClass(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testCanConstruct() { |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf( |
42
|
|
|
'\SIL\HookRegistry', |
43
|
|
|
new HookRegistry( $this->store, $this->cache, $this->cacheKeyProvider ) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testRegister() { |
48
|
|
|
|
49
|
|
|
$title = Title::newFromText( __METHOD__ ); |
50
|
|
|
|
51
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
52
|
|
|
->disableOriginalConstructor() |
53
|
|
|
->getMock(); |
54
|
|
|
|
55
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->getMock(); |
58
|
|
|
|
59
|
|
|
$parser->expects( $this->any() ) |
60
|
|
|
->method( 'getTitle' ) |
61
|
|
|
->will( $this->returnValue( $title ) ); |
62
|
|
|
|
63
|
|
|
$parser->expects( $this->any() ) |
64
|
|
|
->method( 'getOutput' ) |
65
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
66
|
|
|
|
67
|
|
|
$instance = new HookRegistry( $this->store, $this->cache, $this->cacheKeyProvider ); |
68
|
|
|
$instance->register(); |
69
|
|
|
|
70
|
|
|
$this->doTestParserFirstCallInit( $instance, $parser ); |
71
|
|
|
$this->doTestNewRevisionFromEditComplete( $instance ); |
72
|
|
|
$this->doTestSkinTemplateGetLanguageLink( $instance ); |
73
|
|
|
$this->doTestPageContentLanguage( $instance ); |
74
|
|
|
$this->doTestArticleFromTitle( $instance ); |
75
|
|
|
$this->doTestArticlePurge( $instance ); |
76
|
|
|
$this->doTestParserAfterTidy( $instance, $parser ); |
77
|
|
|
|
78
|
|
|
$this->doTestInitProperties( $instance ); |
79
|
|
|
$this->doTestSQLStoreBeforeDeleteSubjectCompletes( $instance ); |
80
|
|
|
$this->doTestSQLStoreBeforeChangeTitleComplete( $instance ); |
81
|
|
|
|
82
|
|
|
$this->doTestSpecialSearchProfiles( $instance ); |
83
|
|
|
$this->doTestSpecialSearchProfileForm( $instance ); |
84
|
|
|
$this->doTestSpecialSearchResults( $instance ); |
85
|
|
|
$this->doTestSpecialSearchSetupEngine( $instance ); |
86
|
|
|
$this->doTestSpecialSearchPowerBox( $instance ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function doTestParserFirstCallInit( $instance, $parser ) { |
90
|
|
|
|
91
|
|
|
$handler = 'ParserFirstCallInit'; |
92
|
|
|
|
93
|
|
|
$this->assertTrue( |
94
|
|
|
$instance->isRegistered( $handler ) |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
$this->assertThatHookIsExcutable( |
98
|
|
|
$instance->getHandlerFor( $handler ), |
99
|
|
|
array( &$parser ) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function doTestNewRevisionFromEditComplete( $instance ) { |
104
|
|
|
|
105
|
|
|
$handler = 'NewRevisionFromEditComplete'; |
106
|
|
|
|
107
|
|
|
$title = Title::newFromText( __METHOD__ ); |
108
|
|
|
|
109
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
110
|
|
|
->disableOriginalConstructor() |
111
|
|
|
->getMock(); |
112
|
|
|
|
113
|
|
|
$wikipage->expects( $this->any() ) |
114
|
|
|
->method( 'getTitle' ) |
115
|
|
|
->will( $this->returnValue( $title ) ); |
116
|
|
|
|
117
|
|
|
$this->assertTrue( |
118
|
|
|
$instance->isRegistered( $handler ) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->assertThatHookIsExcutable( |
122
|
|
|
$instance->getHandlerFor( $handler ), |
123
|
|
|
array( $wikipage ) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function doTestArticlePurge( $instance ) { |
128
|
|
|
|
129
|
|
|
$handler = 'ArticlePurge'; |
130
|
|
|
|
131
|
|
|
$title = Title::newFromText( __METHOD__ ); |
132
|
|
|
|
133
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
134
|
|
|
->disableOriginalConstructor() |
135
|
|
|
->getMock(); |
136
|
|
|
|
137
|
|
|
$wikipage->expects( $this->any() ) |
138
|
|
|
->method( 'getTitle' ) |
139
|
|
|
->will( $this->returnValue( $title ) ); |
140
|
|
|
|
141
|
|
|
$this->assertTrue( |
142
|
|
|
$instance->isRegistered( $handler ) |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$this->assertThatHookIsExcutable( |
146
|
|
|
$instance->getHandlerFor( $handler ), |
147
|
|
|
array( &$wikipage ) |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function doTestSkinTemplateGetLanguageLink( $instance ) { |
152
|
|
|
|
153
|
|
|
$handler = 'SkinTemplateGetLanguageLink'; |
154
|
|
|
|
155
|
|
|
$title = Title::newFromText( __METHOD__ ); |
156
|
|
|
$languageLink = array(); |
157
|
|
|
|
158
|
|
|
$this->assertTrue( |
159
|
|
|
$instance->isRegistered( $handler ) |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$this->assertThatHookIsExcutable( |
163
|
|
|
$instance->getHandlerFor( $handler ), |
164
|
|
|
array( &$languageLink, $title, $title ) |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function doTestPageContentLanguage( $instance ) { |
169
|
|
|
|
170
|
|
|
$handler = 'PageContentLanguage'; |
171
|
|
|
$pageLang = ''; |
172
|
|
|
|
173
|
|
|
$title = Title::newFromText( __METHOD__ ); |
174
|
|
|
|
175
|
|
|
$this->assertTrue( |
176
|
|
|
$instance->isRegistered( $handler ) |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
$this->assertThatHookIsExcutable( |
180
|
|
|
$instance->getHandlerFor( $handler ), |
181
|
|
|
array( $title, &$pageLang ) |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function doTestArticleFromTitle( $instance ) { |
186
|
|
|
|
187
|
|
|
$handler = 'ArticleFromTitle'; |
188
|
|
|
|
189
|
|
|
$title = Title::newFromText( __METHOD__ ); |
190
|
|
|
$page = ''; |
191
|
|
|
|
192
|
|
|
$this->assertTrue( |
193
|
|
|
$instance->isRegistered( $handler ) |
194
|
|
|
); |
195
|
|
|
|
196
|
|
|
$this->assertThatHookIsExcutable( |
197
|
|
|
$instance->getHandlerFor( $handler ), |
198
|
|
|
array( $title, &$page ) |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function doTestParserAfterTidy( $instance, $parser ) { |
203
|
|
|
|
204
|
|
|
$handler = 'ParserAfterTidy'; |
205
|
|
|
$text = ''; |
206
|
|
|
|
207
|
|
|
$this->assertTrue( |
208
|
|
|
$instance->isRegistered( $handler ) |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$this->assertThatHookIsExcutable( |
212
|
|
|
$instance->getHandlerFor( $handler ), |
213
|
|
|
array( &$parser, &$text ) |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function doTestInitProperties( $instance ) { |
218
|
|
|
|
219
|
|
|
$handler = 'SMW::Property::initProperties'; |
220
|
|
|
|
221
|
|
|
$this->assertTrue( |
222
|
|
|
$instance->isRegistered( $handler ) |
223
|
|
|
); |
224
|
|
|
|
225
|
|
|
$this->assertThatHookIsExcutable( |
226
|
|
|
$instance->getHandlerFor( $handler ), |
227
|
|
|
array() |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function doTestSQLStoreBeforeDeleteSubjectCompletes( $instance ) { |
232
|
|
|
|
233
|
|
|
$handler = 'SMW::SQLStore::BeforeDeleteSubjectComplete'; |
234
|
|
|
$title = Title::newFromText( __METHOD__ ); |
235
|
|
|
|
236
|
|
|
$this->assertTrue( |
237
|
|
|
$instance->isRegistered( $handler ) |
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
$this->assertThatHookIsExcutable( |
241
|
|
|
$instance->getHandlerFor( $handler ), |
242
|
|
|
array( $this->store, $title ) |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function doTestSQLStoreBeforeChangeTitleComplete( $instance ) { |
247
|
|
|
|
248
|
|
|
$handler = 'SMW::SQLStore::BeforeChangeTitleComplete'; |
249
|
|
|
$title = Title::newFromText( __METHOD__ ); |
250
|
|
|
|
251
|
|
|
$this->assertTrue( |
252
|
|
|
$instance->isRegistered( $handler ) |
253
|
|
|
); |
254
|
|
|
|
255
|
|
|
$this->assertThatHookIsExcutable( |
256
|
|
|
$instance->getHandlerFor( $handler ), |
257
|
|
|
array( $this->store, $title, $title, 0, 0 ) |
258
|
|
|
); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function doTestSpecialSearchProfiles( $instance ) { |
262
|
|
|
|
263
|
|
|
$handler = 'SpecialSearchProfiles'; |
264
|
|
|
$profiles = array(); |
265
|
|
|
|
266
|
|
|
$this->assertTrue( |
267
|
|
|
$instance->isRegistered( $handler ) |
268
|
|
|
); |
269
|
|
|
|
270
|
|
|
$this->assertThatHookIsExcutable( |
271
|
|
|
$instance->getHandlerFor( $handler ), |
272
|
|
|
array( &$profiles ) |
273
|
|
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function doTestSpecialSearchProfileForm( $instance ) { |
277
|
|
|
|
278
|
|
|
$handler = 'SpecialSearchProfileForm'; |
279
|
|
|
|
280
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
281
|
|
|
->disableOriginalConstructor() |
282
|
|
|
->getMock(); |
283
|
|
|
|
284
|
|
|
$form = ''; |
285
|
|
|
$profile = ''; |
286
|
|
|
$term = ''; |
287
|
|
|
$opts = array(); |
288
|
|
|
|
289
|
|
|
$this->assertTrue( |
290
|
|
|
$instance->isRegistered( $handler ) |
291
|
|
|
); |
292
|
|
|
|
293
|
|
|
$this->assertThatHookIsExcutable( |
294
|
|
|
$instance->getHandlerFor( $handler ), |
295
|
|
|
array( $search, &$form, $profile, $term, $opts ) |
296
|
|
|
); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function doTestSpecialSearchResults( $instance ) { |
300
|
|
|
|
301
|
|
|
$handler = 'SpecialSearchResults'; |
302
|
|
|
|
303
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
304
|
|
|
->disableOriginalConstructor() |
305
|
|
|
->getMock(); |
306
|
|
|
|
307
|
|
|
$titleMatches = false; |
308
|
|
|
$textMatches = false; |
309
|
|
|
|
310
|
|
|
$this->assertTrue( |
311
|
|
|
$instance->isRegistered( $handler ) |
312
|
|
|
); |
313
|
|
|
|
314
|
|
|
$this->assertThatHookIsExcutable( |
315
|
|
|
$instance->getHandlerFor( $handler ), |
316
|
|
|
array( $search, &$titleMatches, &$textMatches ) |
317
|
|
|
); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function doTestSpecialSearchSetupEngine( $instance ) { |
321
|
|
|
|
322
|
|
|
$handler = 'SpecialSearchSetupEngine'; |
323
|
|
|
|
324
|
|
|
$profile = array(); |
325
|
|
|
|
326
|
|
|
$request = $this->getMockBuilder( '\WebRequest' ) |
327
|
|
|
->disableOriginalConstructor() |
328
|
|
|
->getMock(); |
329
|
|
|
|
330
|
|
|
$context = $this->getMockBuilder( '\RequestContext' ) |
331
|
|
|
->disableOriginalConstructor() |
332
|
|
|
->getMock(); |
333
|
|
|
|
334
|
|
|
$context->expects( $this->once() ) |
335
|
|
|
->method( 'getRequest' ) |
336
|
|
|
->will( $this->returnValue( $request ) ); |
337
|
|
|
|
338
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
339
|
|
|
->disableOriginalConstructor() |
340
|
|
|
->getMock(); |
341
|
|
|
|
342
|
|
|
$search->expects( $this->once() ) |
343
|
|
|
->method( 'getContext' ) |
344
|
|
|
->will( $this->returnValue( $context ) ); |
345
|
|
|
|
346
|
|
|
$searchEngine = $this->getMockBuilder( '\SearchEngine' ) |
347
|
|
|
->disableOriginalConstructor() |
348
|
|
|
->getMock(); |
349
|
|
|
|
350
|
|
|
$this->assertTrue( |
351
|
|
|
$instance->isRegistered( $handler ) |
352
|
|
|
); |
353
|
|
|
|
354
|
|
|
$this->assertThatHookIsExcutable( |
355
|
|
|
$instance->getHandlerFor( $handler ), |
356
|
|
|
array( $search, $profile, $searchEngine ) |
357
|
|
|
); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
public function doTestSpecialSearchPowerBox( $instance ) { |
361
|
|
|
|
362
|
|
|
$handler = 'SpecialSearchPowerBox'; |
363
|
|
|
$showSections = array(); |
364
|
|
|
|
365
|
|
|
$this->assertTrue( |
366
|
|
|
$instance->isRegistered( $handler ) |
367
|
|
|
); |
368
|
|
|
|
369
|
|
|
$this->assertThatHookIsExcutable( |
370
|
|
|
$instance->getHandlerFor( $handler ), |
371
|
|
|
array( &$showSections, '', array() ) |
372
|
|
|
); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
376
|
|
|
$this->assertInternalType( |
377
|
|
|
'boolean', |
378
|
|
|
call_user_func_array( $handler, $arguments ) |
379
|
|
|
); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
} |
383
|
|
|
|