Permalink
Browse files

MINOR Updating code to support SS 3.0, still maintains backwards comp…

…atibility with 2.4, just not in the tests.
  • Loading branch information...
1 parent 18ab6d3 commit 6bbe69079d461f6495586e87436eef15f8ff542c @halkyon halkyon committed May 14, 2012
Showing with 24 additions and 43 deletions.
  1. +8 −8 code/MultiForm.php
  2. +10 −10 code/MultiFormStep.php
  3. +6 −25 tests/MultiFormTest.php
View
@@ -302,27 +302,27 @@ function getSavedStepByClass($className) {
}
/**
- * Build a FieldSet of the FormAction fields for the given step.
- *
+ * Build a FieldList of the FormAction fields for the given step.
+ *
* If the current step is the final step, we push in a submit button, which
* calls the action {@link finish()} to finalise the submission. Otherwise,
* we push in a next button which calls the action {@link next()} to determine
* where to go next in our step process, and save any form data collected.
- *
+ *
* If there's a previous step (a step that has the current step as it's next
* step class), then we allow a previous button, which calls the previous action
* to determine which step to go back to.
- *
+ *
* If there are any extra actions defined in MultiFormStep->getExtraActions()
* then that set of actions is appended to the end of the actions FieldSet we
* have created in this method.
- *
+ *
* @param $currentStep Subclass of MultiFormStep
- * @return FieldSet of FormAction objects
+ * @return FieldList of FormAction objects
*/
function actionsFor($step) {
// Create default multi step actions (next, prev), and merge with extra actions, if any
- $actions = new FieldSet();
+ $actions = (class_exists('FieldList')) ? new FieldList() : new FieldSet();
// If the form is at final step, create a submit button to perform final actions
// The last step doesn't have a next button, so add that action to any step that isn't the final one
@@ -543,7 +543,7 @@ public function setDisplayLink($link) {
* @return DataObjectSet
*/
public function getAllStepsLinear() {
- $stepsFound = new DataObjectSet();
+ $stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet();
$firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}");
$templateData = array(
View
@@ -75,11 +75,11 @@ class MultiFormStep extends DataObject {
/**
* Form fields to be rendered with this step.
* (Form object is created in {@link MultiForm}.
- *
+ *
* This function needs to be implemented on your
* subclasses of MultiFormStep.
*
- * @return FieldSet
+ * @return FieldList
*/
public function getFields() {
user_error('Please implement getFields on your MultiFormStep subclass', E_USER_ERROR);
@@ -88,14 +88,14 @@ public function getFields() {
/**
* Additional form actions to be added to this step.
* (Form object is created in {@link MultiForm}.
- *
+ *
* Note: This is optional, and is to be implemented
* on your subclasses of MultiFormStep.
- *
- * @return FieldSet
+ *
+ * @return FieldList
*/
public function getExtraActions() {
- return new FieldSet();
+ return (class_exists('FieldList')) ? new FieldList() : new FieldSet();
}
/**
@@ -166,15 +166,15 @@ public function saveData($data) {
* individually, rather than assuming that all data
* serialized through {@link saveData()} can be saved
* as a simple value outside of the original FormField context.
- *
+ *
* @param DataObject $obj
*/
public function saveInto($obj) {
$form = new Form(
Controller::curr(),
'Form',
$this->getFields(),
- new FieldSet()
+ ((class_exists('FieldList')) ? new FieldList() : new FieldSet())
);
$form->loadDataFrom($this->loadData());
$form->saveInto($obj);
@@ -185,11 +185,11 @@ public function saveInto($obj) {
* Custom validation for a step. In most cases, it should be sufficient
* to have built-in validation through the {@link Validator} class
* on the {@link getValidator()} method.
- *
+ *
* Use {@link Form->sessionMessage()} to feed back validation messages
* to the user. Please don't redirect from this method,
* this is taken care of in {@link next()}.
- *
+ *
* @param array $data Request data
* @param Form $form
* @return boolean Validation success
View
@@ -64,29 +64,10 @@ function testParentForm() {
function testTotalStepCount() {
$this->assertEquals(3, $this->form->getAllStepsLinear()->Count());
}
-
- // TODO Returns "page not found", doesn't test anything really
- // function testStepTraversal() {
- // $this->get($this->controller->class);
- //
- // $actionNextResponse = $this->submitForm('MultiFormTest_Form', 'action_next', array(
- // 'FirstName' => 'Joe',
- // 'Surname' => 'Bloggs',
- // 'Email' => 'joe@bloggs.com'
- // ));
- //
- // $this->assertEquals(200, $actionNextResponse->getStatusCode());
- // $this->assertNotNull($actionNextResponse->getBody());
- //
- // $actionPrevResponse = $this->submitForm('MultiFormTest_Form', 'action_prev');
- //
- // $this->assertEquals(200, $actionPrevResponse->getStatusCode());
- // $this->assertNotNull($actionPrevResponse->getBody());
- // }
-
+
function testCompletedSession() {
$this->form->setCurrentSessionHash($this->form->session->Hash);
- $this->assertType('MultiFormSession', $this->form->getCurrentSession());
+ $this->assertInstanceOf('MultiFormSession', $this->form->getCurrentSession());
$this->form->session->markCompleted();
$this->assertFalse($this->form->getCurrentSession());
}
@@ -96,7 +77,7 @@ function testIncorrectSessionIdentifier() {
$this->assertFalse($this->form->getCurrentSession());
// A new session is generated, even though we made up the identifier
- $this->assertType('MultiFormSession', $this->form->session);
+ $this->assertInstanceOf('MultiFormSession', $this->form->session);
}
}
@@ -127,7 +108,7 @@ class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepTwo';
function getFields() {
- return new FieldSet(
+ return new FieldList(
new TextField('FirstName', 'First name'),
new TextField('Surname', 'Surname'),
new EmailField('Email', 'Email address')
@@ -140,7 +121,7 @@ class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepThree';
function getFields() {
- return new FieldSet(
+ return new FieldList(
new TextareaField('Comments', 'Tell us a bit about yourself...')
);
}
@@ -151,7 +132,7 @@ class MultiFormTest_StepThree extends MultiFormStep implements TestOnly {
public static $is_final_step = true;
function getFields() {
- return new FieldSet(
+ return new FieldList(
new TextField('Test', 'Anything else you\'d like to tell us?')
);
}

0 comments on commit 6bbe690

Please sign in to comment.