wiki.techinc.nl/tests/phpunit/includes/ResourceLoaderTest.php

100 lines
2.7 KiB
PHP
Raw Normal View History

<?php
class ResourceLoaderTest extends MediaWikiTestCase {
protected static $resourceLoaderRegisterModulesHook;
/* Hook Methods */
/**
* ResourceLoaderRegisterModules hook
*/
public static function resourceLoaderRegisterModules( &$resourceLoader ) {
self::$resourceLoaderRegisterModulesHook = true;
return true;
}
/* Provider Methods */
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
public static function provideValidModules() {
return array(
array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
);
}
/* Test Methods */
/**
* Ensures that the ResourceLoaderRegisterModules hook is called when a new ResourceLoader object is constructed
* @covers ResourceLoader::__construct
*/
public function testCreatingNewResourceLoaderCallsRegistrationHook() {
self::$resourceLoaderRegisterModulesHook = false;
$resourceLoader = new ResourceLoader();
$this->assertTrue( self::$resourceLoaderRegisterModulesHook );
return $resourceLoader;
}
/**
* @dataProvider provideValidModules
* @depends testCreatingNewResourceLoaderCallsRegistrationHook
* @covers ResourceLoader::register
* @covers ResourceLoader::getModule
*/
public function testRegisteredValidModulesAreAccessible(
$name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
) {
$resourceLoader->register( $name, $module );
$this->assertEquals( $module, $resourceLoader->getModule( $name ) );
}
/**
* @dataProvider providePackedModules
*/
public function testMakePackedModulesString( $desc, $modules, $packed ) {
$this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc );
}
/**
* @dataProvider providePackedModules
*/
public function testexpandModuleNames( $desc, $modules, $packed ) {
$this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc );
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
public static function providePackedModules() {
return array(
array(
'Example from makePackedModulesString doc comment',
array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
'foo.bar,baz|bar.baz,quux',
),
array(
'Example from expandModuleNames doc comment',
array( 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ),
'jquery.foo,bar|jquery.ui.baz,quux',
),
array(
'Regression fixed in r88706 with dotless names',
array( 'foo', 'bar', 'baz' ),
'foo,bar,baz',
),
array(
'Prefixless modules after a prefixed module',
array( 'single.module', 'foobar', 'foobaz' ),
'single.module|foobar,foobaz',
),
);
}
}
/* Stubs */
class ResourceLoaderTestModule extends ResourceLoaderModule {
}
/* Hooks */
global $wgHooks;
$wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';