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

KnockoutFormTest_Controller::Form()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 38
nc 1
nop 0
dl 0
loc 46
rs 9.312
c 0
b 0
f 0
1
<?php
2
3
namespace AntonyThorpe\Knockout\Tests;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\Control\Controller;
7
use AntonyThorpe\Knockout\KnockoutForm;
8
use SilverStripe\View\SSViewer;
9
use SilverStripe\Control\HTTPRequest;
10
use SilverStripe\Forms\Form;
11
use SilverStripe\Forms\FieldList;
12
use AntonyThorpe\Knockout\KnockoutTextField;
13
use AntonyThorpe\Knockout\KnockoutDropdownField;
14
use AntonyThorpe\Knockout\KnockoutNumericField;
15
use AntonyThorpe\Knockout\KnockoutEmailField;
16
use AntonyThorpe\Knockout\KnockoutTextareaField;
17
use AntonyThorpe\Knockout\KnockoutOptionsetField;
18
use AntonyThorpe\Knockout\KnockoutConfirmedPasswordField;
19
use AntonyThorpe\Knockout\KnockoutFormAction;
20
21
class KnockoutFormTest_Controller extends Controller implements TestOnly
22
{
23
    public function __construct()
24
    {
25
        parent::__construct();
26
        if (Controller::has_curr()) {
27
            $this->setRequest(Controller::curr()->getRequest());
28
        }
29
    }
30
31
    private static $allowed_actions = array('Form');
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
32
33
    private static $url_handlers = array(
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
34
        '$Action//$ID/$OtherID' => "handleAction",
35
    );
36
37
    protected $template = 'BlankPage';
38
39
    public function Link($action = null)
40
    {
41
        return Controller::join_links(
42
            'KnockoutFormTest_Controller',
43
            $this->getRequest()->latestParam('Action'),
44
            $this->getRequest()->latestParam('ID'),
45
            $action
46
        );
47
    }
48
49
    public function Form()
50
    {
51
        $form = KnockoutForm::create(
52
            $this,
53
            'Form',
54
            FieldList::create(
55
                KnockoutTextField::create('Spaceship', 'Spaceship')
56
                    ->setObservable('spaceship2')
57
                    ->setHasFocus(true),
58
                KnockoutTextField::create('FieldWithComma', 'FieldWithComma')
59
                    ->setObservable('fieldwithcomma')
60
                    ->setValue("Enterprise's Voyage"),
61
                KnockoutDropdownField::create(
62
                    'Menu',
63
                    'Space Menu',
64
                    array('1'=>'Light Speed Salad','2'=>'Comet Custard')
65
                )->setObservable('menu'),
66
                KnockoutNumericField::create('SeatNumber', 'Seat Number', 4)
67
                    ->setObservable('seatNumber'),
68
                KnockoutEmailField::create('Email', 'Email')
69
                    ->setObservable('email')
70
                    ->setValue('[email protected]'),
71
                KnockoutTextareaField::create('Comments', 'Comments')
72
                    ->setObservable('comments'),
73
                KnockoutOptionsetField::create(
74
                    'Accessories',
75
                    'Accessories',
76
                    array(
77
                        'Flying High DVD' => 'Flying High DVD',
78
                        'Zero Gravity Pillow' => 'Zero Gravity Pillow',
79
                        'Rocket Replica' => 'Rocket Replica'
80
                    ),
81
                    'Zero Gravity Pillow'
82
                )->setObservable('accessories')
83
                    ->setOtherBindings("blah: someOtherFunction"),
84
                KnockoutConfirmedPasswordField::create('Password', 'Password')
85
                // add any new knockout fields here and assert above
86
            ),
87
            FieldList::create(
88
                KnockoutFormAction::create('doSubmit', 'Submit')
89
                    ->setObservable('canSaveInterGalacticAction')
90
            )
91
        );
92
        $form->setSubmit('addToCart2');
93
94
        return $form;
95
    }
96
97
    public function doSubmit($data, Form $form, HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    public function doSubmit($data, Form $form, /** @scrutinizer ignore-unused */ HTTPRequest $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

97
    public function doSubmit(/** @scrutinizer ignore-unused */ $data, Form $form, HTTPRequest $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        $form->sessionMessage('Test save was successful', 'good');
100
        return $this->redirectBack();
101
    }
102
103
    public function getViewer($action = null)
104
    {
105
        return new SSViewer('BlankPage');
106
    }
107
}
108