4 * @group ResourceLoader
6 class ResourceLoaderFileModuleTest
extends ResourceLoaderTestCase
{
8 protected function setUp() {
11 // The return value of the closure shouldn't matter since this test should
13 SkinFactory
::getDefaultInstance()->register(
21 private static function getModules() {
23 'localBasePath' => realpath( dirname( __FILE__
) ),
27 'noTemplateModule' => array(),
29 'htmlTemplateModule' => $base +
array(
31 'templates/template.html',
32 'templates/template2.html',
36 'aliasedHtmlTemplateModule' => $base +
array(
38 'foo.html' => 'templates/template.html',
39 'bar.html' => 'templates/template2.html',
43 'templateModuleHandlebars' => $base +
array(
45 'templates/template_awesome.handlebars',
49 'aliasFooFromBar' => $base +
array(
51 'foo.foo' => 'templates/template.bar',
57 public static function providerTemplateDependencies() {
58 $modules = self
::getModules();
62 $modules['noTemplateModule'],
66 $modules['htmlTemplateModule'],
72 $modules['templateModuleHandlebars'],
75 'mediawiki.template.handlebars',
79 $modules['aliasFooFromBar'],
82 'mediawiki.template.foo',
89 * @dataProvider providerTemplateDependencies
90 * @covers ResourceLoaderFileModule::__construct
91 * @covers ResourceLoaderFileModule::getDependencies
93 public function testTemplateDependencies( $module, $expected ) {
94 $rl = new ResourceLoaderFileModule( $module );
95 $this->assertEquals( $rl->getDependencies(), $expected );
99 * @covers ResourceLoaderFileModule::getAllStyleFiles
100 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
101 * @covers ResourceLoaderFileModule::getSkinStyleFiles
103 public function testGetAllSkinStyleFiles() {
111 'bar.css' => array( 'media' => 'print' ),
112 'screen.less' => array( 'media' => 'screen' ),
113 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
115 'skinStyles' => array(
116 'default' => 'quux-fallback.less',
128 $module = new ResourceLoaderFileModule( $baseParams );
135 'quux-fallback.less',
140 array_map( 'basename', $module->getAllStyleFiles() )
145 * Strip @noflip annotations from CSS code.
149 private static function stripNoflip( $css ) {
150 return str_replace( '/*@noflip*/ ', '', $css );
154 * What happens when you mix @embed and @noflip?
155 * This really is an integration test, but oh well.
157 * @covers ResourceLoaderFileModule::getStyles
158 * @covers ResourceLoaderFileModule::getStyleFiles
160 public function testMixedCssAnnotations( ) {
161 $basePath = __DIR__
. '/../../data/css';
162 $testModule = new ResourceLoaderFileModule( array(
163 'localBasePath' => $basePath,
164 'styles' => array( 'test.css' ),
166 $expectedModule = new ResourceLoaderFileModule( array(
167 'localBasePath' => $basePath,
168 'styles' => array( 'expected.css' ),
171 $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
172 $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
174 // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
175 // the @noflip annotations are always preserved, we need to strip them first.
177 $expectedModule->getStyles( $contextLtr ),
178 self
::stripNoflip( $testModule->getStyles( $contextLtr ) ),
179 "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
182 $expectedModule->getStyles( $contextLtr ),
183 self
::stripNoflip( $testModule->getStyles( $contextRtl ) ),
184 "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
188 public static function providerGetTemplates() {
189 $modules = self
::getModules();
193 $modules['noTemplateModule'],
197 $modules['templateModuleHandlebars'],
199 'templates/template_awesome.handlebars' => "wow\n",
203 $modules['htmlTemplateModule'],
205 'templates/template.html' => "<strong>hello</strong>\n",
206 'templates/template2.html' => "<div>goodbye</div>\n",
210 $modules['aliasedHtmlTemplateModule'],
212 'foo.html' => "<strong>hello</strong>\n",
213 'bar.html' => "<div>goodbye</div>\n",
220 * @dataProvider providerGetTemplates
221 * @covers ResourceLoaderFileModule::getTemplates
223 public function testGetTemplates( $module, $expected ) {
224 $rl = new ResourceLoaderFileModule( $module );
226 $this->assertEquals( $rl->getTemplates(), $expected );
229 public static function providerGetModifiedTime() {
230 $modules = self
::getModules();
233 // Check the default value when no templates present in module is 1
234 array( $modules['noTemplateModule'], 1 ),
239 * @dataProvider providerGetModifiedTime
240 * @covers ResourceLoaderFileModule::getModifiedTime
242 public function testGetModifiedTime( $module, $expected ) {
243 $rl = new ResourceLoaderFileModule( $module );
244 $ts = $rl->getModifiedTime( $this->getResourceLoaderContext() );
245 $this->assertEquals( $ts, $expected );