X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderStartUpModuleTest.php;h=03a609b664c86a4b16952f52a677563a581629d1;hb=e4a52de02530fbaec779c7ab3103144eb1fbebf5;hp=ab1323ecdc01045c2c7dabe1033ee97c0e55850c;hpb=9535f9e4187cd9b7ed6acedbc74a4265ce2d02b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php index ab1323ecdc..03a609b664 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php @@ -2,18 +2,13 @@ class ResourceLoaderStartUpModuleTest extends ResourceLoaderTestCase { - // Version hash for a blank file module. - // Result of ResourceLoader::makeHash(), ResourceLoaderTestModule - // and ResourceLoaderFileModule::getDefinitionSummary(). - protected static $blankVersion = '09p30q0'; - protected static function expandPlaceholders( $text ) { return strtr( $text, [ - '{blankVer}' => self::$blankVersion + '{blankVer}' => self::BLANK_VERSION ] ); } - public static function provideGetModuleRegistrations() { + public function provideGetModuleRegistrations() { return [ [ [ 'msg' => 'Empty registry', @@ -38,6 +33,88 @@ mw.loader.register( [ "test.blank", "{blankVer}" ] +] );', + ] ], + [ [ + 'msg' => 'Omit raw modules from registry', + 'modules' => [ + 'test.raw' => new ResourceLoaderTestModule( [ 'isRaw' => true ] ), + 'test.blank' => new ResourceLoaderTestModule(), + ], + 'out' => ' +mw.loader.addSource( { + "local": "/w/load.php" +} ); +mw.loader.register( [ + [ + "test.blank", + "{blankVer}" + ] +] );', + ] ], + [ [ + 'msg' => 'Version falls back gracefully if getVersionHash throws', + 'modules' => [ + 'test.fail' => ( + ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ->setMethods( [ 'getVersionHash' ] )->getMock() ) + && $mock->method( 'getVersionHash' )->will( + $this->throwException( new Exception ) + ) + ) ? $mock : $mock + ], + 'out' => ' +mw.loader.addSource( { + "local": "/w/load.php" +} ); +mw.loader.register( [ + [ + "test.fail", + "" + ] +] ); +mw.loader.state( { + "test.fail": "error" +} );', + ] ], + [ [ + 'msg' => 'Use version from getVersionHash', + 'modules' => [ + 'test.version' => ( + ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ->setMethods( [ 'getVersionHash' ] )->getMock() ) + && $mock->method( 'getVersionHash' )->willReturn( '1234567' ) + ) ? $mock : $mock + ], + 'out' => ' +mw.loader.addSource( { + "local": "/w/load.php" +} ); +mw.loader.register( [ + [ + "test.version", + "1234567" + ] +] );', + ] ], + [ [ + 'msg' => 'Re-hash version from getVersionHash if too long', + 'modules' => [ + 'test.version' => ( + ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ->setMethods( [ 'getVersionHash' ] )->getMock() ) + && $mock->method( 'getVersionHash' )->willReturn( '12345678' ) + ) ? $mock : $mock + ], + 'out' => ' +mw.loader.addSource( { + "local": "/w/load.php" +} ); +mw.loader.register( [ + [ + "test.version", + "016es8l" + ] ] );', ] ], [ [ @@ -308,8 +385,8 @@ mw.loader.register( [ /** * @dataProvider provideGetModuleRegistrations - * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies * @covers ResourceLoaderStartUpModule::getModuleRegistrations + * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies * @covers ResourceLoader::makeLoaderRegisterScript */ public function testGetModuleRegistrations( $case ) { @@ -323,6 +400,10 @@ mw.loader.register( [ $module = new ResourceLoaderStartUpModule(); $out = ltrim( $case['out'], "\n" ); + // Disable log from getModuleRegistrations via MWExceptionHandler + // for case where getVersionHash() is expected to throw. + $this->setLogger( 'exception', new Psr\Log\NullLogger() ); + $this->assertEquals( self::expandPlaceholders( $out ), $module->getModuleRegistrations( $context ), @@ -349,6 +430,7 @@ mw.loader.register( [ ]; } /** + * @covers ResourceLoaderStartUpModule::getModuleRegistrations * @dataProvider provideRegistrations */ public function testRegistrationsMinified( $modules ) { @@ -373,6 +455,7 @@ mw.loader.register( [ } /** + * @covers ResourceLoaderStartUpModule::getModuleRegistrations * @dataProvider provideRegistrations */ public function testRegistrationsUnminified( $modules ) {