Skip to content
Permalink
Browse files

Fixing parameters from leaking into the script tag when calling JsHel…

…per::submit(). Added test cases and refactored JsHelper::link(). Fixes #613
  • Loading branch information...
markstory committed Apr 23, 2010
1 parent e4ea82d commit 57648c5492806a351b2af0e5e13852063b39be51
Showing with 40 additions and 5 deletions.
  1. +3 −5 cake/libs/view/helpers/js.php
  2. +37 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -311,10 +311,7 @@ public function link($title, $url = null, $options = array()) {
$event = $this->event('click', $requestString, $options);
}
if (isset($options['buffer']) && $options['buffer'] == false) {
$opts = array();
if (isset($options['safe'])) {
$opts['safe'] = $options['safe'];
}
$opts = array_intersect_key(array('safe' => null), $options);
$out .= $this->Html->scriptBlock($event, $opts);
}
return $out;
@@ -387,7 +384,8 @@ public function submit($caption = null, $options = array()) {
$event = $this->event('click', $requestString, $options);
}
if (isset($options['buffer']) && $options['buffer'] == false) {
$out .= $this->Html->scriptBlock($event, $options);
$opts = array_intersect_key(array('safe' => null), $options);
$out .= $this->Html->scriptBlock($event, $opts);
}
return $out;
}
@@ -456,6 +456,43 @@ function testSubmitWithMock() {
$this->assertTags($result, $expected);
}
/**
* test that no buffer works with submit() and that parameters are leaking into the script tag.
*
* @return void
*/
function testSubmitWithNoBuffer() {
$this->_useMock();
$options = array('update' => '#content', 'id' => 'test-submit', 'buffer' => false, 'safe' => false);
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'serialize-code', array('serializeform', '*'));
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'serialize-code', array('serializeForm', '*'));
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'ajax-code', array('request', '*'));
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'event-handler', array('event', '*'));
$this->Js->TestJsEngine->expectAt(0, 'dispatchMethod', array('get', '*'));
$this->Js->TestJsEngine->expectAt(1, 'dispatchMethod', array(new PatternExpectation('/serializeForm/i'), '*'));
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array('request', '*'));
$params = array(
'update' => $options['update'], 'buffer' => false, 'safe' => false, 'data' => 'serialize-code',
'method' => 'post', 'dataExpression' => true
);
$this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
'event', array('click', "ajax-code", $params)
));
$result = $this->Js->submit('Save', $options);
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save'),
'/div',
'script' => array('type' => 'text/javascript'),
'event-handler',
'/script'
);
$this->assertTags($result, $expected);
}
/**
* Test that Object::Object() is not breaking json output in JsHelper
*

0 comments on commit 57648c5

Please sign in to comment.
You can’t perform that action at this time.