2023-09-22 22:03:01 +00:00
|
|
|
<?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(
|
2023-10-23 20:28:32 +00:00
|
|
|
$this->getServiceContainer()->getMainConfig(),
|
2023-10-23 20:14:57 +00:00
|
|
|
$this->getServiceContainer()->getSpecialPageFactory(),
|
|
|
|
$this->getServiceContainer()->getUserOptionsLookup()
|
2023-09-22 22:03:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
2023-12-15 23:38:06 +00:00
|
|
|
$t = Title::newFromText( $pagename );
|
|
|
|
// Force content model to avoid DB queries
|
|
|
|
$t->setContentModel( CONTENT_MODEL_WIKITEXT );
|
2023-09-22 22:03:01 +00:00
|
|
|
$skin = new SkinTemplate();
|
|
|
|
$output = $this->createMock( OutputPage::class );
|
2023-12-15 23:38:06 +00:00
|
|
|
$output->method( 'getTitle' )->willReturn( $t );
|
2023-09-22 22:03:01 +00:00
|
|
|
$output->method( 'getFileSearchOptions' )->willReturn( array_fill( 0, $fileCount, null ) );
|
|
|
|
$output->expects( $this->exactly( $modulesExpected ? 1 : 0 ) )->method( 'addModules' );
|
|
|
|
$this->newHooksInstance()->onBeforePageDisplay( $output, $skin );
|
|
|
|
}
|
|
|
|
}
|