Merge "SpecialMovepage: Convert form to use OOUI controls"
[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 // 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() + array(
43 'UseSiteJs' => true,
44 'UseSiteCss' => true,
45 );
46
47 $params = array(
48 'styles' => array( 'MediaWiki:Common.css' ),
49 'scripts' => array( 'MediaWiki:Common.js' ),
50 );
51
52 return array(
53 array( array(), new HashConfig( $settings ), array() ),
54 array( $params, new HashConfig( $settings ), array(
55 'MediaWiki:Common.js' => array( 'type' => 'script' ),
56 'MediaWiki:Common.css' => array( 'type' => 'style' )
57 ) ),
58 array( $params, new HashConfig( array( 'UseSiteCss' => false ) + $settings ), array(
59 'MediaWiki:Common.js' => array( 'type' => 'script' ),
60 ) ),
61 array( $params, new HashConfig( array( 'UseSiteJs' => false ) + $settings ), array(
62 'MediaWiki:Common.css' => array( 'type' => 'style' ),
63 ) ),
64 array( $params, new HashConfig( array( 'UseSiteJs' => false, 'UseSiteCss' => false ) ), array() ),
65 );
66 }
67
68 /**
69 * @covers ResourceLoaderWikiModule::getGroup
70 * @dataProvider provideGetGroup
71 */
72 public function testGetGroup( $params, $expected ) {
73 $module = new ResourceLoaderWikiModule( $params );
74 $this->assertEquals( $expected, $module->getGroup() );
75 }
76
77 public static function provideGetGroup() {
78 return array(
79 // No group specified
80 array( array(), null ),
81 // A random group
82 array( array( 'group' => 'foobar' ), 'foobar' ),
83 );
84 }
85
86 /**
87 * @covers ResourceLoaderWikiModule::isKnownEmpty
88 * @dataProvider provideIsKnownEmpty
89 */
90 public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
91 $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
92 ->setMethods( array( 'getTitleInfo', 'getGroup' ) )
93 ->getMock();
94 $module->expects( $this->any() )
95 ->method( 'getTitleInfo' )
96 ->will( $this->returnValue( $titleInfo ) );
97 $module->expects( $this->any() )
98 ->method( 'getGroup' )
99 ->will( $this->returnValue( $group ) );
100 $context = $this->getMockBuilder( 'ResourceLoaderContext' )
101 ->disableOriginalConstructor()
102 ->getMock();
103 $this->assertEquals( $expected, $module->isKnownEmpty( $context ) );
104 }
105
106 public static function provideIsKnownEmpty() {
107 return array(
108 // No valid pages
109 array( array(), 'test1', true ),
110 // 'site' module with a non-empty page
111 array(
112 array( 'MediaWiki:Common.js' => array( 'rev_sha1' => 'dmh6qn', 'rev_len' => 1234 ) ),
113 'site',
114 false,
115 ),
116 // 'site' module with an empty page
117 array(
118 array( 'MediaWiki:Foo.js' => array( 'rev_sha1' => 'phoi', 'rev_len' => 0 ) ),
119 'site',
120 false,
121 ),
122 // 'user' module with a non-empty page
123 array(
124 array( 'User:Example/common.js' => array( 'rev_sha1' => 'j7ssba', 'rev_len' => 25 ) ),
125 'user',
126 false,
127 ),
128 // 'user' module with an empty page
129 array(
130 array( 'User:Example/foo.js' => array( 'rev_sha1' => 'phoi', 'rev_len' => 0 ) ),
131 'user',
132 true,
133 ),
134 );
135 }
136 }