mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 09:05:49 +00:00
MINOR Tidy up of tests
This commit is contained in:
parent
07120018bf
commit
8e04dfbaa5
@ -1,5 +1,2 @@
|
||||
<?php
|
||||
|
||||
// This file is required in order for SilverStripe to detect this directory as a module.
|
||||
|
||||
?>
|
@ -89,7 +89,7 @@ abstract class MultiForm extends Form {
|
||||
$this->setCurrentStep($currentStep);
|
||||
|
||||
// Set the form of the step to this form instance
|
||||
$currentStep->form = $this;
|
||||
$currentStep->setForm($this);
|
||||
|
||||
// Set up the fields for the current step
|
||||
$fields = $currentStep->getFields();
|
||||
@ -171,6 +171,8 @@ abstract class MultiForm extends Form {
|
||||
$currentStep->write();
|
||||
}
|
||||
|
||||
$currentStep->setForm($this);
|
||||
|
||||
return $currentStep;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests for {@link MultiFormSessionTest}
|
||||
*
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormSessionTest extends SapphireTest {
|
||||
|
||||
/**
|
||||
@ -8,14 +13,13 @@ class MultiFormSessionTest extends SapphireTest {
|
||||
* the object in our tests by assigning $this->session
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->session = new MultiFormSession();
|
||||
$this->session->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test generation of a new session.
|
||||
*
|
||||
* @TODO Write some more advanced tests for MultiFormSession.
|
||||
*/
|
||||
function testSessionGeneration() {
|
||||
$this->assertTrue($this->session->ID != 0);
|
||||
@ -35,13 +39,4 @@ class MultiFormSessionTest extends SapphireTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the MultiFormSession record that we created.
|
||||
*/
|
||||
function tearDown() {
|
||||
$this->session->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,74 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MultiFormTest
|
||||
* For testing purposes, we have some test classes:
|
||||
*
|
||||
* @TODO create some behavioural test cases, such as examining what occurs after
|
||||
* submitting the "previous", "next" form actions that a user would normally
|
||||
* be doing.
|
||||
* - MultiFormTest_Controller (simulation of a real Controller class)
|
||||
* - MultiFormTest_Form (subclass of MultiForm)
|
||||
* - MultiFormTest_StepOne (subclass of MultiFormStep)
|
||||
* - MultiFormTest_StepTwo (subclass of MultiFormStep)
|
||||
* - MultiFormTest_StepThree (subclass of MultiFormStep)
|
||||
*
|
||||
* For testing purposes, we have some test MultiForm classes:
|
||||
* The above classes are used to simulate real-world behaviour
|
||||
* of the multiform module - for example, MultiFormTest_Controller
|
||||
* is a simulation of a page where MultiFormTest_Form is a simple
|
||||
* multi-step contact form it belongs to.
|
||||
*
|
||||
* - MultiFormTestClass (subclass of MultiForm)
|
||||
* - MultiFormTestStepOne (subclass of MultiFormStep - the first step)
|
||||
* - MultiFormTestStepTwo (subclass of MultiFormStep - the second step)
|
||||
* - MultiFormTestStepThree (subclass of MultiFormStep - the third step)
|
||||
*
|
||||
* These test classes should be used for testing the operation of a "real"
|
||||
* instance of this multiform step system. Also, as a note here: every instance
|
||||
* of MultiFormStep, which is every step in a form, requires a db/build, as it
|
||||
* is a subclass of DataObject. This is a bit of a pain, but it's required for
|
||||
* the database to store the step data for each step, which is very important!
|
||||
* @package multiform
|
||||
* @subpackage tests
|
||||
*/
|
||||
class MultiFormTest extends SapphireTest {
|
||||
class MultiFormTest extends FunctionalTest {
|
||||
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* Set up the instance of MultiForm, writing a record
|
||||
* to the database for this test. We persist the object
|
||||
* in our tests by assigning $this->getSession()
|
||||
*/
|
||||
function setUp() {
|
||||
$this->form = new MultiFormTestClass(new Controller(), 'Form');
|
||||
parent::setUp();
|
||||
$this->controller = new MultiFormTest_Controller();
|
||||
$this->form = $this->controller->Form();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests initialising a new instance of a test class.
|
||||
*
|
||||
* @TODO Write some decent tests! The current assertions are very basic, and are
|
||||
* nowhere near touching on the more advanced concepts of MultiForm, such
|
||||
* as the form actions (prev/next), session handling, and step handling
|
||||
* through {@link MultiFormStep->getPreviousStep()} and
|
||||
* {@link MultiFormStep->getNextStep()} for example.
|
||||
*/
|
||||
function testInitialisingForm() {
|
||||
$this->assertTrue(is_numeric($this->form->getCurrentStep()->ID) && ($this->form->getCurrentStep()->ID > 0));
|
||||
$this->assertTrue(is_numeric($this->form->getSession()->ID) && ($this->form->getSession()->ID > 0));
|
||||
$this->assertEquals('MultiFormTestStepOne', $this->form->getStartStep());
|
||||
$this->assertEquals('MultiFormTest_StepOne', $this->form->getStartStep());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the 2nd step is correct to what we expect it to be.
|
||||
*/
|
||||
function testSecondStep() {
|
||||
$this->assertEquals('MultiFormTestStepTwo', $this->form->getCurrentStep()->getNextStep());
|
||||
$this->assertEquals('MultiFormTest_StepTwo', $this->form->getCurrentStep()->getNextStep());
|
||||
}
|
||||
|
||||
function testParentForm() {
|
||||
$currentStep = $this->form->getCurrentStep();
|
||||
$this->assertEquals($currentStep->getForm()->class, $this->form->class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the amount of steps we have has been calculated correctly.
|
||||
*/
|
||||
function testTotalStepCount() {
|
||||
$this->assertEquals(3, $this->form->getAllStepsLinear()->Count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the session data that was created. Note: This should delete all the
|
||||
* dependencies such as MultiFormStep instances that are related directly to
|
||||
* this session. These directives can be found on {@link MultiFormSession->onBeforeWrite()}
|
||||
*/
|
||||
function tearDown() {
|
||||
$this->form->getSession()->delete();
|
||||
/*function testNextStepAction() {
|
||||
$this->get($this->controller->class);
|
||||
$response = $this->submitForm('MultiFormTest_Form', 'next', array(
|
||||
'FirstName' => 'Joe',
|
||||
'Surname' => 'Bloggs',
|
||||
'Email' => 'joe@bloggs.com'
|
||||
));
|
||||
|
||||
$this->assertNotNull($response->getBody());
|
||||
}*/
|
||||
|
||||
}
|
||||
class MultiFormTest_Controller extends Controller implements TestOnly {
|
||||
|
||||
function Link($action = null) {
|
||||
return $this->class . '/' . $action;
|
||||
}
|
||||
|
||||
public function Form($request = null) {
|
||||
$form = new MultiFormTest_Form($this, 'Form');
|
||||
$form->setHTMLID('MultiFormTest_Form');
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
class MultiFormTest_Form extends MultiForm implements TestOnly {
|
||||
|
||||
protected static $start_step = 'MultiFormTest_StepOne';
|
||||
|
||||
function getStartStep() {
|
||||
return $this->stat('start_step');
|
||||
}
|
||||
|
||||
}
|
||||
class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $next_steps = 'MultiFormTest_StepTwo';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('FirstName', 'First name'),
|
||||
new TextField('Surname', 'Surname'),
|
||||
new EmailField('Email', 'Email address')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $next_steps = 'MultiFormTest_StepThree';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextareaField('Comments', 'Tell us a bit about yourself...')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
class MultiFormTest_StepThree extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $is_final_step = true;
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('Test', 'Anything else you\'d like to tell us?')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
class MultiFormTestClass extends MultiForm implements TestOnly {
|
||||
|
||||
protected static $start_step = 'MultiFormTestStepOne';
|
||||
|
||||
/**
|
||||
* Accessor method to $start_step
|
||||
* @return string
|
||||
*/
|
||||
function getStartStep() {
|
||||
return $this->stat('start_step');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
class MultiFormTestStepOne extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $next_steps = 'MultiFormTestStepTwo';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('FirstName', 'First name'),
|
||||
new TextField('Surname', 'Surname'),
|
||||
new EmailField('Email', 'Email address')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
class MultiFormTestStepThree extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $is_final_step = true;
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextField('Test', 'Anything else you\'d like to tell us?')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
class MultiFormTestStepTwo extends MultiFormStep implements TestOnly {
|
||||
|
||||
protected static $next_steps = 'MultiFormTestStepThree';
|
||||
|
||||
function getFields() {
|
||||
return new FieldSet(
|
||||
new TextareaField('Comments', 'Tell us a bit about yourself...')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user