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',
52 * @covers ResourceLoaderFileModule::getAllStyleFiles
53 * @covers ResourceLoaderFileModule::getAllSkinStyleFiles
54 * @covers ResourceLoaderFileModule::getSkinStyleFiles
56 public function testGetAllSkinStyleFiles() {
64 'bar.css' => array( 'media' => 'print' ),
65 'screen.less' => array( 'media' => 'screen' ),
66 'screen-query.css' => array( 'media' => 'screen and (min-width: 400px)' ),
68 'skinStyles' => array(
69 'default' => 'quux-fallback.less',
81 $module = new ResourceLoaderFileModule( $baseParams );
93 array_map( 'basename', $module->getAllStyleFiles() )
98 * Strip @noflip annotations from CSS code.
102 private static function stripNoflip( $css ) {
103 return str_replace( '/*@noflip*/ ', '', $css );
107 * What happens when you mix @embed and @noflip?
108 * This really is an integration test, but oh well.
110 * @covers ResourceLoaderFileModule::getStyles
111 * @covers ResourceLoaderFileModule::getStyleFiles
113 public function testMixedCssAnnotations( ) {
114 $basePath = __DIR__
. '/../../data/css';
115 $testModule = new ResourceLoaderFileModule( array(
116 'localBasePath' => $basePath,
117 'styles' => array( 'test.css' ),
119 $expectedModule = new ResourceLoaderFileModule( array(
120 'localBasePath' => $basePath,
121 'styles' => array( 'expected.css' ),
124 $contextLtr = $this->getResourceLoaderContext( 'en', 'ltr' );
125 $contextRtl = $this->getResourceLoaderContext( 'he', 'rtl' );
127 // Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
128 // the @noflip annotations are always preserved, we need to strip them first.
130 $expectedModule->getStyles( $contextLtr ),
131 self
::stripNoflip( $testModule->getStyles( $contextLtr ) ),
132 "/*@noflip*/ with /*@embed*/ gives correct results in LTR mode"
135 $expectedModule->getStyles( $contextLtr ),
136 self
::stripNoflip( $testModule->getStyles( $contextRtl ) ),
137 "/*@noflip*/ with /*@embed*/ gives correct results in RTL mode"
141 public static function providerGetTemplates() {
142 $modules = self
::getModules();
146 $modules['noTemplateModule'],
150 $modules['templateModuleHandlebars'],
152 'templates/template_awesome.handlebars' => "wow\n",
156 $modules['htmlTemplateModule'],
158 'templates/template.html' => "<strong>hello</strong>\n",
159 'templates/template2.html' => "<div>goodbye</div>\n",
163 $modules['aliasedHtmlTemplateModule'],
165 'foo.html' => "<strong>hello</strong>\n",
166 'bar.html' => "<div>goodbye</div>\n",
173 * @dataProvider providerGetTemplates
174 * @covers ResourceLoaderFileModule::getTemplates
176 public function testGetTemplates( $module, $expected ) {
177 $rl = new ResourceLoaderFileModule( $module );
179 $this->assertEquals( $rl->getTemplates(), $expected );
182 public static function providerGetModifiedTime() {
183 $modules = self
::getModules();
186 // Check the default value when no templates present in module is 1
187 array( $modules['noTemplateModule'], 1 ),
192 * @dataProvider providerGetModifiedTime
193 * @covers ResourceLoaderFileModule::getModifiedTime
195 public function testGetModifiedTime( $module, $expected ) {
196 $rl = new ResourceLoaderFileModule( $module );
197 $ts = $rl->getModifiedTime( $this->getResourceLoaderContext() );
198 $this->assertEquals( $ts, $expected );