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
This commit is contained in:
Ingo Schommer 2011-12-23 16:33:45 +01:00
parent 7d245c3803
commit 565e2ab318
2 changed files with 19 additions and 1 deletions

View File

@ -264,6 +264,24 @@ class RequirementsTest extends SapphireTest {
$backend->assertFileIncluded('css', array($basePath .'/RequirementsTest_b.css', $basePath .'/RequirementsTest_c.css')); $backend->assertFileIncluded('css', array($basePath .'/RequirementsTest_b.css', $basePath .'/RequirementsTest_c.css'));
Requirements::set_backend($holder); 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 { class RequirementsTest_Backend extends Requirements_Backend implements TestOnly {

View File

@ -645,7 +645,7 @@ class Requirements_Backend {
function includeInHTML($templateFile, $content) { function includeInHTML($templateFile, $content) {
if(isset($_GET['debug_profile'])) Profiler::mark("Requirements::includeInHTML"); 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 = ''; $requirements = '';
$jsRequirements = ''; $jsRequirements = '';