Skip to content

Commit

Permalink
NEW Add individual test stubs for this module, switch back to prefer-…
Browse files Browse the repository at this point in the history
…dist in Travis
  • Loading branch information
robbieaverill committed Oct 30, 2017
1 parent 02e7fff commit 614a3dd
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions tests/php/ElementFormControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 8 additions & 1 deletion tests/php/ElementFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
5 changes: 3 additions & 2 deletions tests/php/ElementFormTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/php/Stub/TestElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace DNADesign\ElementalUserForms\Tests\Stub;

use SilverStripe\Dev\TestOnly;
use DNADesign\Elemental\Models\BaseElement;

class TestElement extends BaseElement implements TestOnly
{
private static $db = [
'TestValue' => 'Text'
];

private static $controller_class = TestElementController::class;
}
44 changes: 44 additions & 0 deletions tests/php/Stub/TestElementController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace DNADesign\ElementalUserForms\Tests\Stub;

use DNADesign\Elemental\Controllers\ElementController;
use SilverStripe\Dev\TestOnly;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\TextField;

class TestElementController extends ElementController implements TestOnly
{
private static $url_segment = 'test-uf-page';

private static $allowed_actions = [
'Form',
];

public function Form()
{
$elementform = new Form(
$this,
'Form',
new FieldList(
new TextField('TestValue')
),
new FieldList(
new FormAction('doAction')
)
);

return $elementform;
}

public function doAction($data, $form)
{
return sprintf(
'TestValue: %s\nElement ID: %d',
$data['TestValue'],
$this->element->ID
);
}
}
14 changes: 14 additions & 0 deletions tests/php/Stub/TestPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace DNADesign\ElementalUserForms\Tests\Stub;

use Page;
use DNADesign\Elemental\Extensions\ElementalPageExtension;
use SilverStripe\Dev\TestOnly;

class TestPage extends Page implements TestOnly
{
private static $extensions = [
ElementalPageExtension::class
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$Form
$TestValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="test-page-template">
$ElementalArea
</div>

0 comments on commit 614a3dd

Please sign in to comment.