MINOR Updating code to support SS 3.0, still maintains backwards compatibility with 2.4, just not in the tests.

This commit is contained in:
Sean Harvey 2012-05-14 15:23:01 +12:00
parent 18ab6d3933
commit 6bbe69079d
3 changed files with 24 additions and 43 deletions

View File

@ -302,7 +302,7 @@ abstract class MultiForm extends Form {
}
/**
* 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,
@ -318,11 +318,11 @@ abstract class MultiForm extends Form {
* 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 @@ abstract class MultiForm extends Form {
* @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 File

@ -79,7 +79,7 @@ class MultiFormStep extends DataObject {
* 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);
@ -92,10 +92,10 @@ class MultiFormStep extends DataObject {
* 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();
}
/**
@ -174,7 +174,7 @@ class MultiFormStep extends DataObject {
Controller::curr(),
'Form',
$this->getFields(),
new FieldSet()
((class_exists('FieldList')) ? new FieldList() : new FieldSet())
);
$form->loadDataFrom($this->loadData());
$form->saveInto($obj);

View File

@ -65,28 +65,9 @@ class MultiFormTest extends FunctionalTest {
$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 @@ class MultiFormTest extends FunctionalTest {
$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?')
);
}