Permalink
Browse files

Adding stubs for JsHelper::submit()

  • Loading branch information...
1 parent a5bfe72 commit a3d5a9beae22f0a4e6460f9cedd3200909d5fadd @markstory markstory committed Jul 21, 2009
Showing with 40 additions and 0 deletions.
  1. +12 −0 cake/libs/view/helpers/js.php
  2. +28 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -234,6 +234,18 @@ function link($title, $url = null, $options = array()) {
return $out;
}
/**
+ * Uses the selected JS engine to create a submit input
+ * element that is enhanced with Javascript. Options can include
+ * both those for FormHelper::submit() and JsBaseEngine::request(), JsBaseEngine::event();
+ *
+ * @param string $title The display text of the submit button.
+ * @param array $options Array of options to use.
+ * @return string Completed submit button.
+ **/
+ function submit($title, $options = array()) {
+
+ }
+/**
* Parse a set of Options and extract the Html options.
* Extracted Html Options are removed from the $options param.
*
@@ -289,6 +289,34 @@ function testLinkWithMock() {
);
$this->assertTags($result, $expected);
}
+/**
+ * test submit() with a Mock to check Engine method calls
+ *
+ * @return void
+ **/
+ function testSubmitWithMock() {
+ $this->_useMock();
+ $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', '*'));
+ $this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array(
+ 'event', array('click', "serialize-code\najax-code", $options)
+ ));
+ $result = $this->Js->submit('Save', $options);
+ $expected = array(
+ 'div' => array('class' => 'input submit'),
+ 'input' => array('type' => 'submit', 'id' => $options['id'], 'value' => 'Save'),
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+ }
}

0 comments on commit a3d5a9b

Please sign in to comment.