Merge "Special:Search: Remove token from URL when saving settings"
[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(
11 'fakeskin',
12 'FakeSkin',
13 function(){
14 }
15 );
16 }
17
18 /**
19 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
20 */
21 public function testGetAllSkinStyleFiles() {
22 $context = self::getResourceLoaderContext();
23
24 $baseParams = array(
25 'scripts' => array(
26 'foo.js',
27 'bar.js',
28 ),
29 'styles' => array(
30 'foo.css',
31 'bar.css' => array( 'media' => 'print' ),
32 'screen.less' => array( 'media' => 'screen' ),
33 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
34 ),
35 'skinStyles' => array(
36 'default' => 'quux-fallback.less',
37 'fakeskin' => array(
38 'baz-vector.css',
39 'quux-vector.less',
40 ),
41 ),
42 'messages' => array(
43 'hello',
44 'world',
45 ),
46 );
47
48 $module = new ResourceLoaderFileModule( $baseParams );
49
50 $this->assertEquals(
51 array(
52 'foo.css',
53 'baz-vector.css',
54 'quux-vector.less',
55 'quux-fallback.less',
56 'bar.css',
57 'screen.less',
58 'screen-query.css',
59 ),
60 array_map( 'basename', $module->getAllStyleFiles() )
61 );
62 }
63
64 /**
65 * @covers ResourceLoaderModule::getDefinitionSummary
66 * @covers ResourceLoaderFileModule::getDefinitionSummary
67 */
68 public function testDefinitionSummary() {
69 $context = self::getResourceLoaderContext();
70
71 $baseParams = array(
72 'scripts' => array( 'foo.js', 'bar.js' ),
73 'dependencies' => array( 'jquery', 'mediawiki' ),
74 'messages' => array( 'hello', 'world' ),
75 );
76
77 $module = new ResourceLoaderFileModule( $baseParams );
78
79 $jsonSummary = json_encode( $module->getDefinitionSummary( $context ) );
80
81 // Exactly the same
82 $module = new ResourceLoaderFileModule( $baseParams );
83
84 $this->assertEquals(
85 $jsonSummary,
86 json_encode( $module->getDefinitionSummary( $context ) ),
87 'Instance is insignificant'
88 );
89
90 // Re-order dependencies
91 $module = new ResourceLoaderFileModule( array(
92 'dependencies' => array( 'mediawiki', 'jquery' ),
93 ) + $baseParams );
94
95 $this->assertEquals(
96 $jsonSummary,
97 json_encode( $module->getDefinitionSummary( $context ) ),
98 'Order of dependencies is insignificant'
99 );
100
101 // Re-order messages
102 $module = new ResourceLoaderFileModule( array(
103 'messages' => array( 'world', 'hello' ),
104 ) + $baseParams );
105
106 $this->assertEquals(
107 $jsonSummary,
108 json_encode( $module->getDefinitionSummary( $context ) ),
109 'Order of messages is insignificant'
110 );
111
112 // Re-order scripts
113 $module = new ResourceLoaderFileModule( array(
114 'scripts' => array( 'bar.js', 'foo.js' ),
115 ) + $baseParams );
116
117 $this->assertNotEquals(
118 $jsonSummary,
119 json_encode( $module->getDefinitionSummary( $context ) ),
120 'Order of scripts is significant'
121 );
122
123 // Subclass
124 $module = new ResourceLoaderFileModuleTestModule( $baseParams );
125
126 $this->assertNotEquals(
127 $jsonSummary,
128 json_encode( $module->getDefinitionSummary( $context ) ),
129 'Class is significant'
130 );
131 }
132 }