diff --git a/tests/MultiFormSessionTest.php b/tests/MultiFormSessionTest.php index 6360037..0cc3efc 100644 --- a/tests/MultiFormSessionTest.php +++ b/tests/MultiFormSessionTest.php @@ -2,17 +2,24 @@ class MultiFormSessionTest extends SapphireTest { + /** + * Set up the instance of MultiFormSession, writing + * a record to the database for this test. We persist + * the object in our tests by assigning $this->session + */ + function setUp() { + $this->session = new MultiFormSession(); + $this->session->write(); + } + /** * Test generation of a new session. + * + * @TODO Write some more advanced tests for MultiFormSession. */ function testSessionGeneration() { - $session = new MultiFormSession(); - $session->write(); - - $this->assertTrue($session->ID != 0); - $this->assertTrue($session->ID > 0); - - $session->delete(); + $this->assertTrue($this->session->ID != 0); + $this->assertTrue($this->session->ID > 0); } /** @@ -28,6 +35,13 @@ class MultiFormSessionTest extends SapphireTest { } } + /** + * Delete the MultiFormSession record that we created. + */ + function tearDown() { + $this->session->delete(); + } + } ?> \ No newline at end of file diff --git a/tests/MultiFormTest.php b/tests/MultiFormTest.php new file mode 100644 index 0000000..0f7f005 --- /dev/null +++ b/tests/MultiFormTest.php @@ -0,0 +1,64 @@ +session + */ + function setUp() { + $this->form = new MultiFormTestClass(new Controller(), 'Form', new FieldSet(), new FieldSet()); + $this->form->init(); + } + + /** + * 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->session->ID) && ($this->form->session->ID > 0)); + $this->assertTrue($this->form->getStartStep() == 'MultiFormTestStepOne'); + } + + /** + * 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->session->delete(); + } + +} + +?> \ No newline at end of file diff --git a/tests/code/MultiFormTestClass.php b/tests/code/MultiFormTestClass.php new file mode 100644 index 0000000..b0d1e56 --- /dev/null +++ b/tests/code/MultiFormTestClass.php @@ -0,0 +1,17 @@ +stat('start_step'); + } + +} + +?> \ No newline at end of file diff --git a/tests/code/MultiFormTestStepOne.php b/tests/code/MultiFormTestStepOne.php new file mode 100644 index 0000000..3da22ae --- /dev/null +++ b/tests/code/MultiFormTestStepOne.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/tests/code/MultiFormTestStepThree.php b/tests/code/MultiFormTestStepThree.php new file mode 100644 index 0000000..7576ac9 --- /dev/null +++ b/tests/code/MultiFormTestStepThree.php @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/tests/code/MultiFormTestStepTwo.php b/tests/code/MultiFormTestStepTwo.php new file mode 100644 index 0000000..4d7f901 --- /dev/null +++ b/tests/code/MultiFormTestStepTwo.php @@ -0,0 +1,15 @@ + \ No newline at end of file