Use display name in category page subheadings if provided
[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 [
16 // Nothing
17 [ null ],
18 [ [] ],
19 // Unrecognized settings
20 [ [ 'foo' => 'baz' ] ],
21 // Real settings
22 [ [ 'scripts' => [ '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 // Because getPages is protected..
35 $getPages = new ReflectionMethod( $module, 'getPages' );
36 $getPages->setAccessible( true );
37 $out = $getPages->invoke( $module, ResourceLoaderContext::newDummyContext() );
38 $this->assertEquals( $expected, $out );
39 }
40
41 public static function provideGetPages() {
42 $settings = self::getSettings() + [
43 'UseSiteJs' => true,
44 'UseSiteCss' => true,
45 ];
46
47 $params = [
48 'styles' => [ 'MediaWiki:Common.css' ],
49 'scripts' => [ 'MediaWiki:Common.js' ],
50 ];
51
52 $variableParams = [
53 'allowVariables' => true,
54 'styles' => [ 'MediaWiki:Common.css', 'MediaWiki:{skin}.css' ],
55 'scripts' => [ 'MediaWiki:Common.js', 'MediaWiki:{skin}.js' ],
56 ];
57
58 return [
59 [ [], new HashConfig( $settings ), [] ],
60 [ $params, new HashConfig( $settings ), [
61 'MediaWiki:Common.js' => [ 'type' => 'script' ],
62 'MediaWiki:Common.css' => [ 'type' => 'style' ]
63 ] ],
64 [ $params, new HashConfig( [ 'UseSiteCss' => false ] + $settings ), [
65 'MediaWiki:Common.js' => [ 'type' => 'script' ],
66 ] ],
67 [ $params, new HashConfig( [ 'UseSiteJs' => false ] + $settings ), [
68 'MediaWiki:Common.css' => [ 'type' => 'style' ],
69 ] ],
70 [ $params,
71 new HashConfig(
72 [ 'UseSiteJs' => false, 'UseSiteCss' => false ]
73 ),
74 []
75 ],
76 [ $variableParams, new HashConfig( $settings ), [
77 'MediaWiki:Common.js' => [ 'type' => 'script' ],
78 'MediaWiki:vector.js' => [ 'type' => 'script' ],
79 'MediaWiki:Common.css' => [ 'type' => 'style' ],
80 'MediaWiki:vector.css' => [ 'type' => 'style' ]
81 ] ],
82 ];
83 }
84
85 /**
86 * @covers ResourceLoaderWikiModule::getGroup
87 * @dataProvider provideGetGroup
88 */
89 public function testGetGroup( $params, $expected ) {
90 $module = new ResourceLoaderWikiModule( $params );
91 $this->assertEquals( $expected, $module->getGroup() );
92 }
93
94 public static function provideGetGroup() {
95 return [
96 // No group specified
97 [ [], null ],
98 // A random group
99 [ [ 'group' => 'foobar' ], 'foobar' ],
100 ];
101 }
102
103 /**
104 * @covers ResourceLoaderWikiModule::isKnownEmpty
105 * @dataProvider provideIsKnownEmpty
106 */
107 public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
108 $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
109 ->setMethods( [ 'getTitleInfo', 'getGroup' ] )
110 ->getMock();
111 $module->expects( $this->any() )
112 ->method( 'getTitleInfo' )
113 ->will( $this->returnValue( $titleInfo ) );
114 $module->expects( $this->any() )
115 ->method( 'getGroup' )
116 ->will( $this->returnValue( $group ) );
117 $context = $this->getMockBuilder( 'ResourceLoaderContext' )
118 ->disableOriginalConstructor()
119 ->getMock();
120 $this->assertEquals( $expected, $module->isKnownEmpty( $context ) );
121 }
122
123 public static function provideIsKnownEmpty() {
124 return [
125 // No valid pages
126 [ [], 'test1', true ],
127 // 'site' module with a non-empty page
128 [
129 [ 'MediaWiki:Common.js' => [ 'rev_sha1' => 'dmh6qn', 'rev_len' => 1234 ] ],
130 'site',
131 false,
132 ],
133 // 'site' module with an empty page
134 [
135 [ 'MediaWiki:Foo.js' => [ 'rev_sha1' => 'phoi', 'rev_len' => 0 ] ],
136 'site',
137 false,
138 ],
139 // 'user' module with a non-empty page
140 [
141 [ 'User:Example/common.js' => [ 'rev_sha1' => 'j7ssba', 'rev_len' => 25 ] ],
142 'user',
143 false,
144 ],
145 // 'user' module with an empty page
146 [
147 [ 'User:Example/foo.js' => [ 'rev_sha1' => 'phoi', 'rev_len' => 0 ] ],
148 'user',
149 true,
150 ],
151 ];
152 }
153 }