This ResourceLoader module provides a way to ship messages to CSS variables. We will need this going forward to deal with flash of unstyled content in various JavaScript based UIs that are subject to i18n such as table sorting and collapsible elements. To avoid overhead of hitting the database to fetch and transform localisation messages we make use of the MessageBlobStore making use of `messages` definition already inside ResourceLoaderFileModule. Given this resource is only intended for render blocking styles without JavaScript this should be okay (although if requested in JavaScript will also ship associated messages) Bug: T42812 Change-Id: I2bf12cdc848478889acbe9a7a970e46f8aefa287
43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group ResourceLoader
|
|
*/
|
|
class ResourceLoaderLessVarFileModuleTest extends ResourceLoaderTestCase {
|
|
|
|
public static function providerWrapAndEscapeMessage() {
|
|
return [
|
|
[
|
|
"Foo", '"Foo"',
|
|
],
|
|
[
|
|
"Foo bananas", '"Foo bananas"',
|
|
],
|
|
[
|
|
"Who's that test? Who's that test? It's Jess!",
|
|
'"Who\\\'s that test? Who\\\'s that test? It\\\'s Jess!"',
|
|
],
|
|
[
|
|
'Hello "he" said',
|
|
'"Hello \"he\" said"',
|
|
],
|
|
[
|
|
'boo";-o-link:javascript:alert(1);color:red;content:"',
|
|
'"boo\";-o-link:javascript:alert(1);color:red;content:\""',
|
|
],
|
|
[
|
|
'"jon\'s"',
|
|
'"\"jon\\\'s\""'
|
|
]
|
|
];
|
|
}
|
|
/**
|
|
* @dataProvider providerWrapAndEscapeMessage
|
|
* @covers ResourceLoaderLessVarFileModule::wrapAndEscapeMessage
|
|
*/
|
|
public function testEscapeMessage( $msg, $expected ) {
|
|
$method = new ReflectionMethod( ResourceLoaderLessVarFileModule::class, 'wrapAndEscapeMessage' );
|
|
$method->setAccessible( true );
|
|
$this->assertEquals( $expected, $method->invoke( ResourceLoaderLessVarFileModule::class, $msg ) );
|
|
}
|
|
}
|