From a3d5a9beae22f0a4e6460f9cedd3200909d5fadd Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 21 Jul 2009 00:24:58 -0400 Subject: [PATCH] Adding stubs for JsHelper::submit() --- cake/libs/view/helpers/js.php | 12 ++++++++ .../tests/cases/libs/view/helpers/js.test.php | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index 1b9b0c690a0..65a838669a1 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -233,6 +233,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. diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index e4ebc9e5284..33ca8d54022 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -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); + } }