Fix requirements tests

This commit is contained in:
Damian Mooyman 2017-10-03 14:21:24 +13:00
parent 5ffe64f024
commit f4a77649a4
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
2 changed files with 5 additions and 6 deletions

View File

@ -84,7 +84,7 @@ class ModuleResourceLoader implements TemplateGlobalProvider
protected function resolveModuleResource($resource) protected function resolveModuleResource($resource)
{ {
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL // String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
if (!preg_match('#(?<module>[^/: ]*/[^/: ]*) *: *(?<resource>[^ ]*)#', $resource, $matches)) { if (!preg_match('#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#', $resource, $matches)) {
return null; return null;
} }
$module = $matches['module']; $module = $matches['module'];

View File

@ -818,20 +818,19 @@ class RequirementsTest extends SapphireTest
public function testCommentedOutScriptTagIsIgnored() public function testCommentedOutScriptTagIsIgnored()
{ {
/// Disable nonce /// Disable nonce
Injector::inst()->registerService(new SimpleResourceURLGenerator(), ResourceURLGenerator::class); $urlGenerator = new SimpleResourceURLGenerator();
Injector::inst()->registerService($urlGenerator, ResourceURLGenerator::class);
$template = '<html><head></head><body><!--<script>alert("commented out");</script>-->' $template = '<html><head></head><body><!--<script>alert("commented out");</script>-->'
. '<h1>more content</h1></body></html>'; . '<h1>more content</h1></body></html>';
/** /** @var Requirements_Backend $backend */
* @var Requirements_Backend $backend
*/
$backend = Injector::inst()->create(Requirements_Backend::class); $backend = Injector::inst()->create(Requirements_Backend::class);
$this->setupRequirements($backend); $this->setupRequirements($backend);
$src = $this->getThemeRoot() . '/javascript/RequirementsTest_a.js'; $src = $this->getThemeRoot() . '/javascript/RequirementsTest_a.js';
$urlSrc = Controller::join_links(Director::baseURL(), $src);
$backend->javascript($src); $backend->javascript($src);
$html = $backend->includeInHTML($template); $html = $backend->includeInHTML($template);
$urlSrc = $urlGenerator->urlForResource($src);
$this->assertEquals( $this->assertEquals(
'<html><head></head><body><!--<script>alert("commented out");</script>-->' '<html><head></head><body><!--<script>alert("commented out");</script>-->'
. '<h1>more content</h1><script type="application/javascript" src="' . $urlSrc . '<h1>more content</h1><script type="application/javascript" src="' . $urlSrc