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