Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for custom url on submit()

  • Loading branch information...
commit 49e0e5743f4486a3edb98497606ca2849ef6a839 1 parent e8b39fb
@markstory markstory authored
View
1  cake/libs/view/helpers/js.php
@@ -267,7 +267,6 @@ function submit($caption = null, $options = array()) {
$url = $options['url'];
unset($options['url']);
}
-
$requestString .= $this->request($url, $options);
if (!empty($requestString)) {
$event = $this->event('click', $requestString, $options);
View
37 cake/tests/cases/libs/view/helpers/js.test.php
@@ -346,30 +346,49 @@ function testLinkWithNoBuffering() {
**/
function testSubmitWithMock() {
$this->_useMock();
- $options = array(
- 'update' => '#content',
- 'id' => 'test-submit'
- );
+
+ $options = array('update' => '#content', 'id' => 'test-submit');
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'serialize-code', array('serializeForm', '*'));
$this->Js->TestJsEngine->setReturnValue('dispatchMethod', 'ajax-code', array('request', '*'));
$this->Js->TestJsEngine->expectAt(0, 'dispatchMethod', array('get', '*'));
$this->Js->TestJsEngine->expectAt(1, 'dispatchMethod', array('serializeForm', '*'));
$this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array('request', '*'));
- $params = array(
- 'update' => $options['update'],
- 'data' => 'serialize-code'
- );
+
+ $params = array('update' => $options['update'], 'data' => 'serialize-code');
$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'
);
- $this->assertTags($result, $expected, true);
+ $this->assertTags($result, $expected);
+
+
+ $this->Js->TestJsEngine->expectAt(4, 'dispatchMethod', array('get', '*'));
+ $this->Js->TestJsEngine->expectAt(5, 'dispatchMethod', array('serializeForm', '*'));
+ $requestParams = array(
+ '/custom/url', array('update' => '#content', 'data' => 'serialize-code')
+ );
+ $this->Js->TestJsEngine->expectAt(6, 'dispatchMethod', array('request', $requestParams));
+
+ $params = array('update' => '#content', 'data' => 'serialize-code');
+ $this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array(
+ 'event', array('click', "ajax-code", $params)
+ ));
+
+ $options = array('update' => '#content', 'id' => 'test-submit', 'url' => '/custom/url');
+ $result = $this->Js->submit('Save', $options);
+ $expected = array(
+ 'div' => array('class' => 'submit'),
+ 'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save'),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.