X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderWikiModuleTest.php;h=93a3ebba61f8f6185f48264b8a9354e9e27f428f;hb=870f50d45c4d3bb501703adc580b70db9ce6f335;hp=50f88c825f3af81e758bff571049ab7f7d9bc9d9;hpb=768493b825348b42e4bf9837153a937c8033c59e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php index 50f88c825f..93a3ebba61 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -2,12 +2,94 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { + /** + * @covers ResourceLoaderWikiModule::__construct + * @dataProvider provideConstructor + */ + public function testConstructor( $params ) { + $module = new ResourceLoaderWikiModule( $params ); + $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module ); + } + + public static function provideConstructor() { + return array( + // Nothing + array( null ), + array( array() ), + // Unrecognized settings + array( array( 'foo' => 'baz' ) ), + // Real settings + array( array( 'scripts' => array( 'MediaWiki:Common.js' ) ) ), + ); + } + + /** + * @dataProvider provideGetPages + * @covers ResourceLoaderWikiModule::getPages + */ + public function testGetPages( $params, Config $config, $expected ) { + $module = new ResourceLoaderWikiModule( $params ); + $module->setConfig( $config ); + + // Use getDefinitionSummary because getPages is protected + $summary = $module->getDefinitionSummary( ResourceLoaderContext::newDummyContext() ); + $this->assertEquals( + $expected, + $summary['pages'] + ); + } + + public static function provideGetPages() { + $settings = array( + 'UseSiteJs' => true, + 'UseSiteCss' => true, + ); + + $params = array( + 'styles' => array( 'MediaWiki:Common.css' ), + 'scripts' => array( 'MediaWiki:Common.js' ), + ); + + return array( + array( array(), new HashConfig( $settings ), array() ), + array( $params, new HashConfig( $settings ), array( + 'MediaWiki:Common.js' => array( 'type' => 'script' ), + 'MediaWiki:Common.css' => array( 'type' => 'style' ) + ) ), + array( $params, new HashConfig( array( 'UseSiteCss' => false ) + $settings ), array( + 'MediaWiki:Common.js' => array( 'type' => 'script' ), + ) ), + array( $params, new HashConfig( array( 'UseSiteJs' => false ) + $settings ), array( + 'MediaWiki:Common.css' => array( 'type' => 'style' ), + ) ), + array( $params, new HashConfig( array( 'UseSiteJs' => false, 'UseSiteCss' => false ) ), array() ), + ); + } + + /** + * @covers ResourceLoaderWikiModule::getGroup + * @dataProvider provideGetGroup + */ + public function testGetGroup( $params, $expected ) { + $module = new ResourceLoaderWikiModule( $params ); + $this->assertEquals( $expected, $module->getGroup() ); + } + + public static function provideGetGroup() { + return array( + // No group specified + array( array(), null ), + // A random group + array( array( 'group' => 'foobar' ), 'foobar' ), + ); + } + /** * @covers ResourceLoaderWikiModule::isKnownEmpty * @dataProvider provideIsKnownEmpty */ public function testIsKnownEmpty( $titleInfo, $group, $expected ) { - $module = $this->getMockBuilder( 'ResourceLoaderWikiModuleTestModule' ) + $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) ->setMethods( array( 'getTitleInfo', 'getGroup' ) ) ->getMock(); $module->expects( $this->any() ) @@ -22,7 +104,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { $this->assertEquals( $expected, $module->isKnownEmpty( $context ) ); } - public function provideIsKnownEmpty() { + public static function provideIsKnownEmpty() { return array( // No valid pages array( array(), 'test1', true ),