diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index 4b037e3a9..d478f674a 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -105,8 +105,8 @@ class JavascriptHelper extends AppHelper { if (!empty($script)) { $this->_cachedEvents[] = $script; + return null; } - return $this->tags['javascriptend']; } /** diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index 9f9efe03c..980972559 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -75,17 +75,43 @@ class JavascriptTest extends UnitTestCase { $result = $this->Javascript->object(array( '2007' => array( - 'Spring'=>array('1'=>array('id'=>'1','name'=>'Josh'), '2'=>array('id'=>'2','name'=>'Becky')), - 'Fall' => array('1'=>array('id'=>'1','name'=>'Josh'), '2'=>array('id'=>'2','name'=>'Becky')) + 'Spring' => array('1' => array('id' => '1', 'name' => 'Josh'), '2' => array('id' => '2', 'name' => 'Becky')), + 'Fall' => array('1' => array('id' => '1', 'name' => 'Josh'), '2' => array('id' => '2', 'name' => 'Becky')) ), '2006' => array( - 'Spring' => array('1'=>array('id'=>'1','name'=>'Josh'), '2'=>array('id'=>'2','name'=>'Becky')), - 'Fall' => array('1' => array('id'=>'1','name'=>'Josh'), '2'=>array('id'=>'2','name'=>'Becky') + 'Spring' => array('1' => array('id' => '1', 'name' => 'Josh'), '2' => array('id' => '2', 'name' => 'Becky')), + 'Fall' => array('1' => array('id' => '1', 'name' => 'Josh'), '2' => array('id' => '2', 'name' => 'Becky') )) )); $expected = '{"2007":{"Spring":{"1":{"id":1, "name":"Josh"}, "2":{"id":2, "name":"Becky"}}, "Fall":{"1":{"id":1, "name":"Josh"}, "2":{"id":2, "name":"Becky"}}}, "2006":{"Spring":{"1":{"id":1, "name":"Josh"}, "2":{"id":2, "name":"Becky"}}, "Fall":{"1":{"id":1, "name":"Josh"}, "2":{"id":2, "name":"Becky"}}}}'; $this->assertEqual($result, $expected); } + function testScriptBlock() { + $result = $this->Javascript->codeBlock("something"); + $this->assertPattern('/^]+>something<\/script>$/', $result); + $this->assertPattern('/^]+type="text\/javascript">something<\/script>$/', $result); + $this->assertPattern('/^]+type="text\/javascript"[^<>]*>/', $result); + $this->assertNoPattern('/^]*>/', $result); + + $result = $this->Javascript->codeBlock(); + $this->assertPattern('/^]+>$/', $result); + $this->assertNoPattern('/^]*>/', $result); + + $result = $this->Javascript->blockEnd(); + $this->assertEqual("", $result); + + $this->Javascript->cacheEvents(false, true); + $result = $this->Javascript->codeBlock(); + $this->assertIdentical($result, null); + echo 'alert("this is a buffered script");'; + + $result = $this->Javascript->blockEnd(); + $this->assertIdentical($result, null); + + $result = $this->Javascript->getCache(); + $this->assertEqual('alert("this is a buffered script");', $result); + } + function tearDown() { unset($this->Javascript); }