Fixing return value for JavascriptHelper::blockEnd() for script caching (Ticket #3172)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5686 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-09-23 14:23:39 +00:00
parent 52f1e2dc5c
commit 8f4dd39257
2 changed files with 31 additions and 5 deletions

View file

@ -105,8 +105,8 @@ class JavascriptHelper extends AppHelper {
if (!empty($script)) {
$this->_cachedEvents[] = $script;
return null;
}
return $this->tags['javascriptend'];
}
/**

View file

@ -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('/^<script[^<>]+>something<\/script>$/', $result);
$this->assertPattern('/^<script[^<>]+type="text\/javascript">something<\/script>$/', $result);
$this->assertPattern('/^<script[^<>]+type="text\/javascript"[^<>]*>/', $result);
$this->assertNoPattern('/^<script[^type]=[^<>]*>/', $result);
$result = $this->Javascript->codeBlock();
$this->assertPattern('/^<script[^<>]+>$/', $result);
$this->assertNoPattern('/^<script[^type]=[^<>]*>/', $result);
$result = $this->Javascript->blockEnd();
$this->assertEqual("</script>", $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);
}