3 class ResourceLoaderWikiModuleTest
extends ResourceLoaderTestCase
{
6 * @covers ResourceLoaderWikiModule::__construct
7 * @dataProvider provideConstructor
9 public function testConstructor( $params ) {
10 $module = new ResourceLoaderWikiModule( $params );
11 $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module );
14 public static function provideConstructor() {
19 // Unrecognized settings
20 array( array( 'foo' => 'baz' ) ),
22 array( array( 'scripts' => array( 'MediaWiki:Common.js' ) ) ),
27 * @dataProvider provideGetPages
28 * @covers ResourceLoaderWikiModule::getPages
30 public function testGetPages( $params, Config
$config, $expected ) {
31 $module = new ResourceLoaderWikiModule( $params );
32 $module->setConfig( $config );
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 );
41 public static function provideGetPages() {
42 $settings = self
::getSettings() +
array(
48 'styles' => array( 'MediaWiki:Common.css' ),
49 'scripts' => array( 'MediaWiki:Common.js' ),
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' )
58 array( $params, new HashConfig( array( 'UseSiteCss' => false ) +
$settings ), array(
59 'MediaWiki:Common.js' => array( 'type' => 'script' ),
61 array( $params, new HashConfig( array( 'UseSiteJs' => false ) +
$settings ), array(
62 'MediaWiki:Common.css' => array( 'type' => 'style' ),
66 array( 'UseSiteJs' => false, 'UseSiteCss' => false )
74 * @covers ResourceLoaderWikiModule::getGroup
75 * @dataProvider provideGetGroup
77 public function testGetGroup( $params, $expected ) {
78 $module = new ResourceLoaderWikiModule( $params );
79 $this->assertEquals( $expected, $module->getGroup() );
82 public static function provideGetGroup() {
85 array( array(), null ),
87 array( array( 'group' => 'foobar' ), 'foobar' ),
92 * @covers ResourceLoaderWikiModule::isKnownEmpty
93 * @dataProvider provideIsKnownEmpty
95 public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
96 $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
97 ->setMethods( array( 'getTitleInfo', 'getGroup' ) )
99 $module->expects( $this->any() )
100 ->method( 'getTitleInfo' )
101 ->will( $this->returnValue( $titleInfo ) );
102 $module->expects( $this->any() )
103 ->method( 'getGroup' )
104 ->will( $this->returnValue( $group ) );
105 $context = $this->getMockBuilder( 'ResourceLoaderContext' )
106 ->disableOriginalConstructor()
108 $this->assertEquals( $expected, $module->isKnownEmpty( $context ) );
111 public static function provideIsKnownEmpty() {
114 array( array(), 'test1', true ),
115 // 'site' module with a non-empty page
117 array( 'MediaWiki:Common.js' => array( 'rev_sha1' => 'dmh6qn', 'rev_len' => 1234 ) ),
121 // 'site' module with an empty page
123 array( 'MediaWiki:Foo.js' => array( 'rev_sha1' => 'phoi', 'rev_len' => 0 ) ),
127 // 'user' module with a non-empty page
129 array( 'User:Example/common.js' => array( 'rev_sha1' => 'j7ssba', 'rev_len' => 25 ) ),
133 // 'user' module with an empty page
135 array( 'User:Example/foo.js' => array( 'rev_sha1' => 'phoi', 'rev_len' => 0 ) ),