diff options
Diffstat (limited to 'tests/phpunit/structure')
-rw-r--r-- | tests/phpunit/structure/AutoLoaderTest.php | 4 | ||||
-rw-r--r-- | tests/phpunit/structure/AvailableRightsTest.php | 4 | ||||
-rw-r--r-- | tests/phpunit/structure/ResourcesTest.php | 52 |
3 files changed, 53 insertions, 7 deletions
diff --git a/tests/phpunit/structure/AutoLoaderTest.php b/tests/phpunit/structure/AutoLoaderTest.php index cde6547a..8674329a 100644 --- a/tests/phpunit/structure/AutoLoaderTest.php +++ b/tests/phpunit/structure/AutoLoaderTest.php @@ -58,9 +58,9 @@ class AutoLoaderTest extends MediaWikiTestCase { continue; } - wfSuppressWarnings(); + MediaWiki\suppressWarnings(); $contents = file_get_contents( $filePath ); - wfRestoreWarnings(); + MediaWiki\restoreWarnings(); if ( $contents === false ) { $actual[$class] = "[couldn't read file '$filePath']"; diff --git a/tests/phpunit/structure/AvailableRightsTest.php b/tests/phpunit/structure/AvailableRightsTest.php index 51d31aaa..ccf5393b 100644 --- a/tests/phpunit/structure/AvailableRightsTest.php +++ b/tests/phpunit/structure/AvailableRightsTest.php @@ -19,11 +19,11 @@ class AvailableRightsTest extends PHPUnit_Framework_TestCase { $rights = User::getAllRights(); - foreach( $wgGroupPermissions as $permissions ) { + foreach ( $wgGroupPermissions as $permissions ) { $rights = array_merge( $rights, array_keys( $permissions ) ); } - foreach( $wgRevokePermissions as $permissions ) { + foreach ( $wgRevokePermissions as $permissions ) { $rights = array_merge( $rights, array_keys( $permissions ) ); } diff --git a/tests/phpunit/structure/ResourcesTest.php b/tests/phpunit/structure/ResourcesTest.php index d2b699d9..eefc926a 100644 --- a/tests/phpunit/structure/ResourcesTest.php +++ b/tests/phpunit/structure/ResourcesTest.php @@ -36,9 +36,20 @@ class ResourcesTest extends MediaWikiTestCase { ); } + public function testVersionHash() { + $data = self::getAllModules(); + foreach ( $data['modules'] as $moduleName => $module ) { + $version = $module->getVersionHash( $data['context'] ); + $this->assertEquals( 8, strlen( $version ), "$moduleName must use ResourceLoader::makeHash" ); + } + } + /** * Verify that nothing explicitly depends on the 'jquery' and 'mediawiki' modules. * They are always loaded, depending on them is unsupported and leads to unexpected behaviour. + * TODO Modules can dynamically choose dependencies based on context. This method does not + * test such dependencies. The same goes for testMissingDependencies() and + * testUnsatisfiableDependencies(). */ public function testIllegalDependencies() { $data = self::getAllModules(); @@ -49,7 +60,7 @@ class ResourcesTest extends MediaWikiTestCase { foreach ( $illegalDeps as $illegalDep ) { $this->assertNotContains( $illegalDep, - $module->getDependencies(), + $module->getDependencies( $data['context'] ), "Module '$moduleName' must not depend on '$illegalDep'" ); } @@ -65,7 +76,7 @@ class ResourcesTest extends MediaWikiTestCase { /** @var ResourceLoaderModule $module */ foreach ( $data['modules'] as $moduleName => $module ) { - foreach ( $module->getDependencies() as $dep ) { + foreach ( $module->getDependencies( $data['context'] ) as $dep ) { $this->assertContains( $dep, $validDeps, @@ -89,7 +100,7 @@ class ResourcesTest extends MediaWikiTestCase { /** @var ResourceLoaderModule $module */ foreach ( $data['modules'] as $moduleName => $module ) { $moduleTargets = $module->getTargets(); - foreach ( $module->getDependencies() as $dep ) { + foreach ( $module->getDependencies( $data['context'] ) as $dep ) { if ( !isset( $data['modules'][$dep] ) ) { // Missing dependencies reported by testMissingDependencies continue; @@ -108,6 +119,22 @@ class ResourcesTest extends MediaWikiTestCase { } /** + * CSSMin::getAllLocalFileReferences should ignore url(...) expressions + * that have been commented out. + */ + public function testCommentedLocalFileReferences() { + $basepath = __DIR__ . '/../data/css/'; + $css = file_get_contents( $basepath . 'comments.css' ); + $files = CSSMin::getAllLocalFileReferences( $css, $basepath ); + $expected = array( $basepath . 'not-commented.gif' ); + $this->assertArrayEquals( + $expected, + $files, + 'Url(...) expression in comment should be omitted.' + ); + } + + /** * Get all registered modules from ResouceLoader. * @return array */ @@ -265,6 +292,25 @@ class ResourcesTest extends MediaWikiTestCase { ( $file instanceof ResourceLoaderFilePath ? $file->getPath() : $file ), ); } + + // To populate missingLocalFileRefs. Not sure how sane this is inside this test... + $module->readStyleFiles( + $module->getStyleFiles( $data['context'] ), + $module->getFlip( $data['context'] ), + $data['context'] + ); + + $property = $reflectedModule->getProperty( 'missingLocalFileRefs' ); + $property->setAccessible( true ); + $missingLocalFileRefs = $property->getValue( $module ); + + foreach ( $missingLocalFileRefs as $file ) { + $cases[] = array( + $file, + $moduleName, + $file, + ); + } } return $cases; |