mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-12-20 11:52:34 +00:00
fb1de7786c
Avoid creating of Title object to get the "fixed special name" (which is the localized name) and compare that against the local name of the current page, just use the SpecialPageFactory to get the canonical name (which is the english internal name, not the english visible name) and compare against the list of canonical allowed pages (adjust the existing list to the canonical names, that are "old" names in different cases) Change-Id: Ia6f6574bf6e65c75f8977ff016feda6ecdca3776
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\MultimediaViewer\Tests;
|
|
|
|
use MediaWiki\Extension\MultimediaViewer\Hooks;
|
|
use MediaWiki\Output\OutputPage;
|
|
use MediaWiki\Title\Title;
|
|
use MediaWikiIntegrationTestCase;
|
|
use SkinTemplate;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\MultimediaViewer\Hooks
|
|
*/
|
|
class HooksTest extends MediaWikiIntegrationTestCase {
|
|
|
|
public function newHooksInstance() {
|
|
return new Hooks(
|
|
$this->getServiceContainer()->getUserOptionsLookup(),
|
|
$this->getServiceContainer()->getSpecialPageFactory()
|
|
);
|
|
}
|
|
|
|
public static function provideOnBeforePageDisplay() {
|
|
return [
|
|
'no files' => [ 'Main Page', 0, false ],
|
|
'with files' => [ 'Main Page', 1, true ],
|
|
'special with files' => [ 'Special:ListFiles', 0, true ],
|
|
'special no files' => [ 'Special:Watchlist', 0, false ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideOnBeforePageDisplay
|
|
*/
|
|
public function testOnBeforePageDisplay( $pagename, $fileCount, $modulesExpected ) {
|
|
$skin = new SkinTemplate();
|
|
$output = $this->createMock( OutputPage::class );
|
|
$output->method( 'getTitle' )->willReturn( Title::newFromText( $pagename ) );
|
|
$output->method( 'getFileSearchOptions' )->willReturn( array_fill( 0, $fileCount, null ) );
|
|
$output->expects( $this->exactly( $modulesExpected ? 1 : 0 ) )->method( 'addModules' );
|
|
$this->newHooksInstance()->onBeforePageDisplay( $output, $skin );
|
|
}
|
|
}
|