Debian Codegraph @

extensions/MultimediaViewer/tests/phpunit/HooksTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\MultimediaViewer\Tests;
4
5 use MediaWiki\Extension\MultimediaViewer\Hooks;
6 use MediaWiki\Output\OutputPage;
7 use MediaWiki\Title\Title;
8 use MediaWikiIntegrationTestCase;
9 use SkinTemplate;
10
11 /**
12 * @covers \MediaWiki\Extension\MultimediaViewer\Hooks
13 */
14 class HooksTest extends MediaWikiIntegrationTestCase {
15
16 public function newHooksInstance() {
17 return new Hooks(
18 $this->getServiceContainer()->getMainConfig(),
19 $this->getServiceContainer()->getSpecialPageFactory(),
20 $this->getServiceContainer()->getUserOptionsLookup(),
21 null
22 );
23 }
24
25 public static function provideOnBeforePageDisplay() {
26 return [
27 'no files' => [ 'Main Page', 0, false ],
28 'with files' => [ 'Main Page', 1, true ],
29 'special with files' => [ 'Special:ListFiles', 0, true ],
30 'special no files' => [ 'Special:Watchlist', 0, false ],
31 ];
32 }
33
34 /**
35 * @dataProvider provideOnBeforePageDisplay
36 */
37 public function testOnBeforePageDisplay( $pagename, $fileCount, $modulesExpected ) {
38 $t = Title::newFromText( $pagename );
39 // Force content model to avoid DB queries
40 $t->setContentModel( CONTENT_MODEL_WIKITEXT );
41 $skin = new SkinTemplate();
42 $output = $this->createMock( OutputPage::class );
43 $output->method( 'getTitle' )->willReturn( $t );
44 $output->method( 'getFileSearchOptions' )->willReturn( array_fill( 0, $fileCount, null ) );
45 $output->expects( $this->exactly( $modulesExpected ? 1 : 0 ) )->method( 'addModules' );
46 $this->newHooksInstance()->onBeforePageDisplay( $output, $skin );
47 }
48 }