Permalink
Browse files

Merge pull request #143 from Innovatif/sapphire

---

BUGFIX Having <header tag in HTML causes requirements to double. See http://www.silverstripe.org/general-questions/show/17524
  • Loading branch information...
chillu committed Dec 23, 2011
1 parent 7d245c3 commit 565e2ab318f74d2c16f2f23ac7ca25b50438ee10
Showing with 19 additions and 1 deletion.
  1. +18 −0 tests/forms/RequirementsTest.php
  2. +1 −1 view/Requirements.php
@@ -264,6 +264,24 @@ function testConditionalTemplateRequire() {
$backend->assertFileIncluded('css', array($basePath .'/RequirementsTest_b.css', $basePath .'/RequirementsTest_c.css'));
Requirements::set_backend($holder);
}
function testJsWriteToBody() {
$backend = new Requirements_Backend();
$backend->javascript('http://www.mydomain.com/test.js');
// Test matching with HTML5 <header> tags as well
$template = '<html><head></head><body><header>My header</header><p>Body</p></body></html>';
$backend->set_write_js_to_body(false);
$html = $backend->includeInHTML(false, $template);
$this->assertContains('<head><script', $html);
$backend->set_write_js_to_body(true);
$html = $backend->includeInHTML(false, $template);
$this->assertNotContains('<head><script', $html);
$this->assertContains('</script></body>', $html);
}
}
class RequirementsTest_Backend extends Requirements_Backend implements TestOnly {
View
@@ -645,7 +645,7 @@ function restore() {
function includeInHTML($templateFile, $content) {
if(isset($_GET['debug_profile'])) Profiler::mark("Requirements::includeInHTML");
if(strpos($content, '</head') !== false && ($this->css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags)) {
if((strpos($content, '</head>') !== false || strpos($content, '</head ') !== false) && ($this->css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags)) {
$requirements = '';
$jsRequirements = '';

0 comments on commit 565e2ab

Please sign in to comment.