5 * - ResourceLoaderTest::testExpandModuleNames
6 * - ResourceLoaderImageModuleTest::testContext
9 * @covers ResourceLoaderContext
11 class ResourceLoaderContextTest
extends PHPUnit_Framework_TestCase
{
12 protected static function getResourceLoader() {
13 return new EmptyResourceLoader( new HashConfig( [
14 'ResourceLoaderDebug' => false,
15 'DefaultSkin' => 'fallback',
16 'LanguageCode' => 'nl',
20 public function testEmpty() {
21 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
24 $this->assertEquals( [], $ctx->getModules() );
25 $this->assertEquals( 'nl', $ctx->getLanguage() );
26 $this->assertEquals( false, $ctx->getDebug() );
27 $this->assertEquals( null, $ctx->getOnly() );
28 $this->assertEquals( 'fallback', $ctx->getSkin() );
29 $this->assertEquals( null, $ctx->getUser() );
32 $this->assertEquals( 'ltr', $ctx->getDirection() );
33 $this->assertEquals( 'nl|fallback||||||||', $ctx->getHash() );
34 $this->assertInstanceOf( User
::class, $ctx->getUserObj() );
37 public function testDummy() {
38 $this->assertInstanceOf(
39 ResourceLoaderContext
::class,
40 ResourceLoaderContext
::newDummyContext()
44 public function testAccessors() {
45 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
46 $this->assertInstanceOf( WebRequest
::class, $ctx->getRequest() );
47 $this->assertInstanceOf( \Psr\Log\LoggerInterface
::class, $ctx->getLogger() );
50 public function testTypicalRequest() {
51 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
54 'modules' => 'foo|foo.quux,baz,bar|baz.quux',
62 [ 'foo', 'foo.quux', 'foo.baz', 'foo.bar', 'baz.quux' ]
64 $this->assertEquals( false, $ctx->getDebug() );
65 $this->assertEquals( 'zh', $ctx->getLanguage() );
66 $this->assertEquals( 'styles', $ctx->getOnly() );
67 $this->assertEquals( 'fallback', $ctx->getSkin() );
68 $this->assertEquals( null, $ctx->getUser() );
71 $this->assertEquals( 'ltr', $ctx->getDirection() );
72 $this->assertEquals( 'zh|fallback|||styles|||||', $ctx->getHash() );
75 public function testShouldInclude() {
76 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
77 $this->assertTrue( $ctx->shouldIncludeScripts(), 'Scripts in combined' );
78 $this->assertTrue( $ctx->shouldIncludeStyles(), 'Styles in combined' );
79 $this->assertTrue( $ctx->shouldIncludeMessages(), 'Messages in combined' );
81 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
84 $this->assertFalse( $ctx->shouldIncludeScripts(), 'Scripts not in styles-only' );
85 $this->assertTrue( $ctx->shouldIncludeStyles(), 'Styles in styles-only' );
86 $this->assertFalse( $ctx->shouldIncludeMessages(), 'Messages not in styles-only' );
88 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
91 $this->assertTrue( $ctx->shouldIncludeScripts(), 'Scripts in scripts-only' );
92 $this->assertFalse( $ctx->shouldIncludeStyles(), 'Styles not in scripts-only' );
93 $this->assertFalse( $ctx->shouldIncludeMessages(), 'Messages not in scripts-only' );
96 public function testGetUser() {
97 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
98 $this->assertSame( null, $ctx->getUser() );
99 $this->assertTrue( $ctx->getUserObj()->isAnon() );
101 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
104 $this->assertSame( 'Example', $ctx->getUser() );
105 $this->assertEquals( 'Example', $ctx->getUserObj()->getName() );