diff options
author | Kunal Mehta <legoktm@gmail.com> | 2014-10-20 17:43:26 -0700 |
---|---|---|
committer | Krinkle <krinklemail@gmail.com> | 2015-03-03 17:17:02 +0000 |
commit | 870f50d45c4d3bb501703adc580b70db9ce6f335 (patch) | |
tree | f9e9feffaf8ab058a2ab0e461d818e47cfea3db7 /tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php | |
parent | 77b53b3dbdf861f9dd1acca36671d96151db415d (diff) | |
download | mediawikicore-870f50d45c4d3bb501703adc580b70db9ce6f335.tar.gz mediawikicore-870f50d45c4d3bb501703adc580b70db9ce6f335.zip |
resourceloader: Implement '$pages' parameter to ResourceLoaderWikiModule constructor
This makes it easier for subclasses to use ResourceLoaderWikiModule. Currently
many subclasses of this simply need to override the getPages() method.
UserModule and SiteModule keep their getPages override due to the set of pages
being dependent on context.
Change-Id: I388531398671afacfec36c6c5746d72267b5bdac
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php')
-rw-r--r-- | tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php index 9dc180506fd6..93a3ebba61f8 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -3,11 +3,93 @@ 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() ) |