summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/resourceloader/DerivativeResourceLoaderContextTest.php
blob: 0d11f6210aa9da0fde93058cd11a719cc3115aae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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|' );
	}

}