Passed
Push — master ( f12c86...a5399b )
by Antony
07:43
created

KnockoutFormTestController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 58
c 0
b 0
f 0
dl 0
loc 89
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A doSubmit() 0 4 1
A Form() 0 50 1
A getViewer() 0 3 1
A Link() 0 7 1
A __construct() 0 5 2
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\KnockoutCheckboxField;
20
use AntonyThorpe\Knockout\KnockoutSwitchField;
21
use AntonyThorpe\Knockout\KnockoutFormAction;
22
23
class KnockoutFormTestController extends Controller implements TestOnly
24
{
25
    public function __construct()
26
    {
27
        parent::__construct();
28
        if (Controller::has_curr()) {
29
            $this->setRequest(Controller::curr()->getRequest());
30
        }
31
    }
32
33
    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...
34
35
    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...
36
        '$Action//$ID/$OtherID' => "handleAction",
37
    );
38
39
    protected $template = 'BlankPage';
40
41
    public function Link($action = null)
42
    {
43
        return Controller::join_links(
44
            'KnockoutFormTestController',
45
            $this->getRequest()->latestParam('Action'),
46
            $this->getRequest()->latestParam('ID'),
47
            $action
48
        );
49
    }
50
51
    public function Form()
52
    {
53
        $form = KnockoutForm::create(
54
            $this,
55
            'Form',
56
            FieldList::create(
57
                KnockoutTextField::create('Spaceship', 'Spaceship')
58
                    ->setObservable('spaceship2')
59
                    ->setHasFocus(true),
60
                KnockoutTextField::create('FieldWithComma', 'FieldWithComma')
61
                    ->setObservable('fieldwithcomma')
62
                    ->setValue("Enterprise's Voyage"),
63
                KnockoutDropdownField::create(
64
                    'Menu',
65
                    'Space Menu',
66
                    array('1'=>'Light Speed Salad','2'=>'Comet Custard')
67
                )->setObservable('menu'),
68
                KnockoutNumericField::create('SeatNumber', 'Seat Number', 4)
69
                    ->setObservable('seatNumber'),
70
                KnockoutEmailField::create('Email', 'Email')
71
                    ->setObservable('email')
72
                    ->setValue('[email protected]'),
73
                KnockoutTextareaField::create('Comments', 'Comments')
74
                    ->setObservable('comments'),
75
                KnockoutOptionsetField::create(
76
                    'Accessories',
77
                    'Accessories',
78
                    array(
79
                        'Flying High DVD' => 'Flying High DVD',
80
                        'Zero Gravity Pillow' => 'Zero Gravity Pillow',
81
                        'Rocket Replica' => 'Rocket Replica'
82
                    ),
83
                    'Zero Gravity Pillow'
84
                )->setObservable('accessories')
85
                    ->setOtherBindings("blah: someOtherFunction"),
86
                KnockoutConfirmedPasswordField::create('Password', 'Password'),
87
                KnockoutCheckboxField::create('CheckboxFieldExample', 'Checkbox Field Example')
88
                    ->setObservable('checkboxField'),
89
                KnockoutSwitchField::create('SwitchFieldExample', 'Switch Field Example')
90
                        ->setObservable('switchField')
91
                // add any new knockout fields here and assert above
92
            ),
93
            FieldList::create(
94
                KnockoutFormAction::create('doSubmit', 'Submit')
95
                    ->setObservable('canSaveInterGalacticAction')
96
            )
97
        );
98
        $form->setSubmit('addToCart2');
99
100
        return $form;
101
    }
102
103
    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

103
    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

103
    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...
104
    {
105
        $form->sessionMessage('Test save was successful', 'good');
106
        return $this->redirectBack();
107
    }
108
109
    public function getViewer($action = null)
110
    {
111
        return new SSViewer('BlankPage');
112
    }
113
}
114