4 * @group ResourceLoader
6 class DerivativeResourceLoaderContextTest
extends PHPUnit_Framework_TestCase
{
8 protected static function getResourceLoaderContext() {
9 $resourceLoader = new ResourceLoader();
10 $request = new FauxRequest( array(
12 'modules' => 'test.context',
17 return new ResourceLoaderContext( $resourceLoader, $request );
20 public function testGet() {
21 $context = self
::getResourceLoaderContext();
22 $derived = new DerivativeResourceLoaderContext( $context );
24 $this->assertEquals( $derived->getLanguage(), 'zh' );
25 $this->assertEquals( $derived->getModules(), array( 'test.context' ) );
26 $this->assertEquals( $derived->getOnly(), 'scripts' );
27 $this->assertEquals( $derived->getSkin(), 'fallback' );
28 $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
31 public function testSetLanguage() {
32 $context = self
::getResourceLoaderContext();
33 $derived = new DerivativeResourceLoaderContext( $context );
35 $derived->setLanguage( 'nl' );
36 $this->assertEquals( $derived->getLanguage(), 'nl' );
38 $derived->setLanguage( 'he' );
39 $this->assertEquals( $derived->getDirection(), 'rtl' );
42 public function testSetModules() {
43 $context = self
::getResourceLoaderContext();
44 $derived = new DerivativeResourceLoaderContext( $context );
46 $derived->setModules( array( 'test.override' ) );
47 $this->assertEquals( $derived->getModules(), array( 'test.override' ) );
50 public function testSetOnly() {
51 $context = self
::getResourceLoaderContext();
52 $derived = new DerivativeResourceLoaderContext( $context );
54 $derived->setOnly( 'styles' );
55 $this->assertEquals( $derived->getOnly(), 'styles' );
57 $derived->setOnly( null );
58 $this->assertEquals( $derived->getOnly(), null );
61 public function testSetSkin() {
62 $context = self
::getResourceLoaderContext();
63 $derived = new DerivativeResourceLoaderContext( $context );
65 $derived->setSkin( 'override' );
66 $this->assertEquals( $derived->getSkin(), 'override' );
69 public function testGetHash() {
70 $context = self
::getResourceLoaderContext();
71 $derived = new DerivativeResourceLoaderContext( $context );
73 $derived->setLanguage( 'nl' );
74 // Assert that subclass is able to clear parent class "hash" member
75 $this->assertEquals( $derived->getHash(), 'nl|fallback|||scripts|||||' );