Passed
Branch master (d4ff20)
by Antony
02:56 queued 01:42
created

KnockoutFormTest::testKnockoutForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 80
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 63
nc 1
nop 0
dl 0
loc 80
rs 8.8072
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AntonyThorpe\Knockout\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
use SilverStripe\Core\Config\Config;
7
use AntonyThorpe\Knockout\Tests\KnockoutFormTest_Controller;
8
9
/**
10
 * KnockoutFormTest
11
 *
12
 * Controller tests
13
 */
14
class KnockoutFormTest extends FunctionalTest
15
{
16
    protected static $disable_theme = true;
17
18
    protected static $extra_controllers = [
19
        KnockoutFormTest_Controller::class
20
    ];
21
22
    public function setUp()
23
    {
24
        parent::setUp();
25
        Config::modify()->set('SSViewer', 'source_file_comments', true);
26
    }
27
28
    public function testKnockoutForm()
29
    {
30
        $page = $this->get('KnockoutFormTest_Controller');
31
        $this->assertEquals(200, $page->getStatusCode(), "a page should load");
32
        $body = $page->getBody();
33
34
        $this->assertContains(
35
            'data-bind="submit: addToCart2"',
36
            $body,
37
            'form element has submit binding to javascript function'
38
        );
39
        $this->assertContains(
40
            '<input data-bind="textInput: spaceship2, hasFocus: true"',
41
            $body,
42
            'Databind attribute in input element'
43
        );
44
        $this->assertContains(
45
            "setKnockout:{value:'Enterprise\'s Voyage'}",
46
            $body,
47
            'Comma escaped in HTML for javascript'
48
        );
49
        $this->assertContains(
50
            '<select data-bind="value: menu"',
51
            $body,
52
            'Databind attribute applied to select element'
53
        );
54
        $this->assertContains(
55
            '<input data-bind="textInput: seatNumber, setKnockout:{value:4}"',
56
            $body,
57
            'KnockoutNumericField works'
58
        );
59
        $this->assertContains(
60
            '<input data-bind="enable: canSaveInterGalacticAction, css:{ \'FormAction_Disabled\': !canSaveInterGalacticAction() }" type="submit"',
61
            $body,
62
            'Databind attribute in submit button'
63
        );
64
        $this->assertContains(
65
            '<input data-bind="textInput: email, setKnockout:{value:\'[email protected]\'}"',
66
            $body,
67
            'Databind attribute applied to input element for email field'
68
        );
69
        $this->assertContains(
70
            'class="email text"',
71
            $body,
72
            'KnockoutEmailField has a class of "email text"'
73
        );
74
        $this->assertContains(
75
            '<textarea data-bind="textInput: comments"',
76
            $body,
77
            'Databind attribute applied to the textareafield'
78
        );
79
        $this->assertContains(
80
            'class="knockouttextarea textarea"',
81
            $body,
82
            'KnockoutTextareaField has a class of "textarea text"'
83
        );
84
        $this->assertContains(
85
            'data-bind="checked: accessories, setKnockout:{value:\'Zero Gravity Pillow\'}, blah: someOtherFunction"',
86
            $body,
87
            'Databind attribute applied to the radio buttons'
88
        );
89
        $this->assertContains(
90
            'class="radio"',
91
            $body,
92
            'KnockoutOptionsetField has a class of "radio"'
93
        );
94
        $this->assertContains(
95
            'data-bind="enable: canSaveInterGalacticAction',
96
            $body,
97
            'KnockoutFormAction has an obserable of "canSaveInterGalacticAction"'
98
        );
99
        $this->assertContains(
100
            'data-bind="textInput: password',
101
            $body,
102
            'KnockoutConfirmedPasswordField has a child with an obserable of "password"'
103
        );
104
        $this->assertContains(
105
            'data-bind="textInput: confirmedPassword',
106
            $body,
107
            'KnockoutConfirmedPasswordField has a child with an obserable of "confirmedPassword"'
108
        );
109
        // add additional tests here after adding to the form below
110
    }
111
}
112