summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:17:42 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:17:42 -0400
commitf7d4cf9ed0ae68fec630d14e8f6aade38e49f036 (patch)
treea730c57badbe0e2f0f064ca2006c82d4b6ed54ea /tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
parentaee35e4a93d105024bcae947cd8b16c962191f5c (diff)
parent5d1e7dd0ccda0984ccf3e8e3d0f88ac888b05819 (diff)
Merge commit '5d1e7'
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php132
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
new file mode 100644
index 00000000..b0edaaf7
--- /dev/null
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php
@@ -0,0 +1,132 @@
+<?php
+
+class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ // The return value of the closure shouldn't matter since this test should
+ // never call it
+ SkinFactory::getDefaultInstance()->register(
+ 'fakeskin',
+ 'FakeSkin',
+ function () {
+ }
+ );
+ }
+
+ /**
+ * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
+ */
+ public function testGetAllSkinStyleFiles() {
+ $context = self::getResourceLoaderContext();
+
+ $baseParams = array(
+ 'scripts' => array(
+ 'foo.js',
+ 'bar.js',
+ ),
+ 'styles' => array(
+ 'foo.css',
+ 'bar.css' => array( 'media' => 'print' ),
+ 'screen.less' => array( 'media' => 'screen' ),
+ 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
+ ),
+ 'skinStyles' => array(
+ 'default' => 'quux-fallback.less',
+ 'fakeskin' => array(
+ 'baz-vector.css',
+ 'quux-vector.less',
+ ),
+ ),
+ 'messages' => array(
+ 'hello',
+ 'world',
+ ),
+ );
+
+ $module = new ResourceLoaderFileModule( $baseParams );
+
+ $this->assertEquals(
+ array(
+ 'foo.css',
+ 'baz-vector.css',
+ 'quux-vector.less',
+ 'quux-fallback.less',
+ 'bar.css',
+ 'screen.less',
+ 'screen-query.css',
+ ),
+ array_map( 'basename', $module->getAllStyleFiles() )
+ );
+ }
+
+ /**
+ * @covers ResourceLoaderModule::getDefinitionSummary
+ * @covers ResourceLoaderFileModule::getDefinitionSummary
+ */
+ public function testDefinitionSummary() {
+ $context = self::getResourceLoaderContext();
+
+ $baseParams = array(
+ 'scripts' => array( 'foo.js', 'bar.js' ),
+ 'dependencies' => array( 'jquery', 'mediawiki' ),
+ 'messages' => array( 'hello', 'world' ),
+ );
+
+ $module = new ResourceLoaderFileModule( $baseParams );
+
+ $jsonSummary = json_encode( $module->getDefinitionSummary( $context ) );
+
+ // Exactly the same
+ $module = new ResourceLoaderFileModule( $baseParams );
+
+ $this->assertEquals(
+ $jsonSummary,
+ json_encode( $module->getDefinitionSummary( $context ) ),
+ 'Instance is insignificant'
+ );
+
+ // Re-order dependencies
+ $module = new ResourceLoaderFileModule( array(
+ 'dependencies' => array( 'mediawiki', 'jquery' ),
+ ) + $baseParams );
+
+ $this->assertEquals(
+ $jsonSummary,
+ json_encode( $module->getDefinitionSummary( $context ) ),
+ 'Order of dependencies is insignificant'
+ );
+
+ // Re-order messages
+ $module = new ResourceLoaderFileModule( array(
+ 'messages' => array( 'world', 'hello' ),
+ ) + $baseParams );
+
+ $this->assertEquals(
+ $jsonSummary,
+ json_encode( $module->getDefinitionSummary( $context ) ),
+ 'Order of messages is insignificant'
+ );
+
+ // Re-order scripts
+ $module = new ResourceLoaderFileModule( array(
+ 'scripts' => array( 'bar.js', 'foo.js' ),
+ ) + $baseParams );
+
+ $this->assertNotEquals(
+ $jsonSummary,
+ json_encode( $module->getDefinitionSummary( $context ) ),
+ 'Order of scripts is significant'
+ );
+
+ // Subclass
+ $module = new ResourceLoaderFileModuleTestModule( $baseParams );
+
+ $this->assertNotEquals(
+ $jsonSummary,
+ json_encode( $module->getDefinitionSummary( $context ) ),
+ 'Class is significant'
+ );
+ }
+}