From 614a3dd5a3bf6e0c025a8d3fdb2c59b1434b5a1c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 30 Oct 2017 19:19:00 +1300 Subject: [PATCH] NEW Add individual test stubs for this module, switch back to prefer-dist in Travis --- .travis.yml | 2 +- tests/php/ElementFormControllerTest.php | 18 +++----- tests/php/ElementFormTest.php | 9 +++- tests/php/ElementFormTest.yml | 5 ++- tests/php/Stub/TestElement.php | 15 +++++++ tests/php/Stub/TestElementController.php | 44 +++++++++++++++++++ tests/php/Stub/TestPage.php | 14 ++++++ .../Tests/Stub/TestElement.ss | 2 + .../ElementalUserForms/Tests/Stub/TestPage.ss | 3 ++ 9 files changed, 96 insertions(+), 16 deletions(-) create mode 100644 tests/php/Stub/TestElement.php create mode 100644 tests/php/Stub/TestElementController.php create mode 100644 tests/php/Stub/TestPage.php create mode 100644 tests/php/Stub/templates/DNADesign/ElementalUserForms/Tests/Stub/TestElement.ss create mode 100644 tests/php/Stub/templates/DNADesign/ElementalUserForms/Tests/Stub/TestPage.ss diff --git a/.travis.yml b/.travis.yml index e3b02be..05a9723 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ before_script: - composer validate - composer require silverstripe/recipe-cms 1.0.x-dev --no-update - if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi - - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile + - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi diff --git a/tests/php/ElementFormControllerTest.php b/tests/php/ElementFormControllerTest.php index 7a673af..c762fca 100644 --- a/tests/php/ElementFormControllerTest.php +++ b/tests/php/ElementFormControllerTest.php @@ -3,10 +3,10 @@ namespace DNADesign\ElementalUserForms\Tests; use DNADesign\Elemental\Models\BaseElement; -use DNADesign\Elemental\Tests\Src\TestElement; -use DNADesign\Elemental\Tests\Src\TestPage; use DNADesign\ElementalUserForms\Control\ElementFormController; use DNADesign\ElementalUserForms\Model\ElementForm; +use DNADesign\ElementalUserForms\Tests\Stub\TestElement; +use DNADesign\ElementalUserForms\Tests\Stub\TestPage; use SilverStripe\Dev\FunctionalTest; use SilverStripe\UserForms\Control\UserDefinedFormController; use SilverStripe\Versioned\Versioned; @@ -17,16 +17,10 @@ class ElementFormControllerTest extends FunctionalTest protected static $use_draft_site = true; - protected static $extra_dataobjects = array( + protected static $extra_dataobjects = [ TestPage::class, - TestElement::class - ); - - protected function setUp() - { - Versioned::set_stage(Versioned::DRAFT); - parent::setUp(); - } + TestElement::class, + ]; public function testElementFormRendering() { @@ -54,7 +48,7 @@ public function testElementFormSubmission() $response = $this->get($page->URLSegment); - $response = $this->submitForm('UserForm_Form_2', 'action_process', array('TestValue' => 'Updated')); + $response = $this->submitForm('UserForm_Form_2', 'action_process', ['TestValue' => 'Updated']); $this->assertContains( 'received your submission', $response->getBody(), diff --git a/tests/php/ElementFormTest.php b/tests/php/ElementFormTest.php index 0054430..16559f8 100644 --- a/tests/php/ElementFormTest.php +++ b/tests/php/ElementFormTest.php @@ -2,12 +2,19 @@ namespace DNADesign\ElementalUserForms\Tests; +use DNADesign\ElementalUserForms\Model\ElementForm; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Forms\GridField\GridField; class ElementFormTests extends SapphireTest { public function testFormDisplaysInCMS() { - // @todo + $element = new ElementForm; + + $fields = $element->getCMSFields(); + + $this->assertNotNull($fields->fieldByName('Root.FormFields')); + $this->assertInstanceOf(GridField::class, $fields->fieldByName('Root.FormFields.Fields')); } } diff --git a/tests/php/ElementFormTest.yml b/tests/php/ElementFormTest.yml index e962683..33e779f 100644 --- a/tests/php/ElementFormTest.yml +++ b/tests/php/ElementFormTest.yml @@ -2,16 +2,17 @@ DNADesign\Elemental\Models\ElementalArea: area1: Title: Bogus -DNADesign\Elemental\Tests\Src\TestPage: +DNADesign\ElementalUserForms\Tests\Stub\TestPage: page1: Title: Page 1 URLSegment: test-page ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.area1 -DNADesign\Elemental\Tests\Src\TestElement: +DNADesign\ElementalUserForms\Tests\Stub\TestElement: element1: Title: Element 1 ParentID: =>DNADesign\Elemental\Models\ElementalArea.area1 + DNADesign\ElementalUserForms\Model\ElementForm: formelement: Title: Element Form diff --git a/tests/php/Stub/TestElement.php b/tests/php/Stub/TestElement.php new file mode 100644 index 0000000..71a5707 --- /dev/null +++ b/tests/php/Stub/TestElement.php @@ -0,0 +1,15 @@ + 'Text' + ]; + + private static $controller_class = TestElementController::class; +} diff --git a/tests/php/Stub/TestElementController.php b/tests/php/Stub/TestElementController.php new file mode 100644 index 0000000..0e4b8b0 --- /dev/null +++ b/tests/php/Stub/TestElementController.php @@ -0,0 +1,44 @@ +element->ID + ); + } +} diff --git a/tests/php/Stub/TestPage.php b/tests/php/Stub/TestPage.php new file mode 100644 index 0000000..e5b60d5 --- /dev/null +++ b/tests/php/Stub/TestPage.php @@ -0,0 +1,14 @@ + +$ElementalArea +