4 * @group ResourceLoader
5 * @covers DerivativeResourceLoaderContext
7 class DerivativeResourceLoaderContextTest
extends PHPUnit_Framework_TestCase
{
9 protected static function getContext() {
10 $request = new FauxRequest( [
12 'modules' => 'test.context',
17 return new ResourceLoaderContext( new ResourceLoader(), $request );
20 public function testGetInherited() {
21 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
24 $this->assertEquals( $derived->getDebug(), false );
25 $this->assertEquals( $derived->getLanguage(), 'zh' );
26 $this->assertEquals( $derived->getModules(), [ 'test.context' ] );
27 $this->assertEquals( $derived->getOnly(), 'scripts' );
28 $this->assertEquals( $derived->getSkin(), 'fallback' );
29 $this->assertEquals( $derived->getUser(), null );
32 $this->assertEquals( $derived->getDirection(), 'ltr' );
33 $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
36 public function testModules() {
37 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
39 $derived->setModules( [ 'test.override' ] );
40 $this->assertEquals( $derived->getModules(), [ 'test.override' ] );
43 public function testLanguage() {
44 $context = self
::getContext();
45 $derived = new DerivativeResourceLoaderContext( $context );
47 $derived->setLanguage( 'nl' );
48 $this->assertEquals( $derived->getLanguage(), 'nl' );
51 public function testDirection() {
52 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
54 $derived->setLanguage( 'nl' );
55 $this->assertEquals( $derived->getDirection(), 'ltr' );
57 $derived->setLanguage( 'he' );
58 $this->assertEquals( $derived->getDirection(), 'rtl' );
60 $derived->setDirection( 'ltr' );
61 $this->assertEquals( $derived->getDirection(), 'ltr' );
64 public function testSkin() {
65 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
67 $derived->setSkin( 'override' );
68 $this->assertEquals( $derived->getSkin(), 'override' );
71 public function testUser() {
72 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
74 $derived->setUser( 'Example' );
75 $this->assertEquals( $derived->getUser(), 'Example' );
78 public function testDebug() {
79 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
81 $derived->setDebug( true );
82 $this->assertEquals( $derived->getDebug(), true );
85 public function testOnly() {
86 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
88 $derived->setOnly( 'styles' );
89 $this->assertEquals( $derived->getOnly(), 'styles' );
91 $derived->setOnly( null );
92 $this->assertEquals( $derived->getOnly(), null );
95 public function testVersion() {
96 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
98 $derived->setVersion( 'hw1' );
99 $this->assertEquals( $derived->getVersion(), 'hw1' );
102 public function testRaw() {
103 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
105 $derived->setRaw( true );
106 $this->assertEquals( $derived->getRaw(), true );
109 public function testGetHash() {
110 $derived = new DerivativeResourceLoaderContext( self
::getContext() );
112 $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
114 $derived->setLanguage( 'nl' );
115 $derived->setUser( 'Example' );
116 // Assert that subclass is able to clear parent class "hash" member
117 $this->assertEquals( $derived->getHash(), 'nl|fallback||Example|scripts|||||' );
120 public function testAccessors() {
121 $context = self
::getContext();
122 $derived = new DerivativeResourceLoaderContext( $context );
123 $this->assertSame( $derived->getRequest(), $context->getRequest() );
124 $this->assertSame( $derived->getResourceLoader(), $context->getResourceLoader() );