diff options
Diffstat (limited to 'tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php')
-rw-r--r-- | tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php | 78 |
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|' ); + } + +} |