Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / resourceloader / ResourceLoaderFileModuleTest.php
bloba6d1d05effa2ca02f4fdafe4ea5a4d978f830cbf
1 <?php
3 /**
4 * @group Database
5 * @group ResourceLoader
6 */
7 class ResourceLoaderFileModuleTest extends ResourceLoaderTestCase {
9 protected function setUp() {
10 parent::setUp();
12 // The return value of the closure shouldn't matter since this test should
13 // never call it
14 SkinFactory::getDefaultInstance()->register(
15 'fakeskin',
16 'FakeSkin',
17 function () {
22 private static function getModules() {
23 $base = array(
24 'localBasePath' => realpath( __DIR__ ),
27 return array(
28 'noTemplateModule' => array(),
30 'htmlTemplateModule' => $base + array(
31 'templates' => array(
32 'templates/template.html',
33 'templates/template2.html',
37 'aliasedHtmlTemplateModule' => $base + array(
38 'templates' => array(
39 'foo.html' => 'templates/template.html',
40 'bar.html' => 'templates/template2.html',
44 'templateModuleHandlebars' => $base + array(
45 'templates' => array(
46 'templates/template_awesome.handlebars',
50 'aliasFooFromBar' => $base + array(
51 'templates' => array(
52 'foo.foo' => 'templates/template.bar',
58 public static function providerTemplateDependencies() {
59 $modules = self::getModules();
61 return array(
62 array(
63 $modules['noTemplateModule'],
64 array(),
66 array(
67 $modules['htmlTemplateModule'],
68 array(
69 'mediawiki.template',
72 array(
73 $modules['templateModuleHandlebars'],
74 array(
75 'mediawiki.template',
76 'mediawiki.template.handlebars',
79 array(
80 $modules['aliasFooFromBar'],
81 array(
82 'mediawiki.template',
83 'mediawiki.template.foo',
89 /**
90 * @dataProvider providerTemplateDependencies
91 * @covers ResourceLoaderFileModule::__construct
92 * @covers ResourceLoaderFileModule::getDependencies
94 public function testTemplateDependencies( $module, $expected ) {
95 $rl = new ResourceLoaderFileModule( $module );
96 $this->assertEquals( $rl->getDependencies(), $expected );
99 /**
100 * @covers ResourceLoaderFileModule::getAllStyleFiles
101 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
102 * @covers ResourceLoaderFileModule::getSkinStyleFiles
104 public function testGetAllSkinStyleFiles() {
105 $baseParams = array(
106 'scripts' => array(
107 'foo.js',
108 'bar.js',
110 'styles' => array(
111 'foo.css',
112 'bar.css' => array( 'media' => 'print' ),
113 'screen.less' => array( 'media' => 'screen' ),
114 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
116 'skinStyles' => array(
117 'default' => 'quux-fallback.less',
118 'fakeskin' => array(
119 'baz-vector.css',
120 'quux-vector.less',
123 'messages' => array(
124 'hello',
125 'world',
129 $module = new ResourceLoaderFileModule( $baseParams );
131 $this->assertEquals(
132 array(
133 'foo.css',
134 'baz-vector.css',
135 'quux-vector.less',
136 'quux-fallback.less',
137 'bar.css',
138 'screen.less',
139 'screen-query.css',
141 array_map( 'basename', $module->getAllStyleFiles() )
146 * Strip @noflip annotations from CSS code.
147 * @param string $css
148 * @return string
150 private static function stripNoflip( $css ) {
151 return str_replace( '/*@noflip*/ ', '', $css );
155 * What happens when you mix @embed and @noflip?
156 * This really is an integration test, but oh well.
158 * @covers ResourceLoaderFileModule::getStyles
159 * @covers ResourceLoaderFileModule::getStyleFiles
161 public function testMixedCssAnnotations() {
162 $basePath = __DIR__ . '/../../data/css';
163 $testModule = new ResourceLoaderFileModule( array(
164 'localBasePath' => $basePath,
165 'styles' => array( 'test.css' ),
166 ) );
167 $expectedModule = new ResourceLoaderFileModule( array(
168 'localBasePath' => $basePath,
169 'styles' => array( 'expected.css' ),
170 ) );
172 $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
173 $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
175 // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
176 // the @noflip annotations are always preserved, we need to strip them first.
177 $this->assertEquals(
178 $expectedModule->getStyles( $contextLtr ),
179 self::stripNoflip( $testModule->getStyles( $contextLtr ) ),
180 "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
182 $this->assertEquals(
183 $expectedModule->getStyles( $contextLtr ),
184 self::stripNoflip( $testModule->getStyles( $contextRtl ) ),
185 "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
189 public static function providerGetTemplates() {
190 $modules = self::getModules();
192 return array(
193 array(
194 $modules['noTemplateModule'],
195 array(),
197 array(
198 $modules['templateModuleHandlebars'],
199 array(
200 'templates/template_awesome.handlebars' => "wow\n",
203 array(
204 $modules['htmlTemplateModule'],
205 array(
206 'templates/template.html' => "<strong>hello</strong>\n",
207 'templates/template2.html' => "<div>goodbye</div>\n",
210 array(
211 $modules['aliasedHtmlTemplateModule'],
212 array(
213 'foo.html' => "<strong>hello</strong>\n",
214 'bar.html' => "<div>goodbye</div>\n",
221 * @dataProvider providerGetTemplates
222 * @covers ResourceLoaderFileModule::getTemplates
224 public function testGetTemplates( $module, $expected ) {
225 $rl = new ResourceLoaderFileModule( $module );
227 $this->assertEquals( $rl->getTemplates(), $expected );