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',
17 'LoadScript' => '/w/load.php',
21 public function testEmpty() {
22 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
25 $this->assertEquals( [], $ctx->getModules() );
26 $this->assertEquals( 'nl', $ctx->getLanguage() );
27 $this->assertEquals( false, $ctx->getDebug() );
28 $this->assertEquals( null, $ctx->getOnly() );
29 $this->assertEquals( 'fallback', $ctx->getSkin() );
30 $this->assertEquals( null, $ctx->getUser() );
33 $this->assertEquals( 'ltr', $ctx->getDirection() );
34 $this->assertEquals( 'nl|fallback||||||||', $ctx->getHash() );
35 $this->assertInstanceOf( User
::class, $ctx->getUserObj() );
38 public function testDummy() {
39 $this->assertInstanceOf(
40 ResourceLoaderContext
::class,
41 ResourceLoaderContext
::newDummyContext()
45 public function testAccessors() {
46 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
47 $this->assertInstanceOf( WebRequest
::class, $ctx->getRequest() );
48 $this->assertInstanceOf( \Psr\Log\LoggerInterface
::class, $ctx->getLogger() );
51 public function testTypicalRequest() {
52 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
55 'modules' => 'foo|foo.quux,baz,bar|baz.quux',
63 [ 'foo', 'foo.quux', 'foo.baz', 'foo.bar', 'baz.quux' ]
65 $this->assertEquals( false, $ctx->getDebug() );
66 $this->assertEquals( 'zh', $ctx->getLanguage() );
67 $this->assertEquals( 'styles', $ctx->getOnly() );
68 $this->assertEquals( 'fallback', $ctx->getSkin() );
69 $this->assertEquals( null, $ctx->getUser() );
72 $this->assertEquals( 'ltr', $ctx->getDirection() );
73 $this->assertEquals( 'zh|fallback|||styles|||||', $ctx->getHash() );
76 public function testShouldInclude() {
77 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
78 $this->assertTrue( $ctx->shouldIncludeScripts(), 'Scripts in combined' );
79 $this->assertTrue( $ctx->shouldIncludeStyles(), 'Styles in combined' );
80 $this->assertTrue( $ctx->shouldIncludeMessages(), 'Messages in combined' );
82 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
85 $this->assertFalse( $ctx->shouldIncludeScripts(), 'Scripts not in styles-only' );
86 $this->assertTrue( $ctx->shouldIncludeStyles(), 'Styles in styles-only' );
87 $this->assertFalse( $ctx->shouldIncludeMessages(), 'Messages not in styles-only' );
89 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
92 $this->assertTrue( $ctx->shouldIncludeScripts(), 'Scripts in scripts-only' );
93 $this->assertFalse( $ctx->shouldIncludeStyles(), 'Styles not in scripts-only' );
94 $this->assertFalse( $ctx->shouldIncludeMessages(), 'Messages not in scripts-only' );
97 public function testGetUser() {
98 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [] ) );
99 $this->assertSame( null, $ctx->getUser() );
100 $this->assertTrue( $ctx->getUserObj()->isAnon() );
102 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
105 $this->assertSame( 'Example', $ctx->getUser() );
106 $this->assertEquals( 'Example', $ctx->getUserObj()->getName() );
109 public function testMsg() {
110 $ctx = new ResourceLoaderContext( $this->getResourceLoader(), new FauxRequest( [
113 $msg = $ctx->msg( 'mainpage' );
114 $this->assertInstanceOf( Message
::class, $msg );
115 $this->assertSame( 'Main Page', $msg->useDatabase( false )->plain() );