1 | <?php |
||
25 | class SetupTest extends PHPUnit_Framework_TestCase { |
||
26 | /** |
||
27 | * @throws \ConfigException |
||
28 | * @throws \MWException |
||
29 | */ |
||
30 | public function testCanConstruct() { |
||
37 | |||
38 | /** |
||
39 | * @throws \ConfigException cascading {@see \BootstrapComponents\Setup::onExtensionLoad} |
||
40 | * @throws \MWException |
||
41 | */ |
||
42 | public function testOnExtensionLoad() { |
||
47 | |||
48 | /** |
||
49 | * @param string[] $hookList |
||
50 | * |
||
51 | * @throws \ConfigException |
||
52 | * @throws \MWException |
||
53 | * |
||
54 | * @dataProvider buildHookCallbackListForProvider |
||
55 | */ |
||
56 | public function testCanBuildHookCallbackListFor( $hookList ) { |
||
71 | |||
72 | /** |
||
73 | * @throws \ConfigException |
||
74 | * @throws \MWException |
||
75 | */ |
||
76 | public function testCanClear() { |
||
96 | |||
97 | /** |
||
98 | * @param string[] $listOfConfigSettingsSet |
||
99 | * @param string[] $expectedHookList |
||
100 | * |
||
101 | * @throws \ConfigException |
||
102 | * @throws \MWException |
||
103 | * |
||
104 | * @dataProvider hookRegistryProvider |
||
105 | */ |
||
106 | public function testCanCompileRequestedHooksListFor( $listOfConfigSettingsSet, $expectedHookList ) { |
||
137 | |||
138 | /** |
||
139 | * @throws \ConfigException |
||
140 | * @throws \MWException |
||
141 | */ |
||
142 | public function testCanGetCompleteHookDefinitionList() { |
||
169 | |||
170 | /** |
||
171 | * @throws \ConfigException |
||
172 | * @throws \MWException |
||
173 | */ |
||
174 | public function testCanInitializeApplications() { |
||
194 | |||
195 | /** |
||
196 | * @param array $listOfConfigSettingsSet |
||
197 | * @param array $expectedRegisteredHooks |
||
198 | * @param array $expectedNotRegisteredHooks |
||
199 | * |
||
200 | * @throws \ConfigException cascading {@see \Config::get} |
||
201 | * @throws \MWException |
||
202 | * |
||
203 | * @dataProvider hookRegistryProvider |
||
204 | */ |
||
205 | public function testHookRegistrationProcess( $listOfConfigSettingsSet, $expectedRegisteredHooks, $expectedNotRegisteredHooks ) { |
||
230 | |||
231 | /** |
||
232 | * @throws \ConfigException cascading {@see \Config::get} |
||
233 | * @throws \MWException |
||
234 | */ |
||
235 | public function testCanRun() { |
||
244 | |||
245 | /* |
||
246 | * Here end the tests for all the public methods. |
||
247 | * Following one test per hook function and one test for all the parser hook registrations. |
||
248 | */ |
||
249 | |||
250 | /** |
||
251 | * @throws \ConfigException |
||
252 | * @throws \MWException |
||
253 | */ |
||
254 | public function testHookGalleryGetModes() { |
||
273 | |||
274 | /** |
||
275 | * @throws \ConfigException |
||
276 | * @throws \MWException |
||
277 | */ |
||
278 | public function testHookImageBeforeProduceHTML() { |
||
286 | |||
287 | /** |
||
288 | * @throws \ConfigException |
||
289 | * @throws \MWException |
||
290 | */ |
||
291 | public function testHookInternalParseBeforeLinks() { |
||
292 | $parserOutput = $this->getMockBuilder( 'ParserOutput' ) |
||
293 | ->disableOriginalConstructor() |
||
294 | ->getMock(); |
||
295 | $parserOutput->expects( $this->exactly( 2 ) ) |
||
296 | ->method( 'setExtensionData' ) |
||
297 | ->with( |
||
298 | $this->stringContains( 'bsc_no_image_modal' ), |
||
299 | $this->isType( 'boolean' ) |
||
300 | ); |
||
301 | $parser = $this->getMockBuilder( 'Parser' ) |
||
302 | ->disableOriginalConstructor() |
||
303 | ->getMock(); |
||
304 | $parser->expects( $this->exactly( 2 ) ) |
||
305 | ->method( 'getOutput' ) |
||
306 | ->willReturn( $parserOutput ); |
||
307 | |||
308 | $callback = $this->getCallBackForHook( 'InternalParseBeforeLinks' ); |
||
309 | |||
310 | $text = ''; |
||
311 | $this->assertTrue( |
||
312 | $callback( $parser, $text ) |
||
313 | ); |
||
314 | $this->assertEquals( |
||
315 | '', |
||
316 | $text |
||
317 | ); |
||
318 | $text = '__NOIMAGEMODAL__'; |
||
319 | $this->assertTrue( |
||
320 | $callback( $parser, $text ) |
||
321 | ); |
||
322 | $this->assertEquals( |
||
323 | '', |
||
324 | $text |
||
325 | ); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @throws \ConfigException |
||
330 | * @throws \MWException |
||
331 | */ |
||
332 | public function testHookParserBeforeTidy() { |
||
361 | |||
362 | /** |
||
363 | * @throws \ConfigException |
||
364 | * @throws \MWException |
||
365 | */ |
||
366 | public function testHookParserFirstCallInit() { |
||
400 | |||
401 | /** |
||
402 | * @throws \ConfigException |
||
403 | * @throws \MWException |
||
404 | */ |
||
405 | public function testHookScribuntoExternalLibraries() { |
||
428 | |||
429 | /** |
||
430 | * @throws \ConfigException |
||
431 | * @throws \MWException |
||
432 | */ |
||
433 | public function testHookSetupAfterCache() { |
||
439 | |||
440 | /** |
||
441 | * @throws \ConfigException |
||
442 | * @throws \MWException |
||
443 | */ |
||
444 | public function testCanCreateParserHooks() { |
||
476 | |||
477 | /** |
||
478 | * @return array |
||
479 | */ |
||
480 | public function buildHookCallbackListForProvider() { |
||
481 | return [ |
||
482 | 'empty' => [ [] ], |
||
483 | 'default' => [ [ 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries' ] ], |
||
484 | 'alsoImageModal' => [ [ 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries' ] ], |
||
485 | 'alsoCarouselGallery' => [ [ 'GalleryGetModes', 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries' ] ], |
||
486 | 'all' => [ [ 'GalleryGetModes', 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries' ] ], |
||
487 | 'invalid' => [ [ 'nonExistingHook', 'PageContentSave' ] ], |
||
488 | ]; |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * @return string[] |
||
493 | */ |
||
494 | public function hookRegistryProvider() { |
||
495 | return [ |
||
496 | 'onlydefault' => [ |
||
497 | [], |
||
498 | [ 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries', ], |
||
499 | [ 'GalleryGetModes', 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', ], |
||
500 | ], |
||
501 | 'gallery activated' => [ |
||
502 | [ 'BootstrapComponentsEnableCarouselGalleryMode' ], |
||
503 | [ 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries', 'GalleryGetModes', ], |
||
504 | [ 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', ], |
||
505 | ], |
||
506 | 'image replacement activated' => [ |
||
507 | [ 'BootstrapComponentsModalReplaceImageTag' ], |
||
508 | [ 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries', 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', ], |
||
509 | [ 'GalleryGetModes', ], |
||
510 | ], |
||
511 | 'both activated' => [ |
||
512 | [ 'BootstrapComponentsEnableCarouselGalleryMode', 'BootstrapComponentsModalReplaceImageTag' ], |
||
513 | [ 'ParserBeforeTidy', 'ParserFirstCallInit', 'SetupAfterCache', 'ScribuntoExternalLibraries', 'GalleryGetModes', 'ImageBeforeProduceHTML', 'InternalParseBeforeLinks', ], |
||
514 | [], |
||
515 | ], |
||
516 | ]; |
||
517 | } |
||
518 | |||
519 | /** |
||
520 | * @param $hookList |
||
521 | * |
||
522 | * @return array $expectedHookList, $invertedHookList |
||
523 | */ |
||
524 | private function buildHookListsForCanBuildHookListCheck( $hookList ) { |
||
539 | |||
540 | /** |
||
541 | * @param Setup $instance |
||
542 | * @param array $registeredHooks |
||
543 | * @param string $expectedHook |
||
544 | * @param bool $hardRegisterTest |
||
545 | */ |
||
546 | private function doTestHookIsRegistered( Setup $instance, $registeredHooks, $expectedHook, $hardRegisterTest = true ) { |
||
561 | |||
562 | /** |
||
563 | * @param array $registeredHooks |
||
564 | * @param string $notExpectedHook |
||
565 | */ |
||
566 | private function doTestHookIsNotRegistered( $registeredHooks, $notExpectedHook ) { |
||
573 | |||
574 | /** |
||
575 | * @param string $registeredParserHook |
||
576 | * @param \Closure $callback |
||
577 | * @param string $handlerType |
||
578 | */ |
||
579 | private function doTestParserHook( $registeredParserHook, $callback, $handlerType ) { |
||
597 | |||
598 | /** |
||
599 | * @throws \ConfigException |
||
600 | * @throws \MWException |
||
601 | * |
||
602 | * @return \Closure |
||
603 | */ |
||
604 | private function getCallBackForHook( $hook ) { |
||
618 | } |
||
619 |