|
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 testOnBeforeConfigCompletion() { |
|
90
|
|
|
|
|
91
|
|
|
$config = array( |
|
92
|
|
|
'smwgFulltextSearchPropertyExemptionList' => array() |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$propertyExemptionList = array( |
|
96
|
|
|
'__sil_iwl_lang', |
|
97
|
|
|
'__sil_ill_lang' |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
HookRegistry::onBeforeConfigCompletion( $config ); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertEquals( |
|
103
|
|
|
array( |
|
104
|
|
|
'smwgFulltextSearchPropertyExemptionList' => $propertyExemptionList, |
|
105
|
|
|
), |
|
106
|
|
|
$config |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function doTestParserFirstCallInit( $instance, $parser ) { |
|
111
|
|
|
|
|
112
|
|
|
$handler = 'ParserFirstCallInit'; |
|
113
|
|
|
|
|
114
|
|
|
$this->assertTrue( |
|
115
|
|
|
$instance->isRegistered( $handler ) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertThatHookIsExcutable( |
|
119
|
|
|
$instance->getHandlerFor( $handler ), |
|
120
|
|
|
array( &$parser ) |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function doTestNewRevisionFromEditComplete( $instance ) { |
|
125
|
|
|
|
|
126
|
|
|
$handler = 'NewRevisionFromEditComplete'; |
|
127
|
|
|
|
|
128
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
129
|
|
|
|
|
130
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
|
131
|
|
|
->disableOriginalConstructor() |
|
132
|
|
|
->getMock(); |
|
133
|
|
|
|
|
134
|
|
|
$wikipage->expects( $this->any() ) |
|
135
|
|
|
->method( 'getTitle' ) |
|
136
|
|
|
->will( $this->returnValue( $title ) ); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertTrue( |
|
139
|
|
|
$instance->isRegistered( $handler ) |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertThatHookIsExcutable( |
|
143
|
|
|
$instance->getHandlerFor( $handler ), |
|
144
|
|
|
array( $wikipage ) |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function doTestArticlePurge( $instance ) { |
|
149
|
|
|
|
|
150
|
|
|
$handler = 'ArticlePurge'; |
|
151
|
|
|
|
|
152
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
153
|
|
|
|
|
154
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
|
155
|
|
|
->disableOriginalConstructor() |
|
156
|
|
|
->getMock(); |
|
157
|
|
|
|
|
158
|
|
|
$wikipage->expects( $this->any() ) |
|
159
|
|
|
->method( 'getTitle' ) |
|
160
|
|
|
->will( $this->returnValue( $title ) ); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertTrue( |
|
163
|
|
|
$instance->isRegistered( $handler ) |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
|
|
$this->assertThatHookIsExcutable( |
|
167
|
|
|
$instance->getHandlerFor( $handler ), |
|
168
|
|
|
array( &$wikipage ) |
|
169
|
|
|
); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function doTestSkinTemplateGetLanguageLink( $instance ) { |
|
173
|
|
|
|
|
174
|
|
|
$handler = 'SkinTemplateGetLanguageLink'; |
|
175
|
|
|
|
|
176
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
177
|
|
|
$languageLink = array(); |
|
178
|
|
|
|
|
179
|
|
|
$this->assertTrue( |
|
180
|
|
|
$instance->isRegistered( $handler ) |
|
181
|
|
|
); |
|
182
|
|
|
|
|
183
|
|
|
$this->assertThatHookIsExcutable( |
|
184
|
|
|
$instance->getHandlerFor( $handler ), |
|
185
|
|
|
array( &$languageLink, $title, $title ) |
|
186
|
|
|
); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function doTestPageContentLanguage( $instance ) { |
|
190
|
|
|
|
|
191
|
|
|
$handler = 'PageContentLanguage'; |
|
192
|
|
|
$pageLang = ''; |
|
193
|
|
|
|
|
194
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
195
|
|
|
|
|
196
|
|
|
$this->assertTrue( |
|
197
|
|
|
$instance->isRegistered( $handler ) |
|
198
|
|
|
); |
|
199
|
|
|
|
|
200
|
|
|
$this->assertThatHookIsExcutable( |
|
201
|
|
|
$instance->getHandlerFor( $handler ), |
|
202
|
|
|
array( $title, &$pageLang ) |
|
203
|
|
|
); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function doTestArticleFromTitle( $instance ) { |
|
207
|
|
|
|
|
208
|
|
|
$handler = 'ArticleFromTitle'; |
|
209
|
|
|
|
|
210
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
211
|
|
|
$page = ''; |
|
212
|
|
|
|
|
213
|
|
|
$this->assertTrue( |
|
214
|
|
|
$instance->isRegistered( $handler ) |
|
215
|
|
|
); |
|
216
|
|
|
|
|
217
|
|
|
$this->assertThatHookIsExcutable( |
|
218
|
|
|
$instance->getHandlerFor( $handler ), |
|
219
|
|
|
array( $title, &$page ) |
|
220
|
|
|
); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function doTestParserAfterTidy( $instance, $parser ) { |
|
224
|
|
|
|
|
225
|
|
|
$handler = 'ParserAfterTidy'; |
|
226
|
|
|
$text = ''; |
|
227
|
|
|
|
|
228
|
|
|
$this->assertTrue( |
|
229
|
|
|
$instance->isRegistered( $handler ) |
|
230
|
|
|
); |
|
231
|
|
|
|
|
232
|
|
|
$this->assertThatHookIsExcutable( |
|
233
|
|
|
$instance->getHandlerFor( $handler ), |
|
234
|
|
|
array( &$parser, &$text ) |
|
235
|
|
|
); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
public function doTestInitProperties( $instance ) { |
|
239
|
|
|
|
|
240
|
|
|
$handler = 'SMW::Property::initProperties'; |
|
241
|
|
|
|
|
242
|
|
|
$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' ) |
|
243
|
|
|
->disableOriginalConstructor() |
|
244
|
|
|
->getMock(); |
|
245
|
|
|
|
|
246
|
|
|
$this->assertTrue( |
|
247
|
|
|
$instance->isRegistered( $handler ) |
|
248
|
|
|
); |
|
249
|
|
|
|
|
250
|
|
|
$this->assertThatHookIsExcutable( |
|
251
|
|
|
$instance->getHandlerFor( $handler ), |
|
252
|
|
|
array( $propertyRegistry ) |
|
253
|
|
|
); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public function doTestSQLStoreBeforeDeleteSubjectCompletes( $instance ) { |
|
257
|
|
|
|
|
258
|
|
|
$handler = 'SMW::SQLStore::BeforeDeleteSubjectComplete'; |
|
259
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
260
|
|
|
|
|
261
|
|
|
$this->assertTrue( |
|
262
|
|
|
$instance->isRegistered( $handler ) |
|
263
|
|
|
); |
|
264
|
|
|
|
|
265
|
|
|
$this->assertThatHookIsExcutable( |
|
266
|
|
|
$instance->getHandlerFor( $handler ), |
|
267
|
|
|
array( $this->store, $title ) |
|
268
|
|
|
); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
public function doTestSQLStoreBeforeChangeTitleComplete( $instance ) { |
|
272
|
|
|
|
|
273
|
|
|
$handler = 'SMW::SQLStore::BeforeChangeTitleComplete'; |
|
274
|
|
|
$title = Title::newFromText( __METHOD__ ); |
|
275
|
|
|
|
|
276
|
|
|
$this->assertTrue( |
|
277
|
|
|
$instance->isRegistered( $handler ) |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
$this->assertThatHookIsExcutable( |
|
281
|
|
|
$instance->getHandlerFor( $handler ), |
|
282
|
|
|
array( $this->store, $title, $title, 0, 0 ) |
|
283
|
|
|
); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
public function doTestSpecialSearchProfiles( $instance ) { |
|
287
|
|
|
|
|
288
|
|
|
$handler = 'SpecialSearchProfiles'; |
|
289
|
|
|
$profiles = array(); |
|
290
|
|
|
|
|
291
|
|
|
$this->assertTrue( |
|
292
|
|
|
$instance->isRegistered( $handler ) |
|
293
|
|
|
); |
|
294
|
|
|
|
|
295
|
|
|
$this->assertThatHookIsExcutable( |
|
296
|
|
|
$instance->getHandlerFor( $handler ), |
|
297
|
|
|
array( &$profiles ) |
|
298
|
|
|
); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
public function doTestSpecialSearchProfileForm( $instance ) { |
|
302
|
|
|
|
|
303
|
|
|
$handler = 'SpecialSearchProfileForm'; |
|
304
|
|
|
|
|
305
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
|
306
|
|
|
->disableOriginalConstructor() |
|
307
|
|
|
->getMock(); |
|
308
|
|
|
|
|
309
|
|
|
$form = ''; |
|
310
|
|
|
$profile = ''; |
|
311
|
|
|
$term = ''; |
|
312
|
|
|
$opts = array(); |
|
313
|
|
|
|
|
314
|
|
|
$this->assertTrue( |
|
315
|
|
|
$instance->isRegistered( $handler ) |
|
316
|
|
|
); |
|
317
|
|
|
|
|
318
|
|
|
$this->assertThatHookIsExcutable( |
|
319
|
|
|
$instance->getHandlerFor( $handler ), |
|
320
|
|
|
array( $search, &$form, $profile, $term, $opts ) |
|
321
|
|
|
); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
public function doTestSpecialSearchResults( $instance ) { |
|
325
|
|
|
|
|
326
|
|
|
$handler = 'SpecialSearchResults'; |
|
327
|
|
|
|
|
328
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
|
329
|
|
|
->disableOriginalConstructor() |
|
330
|
|
|
->getMock(); |
|
331
|
|
|
|
|
332
|
|
|
$titleMatches = false; |
|
333
|
|
|
$textMatches = false; |
|
334
|
|
|
|
|
335
|
|
|
$this->assertTrue( |
|
336
|
|
|
$instance->isRegistered( $handler ) |
|
337
|
|
|
); |
|
338
|
|
|
|
|
339
|
|
|
$this->assertThatHookIsExcutable( |
|
340
|
|
|
$instance->getHandlerFor( $handler ), |
|
341
|
|
|
array( $search, &$titleMatches, &$textMatches ) |
|
342
|
|
|
); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
public function doTestSpecialSearchSetupEngine( $instance ) { |
|
346
|
|
|
|
|
347
|
|
|
$handler = 'SpecialSearchSetupEngine'; |
|
348
|
|
|
|
|
349
|
|
|
$profile = array(); |
|
350
|
|
|
|
|
351
|
|
|
$request = $this->getMockBuilder( '\WebRequest' ) |
|
352
|
|
|
->disableOriginalConstructor() |
|
353
|
|
|
->getMock(); |
|
354
|
|
|
|
|
355
|
|
|
$request->expects( $this->once() ) |
|
356
|
|
|
->method( 'getVal' ) |
|
357
|
|
|
->will( $this->returnValue( true ) ); |
|
358
|
|
|
|
|
359
|
|
|
$context = $this->getMockBuilder( '\RequestContext' ) |
|
360
|
|
|
->disableOriginalConstructor() |
|
361
|
|
|
->getMock(); |
|
362
|
|
|
|
|
363
|
|
|
$context->expects( $this->once() ) |
|
364
|
|
|
->method( 'getRequest' ) |
|
365
|
|
|
->will( $this->returnValue( $request ) ); |
|
366
|
|
|
|
|
367
|
|
|
$search = $this->getMockBuilder( '\SpecialSearch' ) |
|
368
|
|
|
->disableOriginalConstructor() |
|
369
|
|
|
->getMock(); |
|
370
|
|
|
|
|
371
|
|
|
$search->expects( $this->once() ) |
|
372
|
|
|
->method( 'getContext' ) |
|
373
|
|
|
->will( $this->returnValue( $context ) ); |
|
374
|
|
|
|
|
375
|
|
|
$searchEngine = $this->getMockBuilder( '\SearchEngine' ) |
|
376
|
|
|
->disableOriginalConstructor() |
|
377
|
|
|
->getMock(); |
|
378
|
|
|
|
|
379
|
|
|
$searchEngine->expects( $this->once() ) |
|
380
|
|
|
->method( 'setNamespaces' ); |
|
381
|
|
|
|
|
382
|
|
|
$this->assertTrue( |
|
383
|
|
|
$instance->isRegistered( $handler ) |
|
384
|
|
|
); |
|
385
|
|
|
|
|
386
|
|
|
$this->assertThatHookIsExcutable( |
|
387
|
|
|
$instance->getHandlerFor( $handler ), |
|
388
|
|
|
array( $search, $profile, $searchEngine ) |
|
389
|
|
|
); |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
public function doTestSpecialSearchPowerBox( $instance ) { |
|
393
|
|
|
|
|
394
|
|
|
$handler = 'SpecialSearchPowerBox'; |
|
395
|
|
|
$showSections = array(); |
|
396
|
|
|
|
|
397
|
|
|
$this->assertTrue( |
|
398
|
|
|
$instance->isRegistered( $handler ) |
|
399
|
|
|
); |
|
400
|
|
|
|
|
401
|
|
|
$this->assertThatHookIsExcutable( |
|
402
|
|
|
$instance->getHandlerFor( $handler ), |
|
403
|
|
|
array( &$showSections, '', array() ) |
|
404
|
|
|
); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
|
408
|
|
|
$this->assertInternalType( |
|
409
|
|
|
'boolean', |
|
410
|
|
|
call_user_func_array( $handler, $arguments ) |
|
411
|
|
|
); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
} |
|
415
|
|
|
|