resourceloader: Implement '$pages' parameter to ResourceLoaderWikiModule constructor
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderWikiModuleTest.php
1 <?php
2
3 class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase {
4
5 /**
6 * @covers ResourceLoaderWikiModule::__construct
7 * @dataProvider provideConstructor
8 */
9 public function testConstructor( $params ) {
10 $module = new ResourceLoaderWikiModule( $params );
11 $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module );
12 }
13
14 public static function provideConstructor() {
15 return array(
16 // Nothing
17 array( null ),
18 array( array() ),
19 // Unrecognized settings
20 array( array( 'foo' => 'baz' ) ),
21 // Real settings
22 array( array( 'scripts' => array( 'MediaWiki:Common.js' ) ) ),
23 );
24 }
25
26 /**
27 * @dataProvider provideGetPages
28 * @covers ResourceLoaderWikiModule::getPages
29 */
30 public function testGetPages( $params, Config $config, $expected ) {
31 $module = new ResourceLoaderWikiModule( $params );
32 $module->setConfig( $config );
33
34 // Use getDefinitionSummary because getPages is protected
35 $summary = $module->getDefinitionSummary( ResourceLoaderContext::newDummyContext() );
36 $this->assertEquals(
37 $expected,
38 $summary['pages']
39 );
40 }
41
42 public static function provideGetPages() {
43 $settings = array(
44 'UseSiteJs' => true,
45 'UseSiteCss' => true,
46 );
47
48 $params = array(
49 'styles' => array( 'MediaWiki:Common.css' ),
50 'scripts' => array( 'MediaWiki:Common.js' ),
51 );
52
53 return array(
54 array( array(), new HashConfig( $settings ), array() ),
55 array( $params, new HashConfig( $settings ), array(
56 'MediaWiki:Common.js' => array( 'type' => 'script' ),
57 'MediaWiki:Common.css' => array( 'type' => 'style' )
58 ) ),
59 array( $params, new HashConfig( array( 'UseSiteCss' => false ) + $settings ), array(
60 'MediaWiki:Common.js' => array( 'type' => 'script' ),
61 ) ),
62 array( $params, new HashConfig( array( 'UseSiteJs' => false ) + $settings ), array(
63 'MediaWiki:Common.css' => array( 'type' => 'style' ),
64 ) ),
65 array( $params, new HashConfig( array( 'UseSiteJs' => false, 'UseSiteCss' => false ) ), array() ),
66 );
67 }
68
69 /**
70 * @covers ResourceLoaderWikiModule::getGroup
71 * @dataProvider provideGetGroup
72 */
73 public function testGetGroup( $params, $expected ) {
74 $module = new ResourceLoaderWikiModule( $params );
75 $this->assertEquals( $expected, $module->getGroup() );
76 }
77
78 public static function provideGetGroup() {
79 return array(
80 // No group specified
81 array( array(), null ),
82 // A random group
83 array( array( 'group' => 'foobar' ), 'foobar' ),
84 );
85 }
86
87 /**
88 * @covers ResourceLoaderWikiModule::isKnownEmpty
89 * @dataProvider provideIsKnownEmpty
90 */
91 public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
92 $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
93 ->setMethods( array( 'getTitleInfo', 'getGroup' ) )
94 ->getMock();
95 $module->expects( $this->any() )
96 ->method( 'getTitleInfo' )
97 ->will( $this->returnValue( $titleInfo ) );
98 $module->expects( $this->any() )
99 ->method( 'getGroup' )
100 ->will( $this->returnValue( $group ) );
101 $context = $this->getMockBuilder( 'ResourceLoaderContext' )
102 ->disableOriginalConstructor()
103 ->getMock();
104 $this->assertEquals( $expected, $module->isKnownEmpty( $context ) );
105 }
106
107 public static function provideIsKnownEmpty() {
108 return array(
109 // No valid pages
110 array( array(), 'test1', true ),
111 // 'site' module with a non-empty page
112 array(
113 array(
114 'MediaWiki:Common.js' => array(
115 'timestamp' => 123456789,
116 'length' => 1234
117 )
118 ), 'site', false,
119 ),
120 // 'site' module with an empty page
121 array(
122 array(
123 'MediaWiki:Monobook.js' => array(
124 'timestamp' => 987654321,
125 'length' => 0,
126 ),
127 ), 'site', false,
128 ),
129 // 'user' module with a non-empty page
130 array(
131 array(
132 'User:FooBar/common.js' => array(
133 'timestamp' => 246813579,
134 'length' => 25,
135 ),
136 ), 'user', false,
137 ),
138 // 'user' module with an empty page
139 array(
140 array(
141 'User:FooBar/monobook.js' => array(
142 'timestamp' => 1357924680,
143 'length' => 0,
144 ),
145 ), 'user', true,
146 ),
147 );
148 }
149 }