Completed
Push — master ( 663a06...123975 )
by Robbie
02:38
created

testElementFormSubmission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 19
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace DNADesign\ElementalUserForms\Tests;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use SilverStripe\Dev\FunctionalTest;
7
use SilverStripe\Dev\TestOnly;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\Form;
10
use SilverStripe\Forms\FormAction;
11
use SilverStripe\Forms\TextField;
12
use DNADesign\Elemental\Controllers\ElementController;
13
use DNADesign\Elemental\Models\ElementalArea;
14
use DNADesign\Elemental\Tests\ElementControllerTest\TestElement;
0 ignored issues
show
Bug introduced by
The type DNADesign\Elemental\Test...trollerTest\TestElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use DNADesign\Elemental\Tests\ElementControllerTest\TestPage;
0 ignored issues
show
Bug introduced by
The type DNADesign\Elemental\Test...ControllerTest\TestPage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use SilverStripe\Versioned\Versioned;
17
18
class ElementFormControllerTest extends FunctionalTest
19
{
20
    protected static $fixture_file = 'ElementFormTest.yml';
21
22
    protected static $use_draft_site = true;
23
24
    protected static $extra_dataobjects = array(
25
        TestPage::class,
26
        TestElement::class
27
    );
28
29
    protected function setUp()
30
    {
31
        Versioned::set_stage(Versioned::DRAFT);
32
        parent::setUp();
33
    }
34
35
    public function testElementFormRendering()
36
    {
37
        $this->logInWithPermission('ADMIN');
38
        $page = $this->objFromFixture(TestPage::class, 'page1');
39
40
        $element = $this->objFromFixture(TestElement::class, 'element1');
41
42
        $response = $this->get($page->URLSegment);
43
        $formAction = sprintf('%s/element/%d/Form', $page->URLSegment, $element->ID);
44
45
        $this->assertContains(
46
            $formAction,
47
            $response->getBody(),
48
            'Element forms are rendered through ElementalArea templates'
49
        );
50
    }
51
52
    public function testElementFormSubmission()
53
    {
54
        $this->logInWithPermission('ADMIN');
55
        $page = $this->objFromFixture(TestPage::class, 'page1');
56
57
        $element = $this->objFromFixture(TestElement::class, 'element1');
58
59
        $response = $this->get($page->URLSegment);
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
60
        $response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated'));
61
62
        $this->assertContains(
63
            'TestValue: Updated',
64
            $response->getBody(),
65
            'Form values are submitted to correct element form'
66
        );
67
        $this->assertContains(
68
            sprintf('Element ID: %d', $element->ID),
69
            $response->getBody(),
70
            'Element form acts on correct element, as identified in the URL'
71
        );
72
    }
73
}
74