Add session_write_close() calls to SessionManager tests
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderClientHtmlTest.php
index c83f500..07956f1 100644 (file)
@@ -5,7 +5,7 @@ use Wikimedia\TestingAccessWrapper;
 /**
  * @group ResourceLoader
  */
-class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
+class ResourceLoaderClientHtmlTest extends PHPUnit\Framework\TestCase {
 
        use MediaWikiCoversValidator;
 
@@ -42,9 +42,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
        protected static function makeSampleModules() {
                $modules = [
                        'test' => [],
-                       'test.top' => [ 'position' => 'top' ],
-                       'test.private.top' => [ 'group' => 'private', 'position' => 'top' ],
-                       'test.private.bottom' => [ 'group' => 'private', 'position' => 'bottom' ],
+                       'test.private' => [ 'group' => 'private' ],
                        'test.shouldembed.empty' => [ 'shouldEmbed' => true, 'isKnownEmpty' => true ],
                        'test.shouldembed' => [ 'shouldEmbed' => true ],
 
@@ -75,7 +73,6 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                        ],
 
                        'test.scripts' => [],
-                       'test.scripts.top' => [ 'position' => 'top' ],
                        'test.scripts.user' => [ 'group' => 'user' ],
                        'test.scripts.user.empty' => [ 'group' => 'user', 'isKnownEmpty' => true ],
                        'test.scripts.raw' => [ 'isRaw' => true ],
@@ -115,9 +112,7 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                $client = new ResourceLoaderClientHtml( $context );
                $client->setModules( [
                        'test',
-                       'test.private.bottom',
-                       'test.private.top',
-                       'test.top',
+                       'test.private',
                        'test.shouldembed.empty',
                        'test.shouldembed',
                        'test.unregistered',
@@ -132,16 +127,15 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                ] );
                $client->setModuleScripts( [
                        'test.scripts',
+                       'test.scripts.user',
                        'test.scripts.user.empty',
-                       'test.scripts.top',
                        'test.scripts.shouldembed',
                        'test.unregistered.scripts',
                ] );
 
                $expected = [
                        'states' => [
-                               'test.private.top' => 'loading',
-                               'test.private.bottom' => 'loading',
+                               'test.private' => 'loading',
                                'test.shouldembed.empty' => 'ready',
                                'test.shouldembed' => 'loading',
                                'test.styles.pure' => 'ready',
@@ -149,27 +143,25 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                                'test.styles.private' => 'ready',
                                'test.styles.shouldembed' => 'ready',
                                'test.scripts' => 'loading',
-                               'test.scripts.top' => 'loading',
+                               'test.scripts.user' => 'loading',
                                'test.scripts.user.empty' => 'ready',
                                'test.scripts.shouldembed' => 'loading',
                        ],
                        'general' => [
                                'test',
-                               'test.top',
                        ],
                        'styles' => [
                                'test.styles.pure',
                        ],
                        'scripts' => [
                                'test.scripts',
-                               'test.scripts.top',
+                               'test.scripts.user',
                                'test.scripts.shouldembed',
                        ],
                        'embed' => [
                                'styles' => [ 'test.styles.private', 'test.styles.shouldembed' ],
                                'general' => [
-                                       'test.private.bottom',
-                                       'test.private.top',
+                                       'test.private',
                                        'test.shouldembed',
                                ],
                        ],
@@ -193,15 +185,15 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                $client = new ResourceLoaderClientHtml( $context );
                $client->setConfig( [ 'key' => 'value' ] );
                $client->setModules( [
-                       'test.top',
-                       'test.private.top',
+                       'test',
+                       'test.private',
                ] );
                $client->setModuleStyles( [
                        'test.styles.pure',
                        'test.styles.private',
                ] );
                $client->setModuleScripts( [
-                       'test.scripts.top',
+                       'test.scripts',
                ] );
                $client->setExemptStates( [
                        'test.exempt' => 'ready',
@@ -211,10 +203,10 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
                        . '<script>(window.RLQ=window.RLQ||[]).push(function(){'
                        . 'mw.config.set({"key":"value"});'
-                       . 'mw.loader.state({"test.exempt":"ready","test.private.top":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.scripts.top":"loading"});'
-                       . 'mw.loader.implement("test.private.top@{blankVer}",function($,jQuery,require,module){},{"css":[]});'
-                       . 'mw.loader.load(["test.top"]);'
-                       . 'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts.top\u0026only=scripts\u0026skin=fallback");'
+                       . 'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.scripts":"loading"});'
+                       . 'mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});'
+                       . 'mw.loader.load(["test"]);'
+                       . 'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts\u0026only=scripts\u0026skin=fallback");'
                        . '});</script>' . "\n"
                        . '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=nl&amp;modules=test.styles.pure&amp;only=styles&amp;skin=fallback"/>' . "\n"
                        . '<style>.private{}</style>' . "\n"
@@ -225,6 +217,44 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( $expected, $client->getHeadHtml() );
        }
 
+       /**
+        * Confirm that 'target' is passed down to the startup module's load url.
+        *
+        * @covers ResourceLoaderClientHtml::getHeadHtml
+        */
+       public function testGetHeadHtmlWithTarget() {
+               $client = new ResourceLoaderClientHtml(
+                       self::makeContext(),
+                       [ 'target' => 'example' ]
+               );
+
+               // phpcs:disable Generic.Files.LineLength
+               $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
+                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback&amp;target=example"></script>';
+               // phpcs:enable
+
+               $this->assertEquals( $expected, $client->getHeadHtml() );
+       }
+
+       /**
+        * Confirm that a null 'target' is the same as no target.
+        *
+        * @covers ResourceLoaderClientHtml::getHeadHtml
+        */
+       public function testGetHeadHtmlWithNullTarget() {
+               $client = new ResourceLoaderClientHtml(
+                       self::makeContext(),
+                       [ 'target' => null ]
+               );
+
+               // phpcs:disable Generic.Files.LineLength
+               $expected = '<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' . "\n"
+                       . '<script async="" src="/w/load.php?debug=false&amp;lang=nl&amp;modules=startup&amp;only=scripts&amp;skin=fallback"></script>';
+               // phpcs:enable
+
+               $this->assertEquals( $expected, $client->getHeadHtml() );
+       }
+
        /**
         * @covers ResourceLoaderClientHtml::getBodyHtml
         * @covers ResourceLoaderClientHtml::getLoad
@@ -266,9 +296,9 @@ class ResourceLoaderClientHtmlTest extends PHPUnit_Framework_TestCase {
                        ],
                        [
                                'context' => [],
-                               'modules' => [ 'test.private.top' ],
+                               'modules' => [ 'test.private' ],
                                'only' => ResourceLoaderModule::TYPE_COMBINED,
-                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private.top@{blankVer}",function($,jQuery,require,module){},{"css":[]});});</script>',
+                               'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});});</script>',
                        ],
                        [
                                'context' => [],