MediaWiki  1.27.2
ResourceLoaderWikiModuleTest.php
Go to the documentation of this file.
1 <?php
2 
4 
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 
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  return [
53  [ [], new HashConfig( $settings ), [] ],
54  [ $params, new HashConfig( $settings ), [
55  'MediaWiki:Common.js' => [ 'type' => 'script' ],
56  'MediaWiki:Common.css' => [ 'type' => 'style' ]
57  ] ],
58  [ $params, new HashConfig( [ 'UseSiteCss' => false ] + $settings ), [
59  'MediaWiki:Common.js' => [ 'type' => 'script' ],
60  ] ],
61  [ $params, new HashConfig( [ 'UseSiteJs' => false ] + $settings ), [
62  'MediaWiki:Common.css' => [ 'type' => 'style' ],
63  ] ],
64  [ $params,
65  new HashConfig(
66  [ 'UseSiteJs' => false, 'UseSiteCss' => false ]
67  ),
68  []
69  ],
70  ];
71  }
72 
77  public function testGetGroup( $params, $expected ) {
78  $module = new ResourceLoaderWikiModule( $params );
79  $this->assertEquals( $expected, $module->getGroup() );
80  }
81 
82  public static function provideGetGroup() {
83  return [
84  // No group specified
85  [ [], null ],
86  // A random group
87  [ [ 'group' => 'foobar' ], 'foobar' ],
88  ];
89  }
90 
95  public function testIsKnownEmpty( $titleInfo, $group, $expected ) {
96  $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' )
97  ->setMethods( [ 'getTitleInfo', 'getGroup' ] )
98  ->getMock();
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()
107  ->getMock();
108  $this->assertEquals( $expected, $module->isKnownEmpty( $context ) );
109  }
110 
111  public static function provideIsKnownEmpty() {
112  return [
113  // No valid pages
114  [ [], 'test1', true ],
115  // 'site' module with a non-empty page
116  [
117  [ 'MediaWiki:Common.js' => [ 'rev_sha1' => 'dmh6qn', 'rev_len' => 1234 ] ],
118  'site',
119  false,
120  ],
121  // 'site' module with an empty page
122  [
123  [ 'MediaWiki:Foo.js' => [ 'rev_sha1' => 'phoi', 'rev_len' => 0 ] ],
124  'site',
125  false,
126  ],
127  // 'user' module with a non-empty page
128  [
129  [ 'User:Example/common.js' => [ 'rev_sha1' => 'j7ssba', 'rev_len' => 25 ] ],
130  'user',
131  false,
132  ],
133  // 'user' module with an empty page
134  [
135  [ 'User:Example/foo.js' => [ 'rev_sha1' => 'phoi', 'rev_len' => 0 ] ],
136  'user',
137  true,
138  ],
139  ];
140  }
141 }
Abstraction for ResourceLoader modules which pull from wiki pages.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:762
testGetPages($params, Config $config, $expected)
provideGetPages ResourceLoaderWikiModule::getPages
$context
Definition: load.php:44
static newDummyContext()
Return a dummy ResourceLoaderContext object suitable for passing into things that don't "really" need...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1798
$params
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testConstructor($params)
ResourceLoaderWikiModule::__construct provideConstructor.
testGetGroup($params, $expected)
ResourceLoaderWikiModule::getGroup provideGetGroup.
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
testIsKnownEmpty($titleInfo, $group, $expected)
ResourceLoaderWikiModule::isKnownEmpty provideIsKnownEmpty.