summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-20 09:00:55 +0100
commita2190ac74dd4d7080b12bab90e552d7aa81209ef (patch)
tree8b31f38de9882d18df54cf8d9e0de74167a094eb /tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
parent15e69f7b20b6596b9148030acce5b59993b95a45 (diff)
parent257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff)
Merge branch 'mw-1.26'
Diffstat (limited to 'tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php b/tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
new file mode 100644
index 00000000..0d11f621
--- /dev/null
+++ b/tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * @group ResourceLoader
+ */
+class DerivativeResourceLoaderContextTest extends PHPUnit_Framework_TestCase {
+
+ protected static function getResourceLoaderContext() {
+ $resourceLoader = new ResourceLoader();
+ $request = new FauxRequest( array(
+ 'lang' => 'zh',
+ 'modules' => 'test.context',
+ 'only' => 'scripts',
+ 'skin' => 'fallback',
+ 'target' => 'test',
+ ) );
+ return new ResourceLoaderContext( $resourceLoader, $request );
+ }
+
+ public function testGet() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $this->assertEquals( $derived->getLanguage(), 'zh' );
+ $this->assertEquals( $derived->getModules(), array( 'test.context' ) );
+ $this->assertEquals( $derived->getOnly(), 'scripts' );
+ $this->assertEquals( $derived->getSkin(), 'fallback' );
+ $this->assertEquals( $derived->getHash(), 'zh|ltr|fallback||||||scripts|' );
+ }
+
+ public function testSetLanguage() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $derived->setLanguage( 'nl' );
+ $this->assertEquals( $derived->getLanguage(), 'nl' );
+
+ $derived->setLanguage( 'he' );
+ $this->assertEquals( $derived->getDirection(), 'rtl' );
+ }
+
+ public function testSetModules() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $derived->setModules( array( 'test.override' ) );
+ $this->assertEquals( $derived->getModules(), array( 'test.override' ) );
+ }
+
+ public function testSetOnly() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $derived->setOnly( 'styles' );
+ $this->assertEquals( $derived->getOnly(), 'styles' );
+
+ $derived->setOnly( null );
+ $this->assertEquals( $derived->getOnly(), null );
+ }
+
+ public function testSetSkin() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $derived->setSkin( 'override' );
+ $this->assertEquals( $derived->getSkin(), 'override' );
+ }
+
+ public function testGetHash() {
+ $context = self::getResourceLoaderContext();
+ $derived = new DerivativeResourceLoaderContext( $context );
+
+ $derived->setLanguage( 'nl' );
+ // Assert that subclass is able to clear parent class "hash" member
+ $this->assertEquals( $derived->getHash(), 'nl|ltr|fallback||||||scripts|' );
+ }
+
+}