Completed
Push — master ( f3b14d...1fe4c3 )
by Damian
10s
created

WidgetControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testWidgetFormRendering() 0 16 1
A testWidgetFormSubmission() 0 21 1
1
<?php
2
3
namespace SilverStripe\Widgets\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
use SilverStripe\Widgets\Model\Widget;
7
use SilverStripe\Dev\TestOnly;
8
use SilverStripe\Forms\TextField;
9
use SilverStripe\Forms\FieldList;
10
use SilverStripe\Forms\FormAction;
11
use SilverStripe\Forms\Form;
12
use SilverStripe\Widgets\Controllers\WidgetController;
13
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage;
14
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget;
15
16
/**
17
 * @package widgets
18
 * @subpackage tests
19
 */
20
class WidgetControllerTest extends FunctionalTest
21
{
22
    protected static $fixture_file = 'WidgetControllerTest.yml';
23
24
    protected $extraDataObjects = array(
25
        TestPage::class,
26
        TestWidget::class,
27
    );
28
29
    public function testWidgetFormRendering()
30
    {
31
        $page = $this->objFromFixture(TestPage::class, 'page1');
32
        $page->copyVersionToStage('Stage', 'Live');
33
34
        $widget = $this->objFromFixture(TestWidget::class, 'widget1');
35
36
        $response = $this->get($page->URLSegment);
37
38
        $formAction = sprintf('%s/widget/%d/Form', $page->URLSegment, $widget->ID);
39
        $this->assertContains(
40
            $formAction,
41
            $response->getBody(),
42
            "Widget forms are rendered through WidgetArea templates"
43
        );
44
    }
45
46
    public function testWidgetFormSubmission()
47
    {
48
        $page = $this->objFromFixture(TestPage::class, 'page1');
49
        $page->copyVersionToStage('Stage', 'Live');
50
51
        $widget = $this->objFromFixture(TestWidget::class, 'widget1');
52
53
        $response = $this->get($page->URLSegment);
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
        $response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated'));
55
56
        $this->assertContains(
57
            'TestValue: Updated',
58
            $response->getBody(),
59
            "Form values are submitted to correct widget form"
60
        );
61
        $this->assertContains(
62
            sprintf('Widget ID: %d', $widget->ID),
63
            $response->getBody(),
64
            "Widget form acts on correct widget, as identified in the URL"
65
        );
66
    }
67
}
68