public function testStyleMedia( $moduleName, $media, $filename, $css ) {
$cssText = CSSMin::minify( $css->cssText );
- $this->assertTrue( strpos( $cssText, '@media' ) === false, 'Stylesheets should not both specify "media" and contain @media' );
+ $this->assertTrue(
+ strpos( $cssText, '@media' ) === false,
+ 'Stylesheets should not both specify "media" and contain @media'
+ );
}
- public function testDependencies() {
+ /**
+ * 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.
+ */
+ public function testIllegalDependencies() {
$data = self::getAllModules();
$illegalDeps = array( 'jquery', 'mediawiki' );
+ /** @var ResourceLoaderModule $module */
foreach ( $data['modules'] as $moduleName => $module ) {
foreach ( $illegalDeps as $illegalDep ) {
$this->assertNotContains(
}
}
+ /**
+ * Verify that all modules specified as dependencies of other modules actually exist.
+ */
+ public function testMissingDependencies() {
+ $data = self::getAllModules();
+ $validDeps = array_keys( $data['modules'] );
+
+ /** @var ResourceLoaderModule $module */
+ foreach ( $data['modules'] as $moduleName => $module ) {
+ foreach ( $module->getDependencies() as $dep ) {
+ $this->assertContains(
+ $dep,
+ $validDeps,
+ "The module '$dep' required by '$moduleName' must exist"
+ );
+ }
+ }
+ }
+
+ /**
+ * Verify that all dependencies of all modules are always satisfiable with the 'targets' defined
+ * for the involved modules.
+ *
+ * Example: A depends on B. A has targets: mobile, desktop. B has targets: desktop. Therefore the
+ * dependency is sometimes unsatisfiable: it's impossible to load module A on mobile.
+ */
+ public function testUnsatisfiableDependencies() {
+ $data = self::getAllModules();
+ $validDeps = array_keys( $data['modules'] );
+
+ /** @var ResourceLoaderModule $module */
+ foreach ( $data['modules'] as $moduleName => $module ) {
+ $moduleTargets = $module->getTargets();
+ foreach ( $module->getDependencies() as $dep ) {
+ $targets = $data['modules'][$dep]->getTargets();
+ foreach ( $moduleTargets as $moduleTarget ) {
+ $this->assertContains(
+ $moduleTarget,
+ $targets,
+ "The module '$moduleName' must not have target '$moduleTarget' "
+ . "because its dependency '$dep' does not have it"
+ );
+ }
+ }
+ }
+ }
+
/**
* Get all registered modules from ResouceLoader.
*/
$media,
$file,
// XXX: Wrapped in an object to keep it out of PHPUnit output
- (object) array( 'cssText' => $readStyleFile->invoke( $module, $file, $flip ) ),
+ (object)array( 'cssText' => $readStyleFile->invoke( $module, $file, $flip ) ),
);
}
}
$cases[] = array(
$method->invoke( $module, $file ),
$moduleName,
- $file,
+ ( $file instanceof ResourceLoaderFilePath ? $file->getPath() : $file ),
);
}
}