Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR Tidy up of tests

  • Loading branch information...
commit 8e04dfbaa53dd7d2d7345df51340d71cc461779a 1 parent 0712001
@halkyon halkyon authored
View
3  _config.php
@@ -1,5 +1,2 @@
<?php
-// This file is required in order for SilverStripe to detect this directory as a module.
-
-?>
View
6 code/MultiForm.php
@@ -89,7 +89,7 @@ public function __construct($controller, $name) {
$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 @@ public function getCurrentStep() {
$currentStep->write();
}
+ $currentStep->setForm($this);
+
return $currentStep;
}
@@ -579,4 +581,4 @@ public function getCompletedPercent() {
}
-?>
+?>
View
4 code/MultiFormStep.php
@@ -281,7 +281,7 @@ public function getPreviousStep() {
*/
public function getPreviousStepFromDatabase() {
if($prevStepClass = $this->getPreviousStep()) {
- return DataObject::get_one($prevStepClass, "SessionID = {$this->SessionID}");
+ return DataObject::get_one($prevStepClass, "SessionID = {$this->SessionID}");
}
}
@@ -337,4 +337,4 @@ public function isCurrentStep() {
}
-?>
+?>
View
19 tests/MultiFormSessionTest.php
@@ -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 @@ function testMemberLogging() {
}
}
- /**
- * Delete the MultiFormSession record that we created.
- */
- function tearDown() {
- $this->session->delete();
- }
-
}
-
-?>
View
142 tests/MultiFormTest.php
@@ -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.
- *
- * For testing purposes, we have some test MultiForm classes:
- *
- * - 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)
+ * - 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)
+ *
+ * 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.
*
- * 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 {
-
- /**
- * 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()
- */
+class MultiFormTest extends FunctionalTest {
+
+ protected $controller;
+
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?')
+ );
}
}
-?>
View
17 tests/code/MultiFormTestClass.php
@@ -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');
- }
-
-}
-
-?>
View
17 tests/code/MultiFormTestStepOne.php
@@ -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')
- );
- }
-
-}
-
-?>
View
15 tests/code/MultiFormTestStepThree.php
@@ -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?')
- );
- }
-
-}
-
-?>
View
15 tests/code/MultiFormTestStepTwo.php
@@ -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...')
- );
- }
-
-}
-
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.