Merge "Fix the (un)watch token to include the namespace name."
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderModuleTest.php
1 <?php
2
3 class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
4
5 protected function setUp() {
6 parent::setUp();
7
8 // The return value of the closure shouldn't matter since this test should
9 // never call it
10 SkinFactory::getDefaultInstance()->register( 'fakeskin', 'FakeSkin', function(){});
11 }
12
13 /**
14 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
15 */
16 public function testGetAllSkinStyleFiles() {
17 $context = self::getResourceLoaderContext();
18
19 $baseParams = array(
20 'scripts' => array(
21 'foo.js',
22 'bar.js',
23 ),
24 'styles' => array(
25 'foo.css',
26 'bar.css' => array( 'media' => 'print' ),
27 'screen.less' => array( 'media' => 'screen' ),
28 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
29 ),
30 'skinStyles' => array(
31 'default' => 'quux-fallback.less',
32 'fakeskin' => array(
33 'baz-vector.css',
34 'quux-vector.less',
35 ),
36 ),
37 'messages' => array(
38 'hello',
39 'world',
40 ),
41 );
42
43 $module = new ResourceLoaderFileModule( $baseParams );
44
45 $this->assertEquals(
46 array(
47 'foo.css',
48 'baz-vector.css',
49 'quux-vector.less',
50 'quux-fallback.less',
51 'bar.css',
52 'screen.less',
53 'screen-query.css',
54 ),
55 array_map( 'basename', $module->getAllStyleFiles() )
56 );
57 }
58
59 /**
60 * @covers ResourceLoaderModule::getDefinitionSummary
61 * @covers ResourceLoaderFileModule::getDefinitionSummary
62 */
63 public function testDefinitionSummary() {
64 $context = self::getResourceLoaderContext();
65
66 $baseParams = array(
67 'scripts' => array( 'foo.js', 'bar.js' ),
68 'dependencies' => array( 'jquery', 'mediawiki' ),
69 'messages' => array( 'hello', 'world' ),
70 );
71
72 $module = new ResourceLoaderFileModule( $baseParams );
73
74 $jsonSummary = json_encode( $module->getDefinitionSummary( $context ) );
75
76 // Exactly the same
77 $module = new ResourceLoaderFileModule( $baseParams );
78
79 $this->assertEquals(
80 $jsonSummary,
81 json_encode( $module->getDefinitionSummary( $context ) ),
82 'Instance is insignificant'
83 );
84
85 // Re-order dependencies
86 $module = new ResourceLoaderFileModule( array(
87 'dependencies' => array( 'mediawiki', 'jquery' ),
88 ) + $baseParams );
89
90 $this->assertEquals(
91 $jsonSummary,
92 json_encode( $module->getDefinitionSummary( $context ) ),
93 'Order of dependencies is insignificant'
94 );
95
96 // Re-order messages
97 $module = new ResourceLoaderFileModule( array(
98 'messages' => array( 'world', 'hello' ),
99 ) + $baseParams );
100
101 $this->assertEquals(
102 $jsonSummary,
103 json_encode( $module->getDefinitionSummary( $context ) ),
104 'Order of messages is insignificant'
105 );
106
107 // Re-order scripts
108 $module = new ResourceLoaderFileModule( array(
109 'scripts' => array( 'bar.js', 'foo.js' ),
110 ) + $baseParams );
111
112 $this->assertNotEquals(
113 $jsonSummary,
114 json_encode( $module->getDefinitionSummary( $context ) ),
115 'Order of scripts is significant'
116 );
117
118 // Subclass
119 $module = new ResourceLoaderFileModuleTestModule( $baseParams );
120
121 $this->assertNotEquals(
122 $jsonSummary,
123 json_encode( $module->getDefinitionSummary( $context ) ),
124 'Class is significant'
125 );
126 }
127 }