5 * @group ResourceLoader
7 class ResourceLoaderFileModuleTest
extends ResourceLoaderTestCase
{
9 protected function setUp() {
12 // The return value of the closure shouldn't matter since this test should
14 SkinFactory
::getDefaultInstance()->register(
22 private static function getModules() {
24 'localBasePath' => realpath( __DIR__
),
28 'noTemplateModule' => array(),
30 'htmlTemplateModule' => $base +
array(
32 'templates/template.html',
33 'templates/template2.html',
37 'aliasedHtmlTemplateModule' => $base +
array(
39 'foo.html' => 'templates/template.html',
40 'bar.html' => 'templates/template2.html',
44 'templateModuleHandlebars' => $base +
array(
46 'templates/template_awesome.handlebars',
50 'aliasFooFromBar' => $base +
array(
52 'foo.foo' => 'templates/template.bar',
58 public static function providerTemplateDependencies() {
59 $modules = self
::getModules();
63 $modules['noTemplateModule'],
67 $modules['htmlTemplateModule'],
73 $modules['templateModuleHandlebars'],
76 'mediawiki.template.handlebars',
80 $modules['aliasFooFromBar'],
83 'mediawiki.template.foo',
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 );
100 * @covers ResourceLoaderFileModule::getAllStyleFiles
101 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
102 * @covers ResourceLoaderFileModule::getSkinStyleFiles
104 public function testGetAllSkinStyleFiles() {
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',
129 $module = new ResourceLoaderFileModule( $baseParams );
136 'quux-fallback.less',
141 array_map( 'basename', $module->getAllStyleFiles() )
146 * Strip @noflip annotations from CSS code.
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' ),
167 $expectedModule = new ResourceLoaderFileModule( array(
168 'localBasePath' => $basePath,
169 'styles' => array( 'expected.css' ),
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.
178 $expectedModule->getStyles( $contextLtr ),
179 self
::stripNoflip( $testModule->getStyles( $contextLtr ) ),
180 "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
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();
194 $modules['noTemplateModule'],
198 $modules['templateModuleHandlebars'],
200 'templates/template_awesome.handlebars' => "wow\n",
204 $modules['htmlTemplateModule'],
206 'templates/template.html' => "<strong>hello</strong>\n",
207 'templates/template2.html' => "<div>goodbye</div>\n",
211 $modules['aliasedHtmlTemplateModule'],
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 );