Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderStartUpModuleTest.php
index 1b756be..564f50b 100644 (file)
@@ -8,7 +8,7 @@ class ResourceLoaderStartUpModuleTest extends ResourceLoaderTestCase {
                ] );
        }
 
-       public static function provideGetModuleRegistrations() {
+       public function provideGetModuleRegistrations() {
                return [
                        [ [
                                'msg' => 'Empty registry',
@@ -33,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::class )
+                                                       ->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::class )
+                                                       ->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::class )
+                                                       ->setMethods( [ 'getVersionHash' ] )->getMock() )
+                                               && $mock->method( 'getVersionHash' )->willReturn( '12345678' )
+                                       ) ? $mock : $mock
+                               ],
+                               'out' => '
+mw.loader.addSource( {
+    "local": "/w/load.php"
+} );
+mw.loader.register( [
+    [
+        "test.version",
+        "016es8l"
+    ]
 ] );',
                        ] ],
                        [ [
@@ -303,8 +385,8 @@ mw.loader.register( [
 
        /**
         * @dataProvider provideGetModuleRegistrations
-        * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
         * @covers ResourceLoaderStartUpModule::getModuleRegistrations
+        * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
         * @covers ResourceLoader::makeLoaderRegisterScript
         */
        public function testGetModuleRegistrations( $case ) {
@@ -318,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 ),
@@ -344,6 +430,7 @@ mw.loader.register( [
                ];
        }
        /**
+        * @covers ResourceLoaderStartUpModule::getModuleRegistrations
         * @dataProvider provideRegistrations
         */
        public function testRegistrationsMinified( $modules ) {
@@ -368,6 +455,7 @@ mw.loader.register( [
        }
 
        /**
+        * @covers ResourceLoaderStartUpModule::getModuleRegistrations
         * @dataProvider provideRegistrations
         */
        public function testRegistrationsUnminified( $modules ) {