1 | <?php |
||
7 | use SilverStripe\Control\Controller; |
||
8 | use SilverStripe\Control\HTTPRequest; |
||
9 | use SilverStripe\Dev\TestOnly; |
||
10 | use SilverStripe\Forms\FieldList; |
||
11 | use SilverStripe\View\SSViewer; |
||
12 | use SilverStripe\Forms\Form; |
||
13 | use AntonyThorpe\Knockout\KnockoutForm; |
||
14 | use AntonyThorpe\Knockout\KnockoutTextField; |
||
15 | use AntonyThorpe\Knockout\KnockoutDropdownField; |
||
16 | use AntonyThorpe\Knockout\KnockoutNumericField; |
||
17 | use AntonyThorpe\Knockout\KnockoutEmailField; |
||
18 | use AntonyThorpe\Knockout\KnockoutTextareaField; |
||
19 | use AntonyThorpe\Knockout\KnockoutOptionsetField; |
||
20 | use AntonyThorpe\Knockout\KnockoutConfirmedPasswordField; |
||
21 | use AntonyThorpe\Knockout\KnockoutFormAction; |
||
22 | |||
23 | /** |
||
24 | * KnockoutFormTest |
||
25 | * |
||
26 | * Controller tests |
||
27 | */ |
||
28 | class KnockoutFormTest extends FunctionalTest |
||
29 | { |
||
30 | protected static $disable_theme = true; |
||
31 | |||
32 | protected static $extra_controllers = [ |
||
33 | KnockoutFormTest_Controller::class |
||
34 | ]; |
||
35 | |||
36 | public function setUp() |
||
40 | } |
||
41 | |||
42 | public function testKnockoutForm() |
||
43 | { |
||
44 | $page = $this->get('KnockoutFormTest_Controller'); |
||
45 | $this->assertEquals(200, $page->getStatusCode(), "a page should load"); |
||
46 | $body = $page->getBody(); |
||
47 | |||
48 | $this->assertContains( |
||
49 | 'data-bind="submit: addToCart2"', |
||
50 | $body, |
||
51 | 'form element has submit binding to javascript function' |
||
52 | ); |
||
53 | $this->assertContains( |
||
54 | '<input data-bind="textInput: spaceship2, hasFocus: true"', |
||
55 | $body, |
||
56 | 'Databind attribute in input element' |
||
57 | ); |
||
58 | $this->assertContains( |
||
59 | "setKnockout:{value:'Enterprise\'s Voyage'}", |
||
60 | $body, |
||
61 | 'Comma escaped in HTML for javascript' |
||
62 | ); |
||
63 | $this->assertContains( |
||
64 | '<select data-bind="value: menu"', |
||
65 | $body, |
||
66 | 'Databind attribute applied to select element' |
||
67 | ); |
||
68 | $this->assertContains( |
||
69 | '<input data-bind="textInput: seatNumber, setKnockout:{value:4}"', |
||
70 | $body, |
||
71 | 'KnockoutNumericField works' |
||
72 | ); |
||
73 | $this->assertContains( |
||
74 | '<input data-bind="enable: canSaveInterGalacticAction, css:{ \'FormAction_Disabled\': !canSaveInterGalacticAction() }" type="submit"', |
||
75 | $body, |
||
76 | 'Databind attribute in submit button' |
||
77 | ); |
||
78 | $this->assertContains( |
||
79 | '<input data-bind="textInput: email, setKnockout:{value:\'[email protected]\'}"', |
||
80 | $body, |
||
81 | 'Databind attribute applied to input element for email field' |
||
82 | ); |
||
83 | $this->assertContains( |
||
84 | 'class="email text"', |
||
85 | $body, |
||
86 | 'KnockoutEmailField has a class of "email text"' |
||
87 | ); |
||
88 | $this->assertContains( |
||
89 | '<textarea data-bind="textInput: comments"', |
||
90 | $body, |
||
91 | 'Databind attribute applied to the textareafield' |
||
92 | ); |
||
93 | $this->assertContains( |
||
94 | 'class="knockouttextarea textarea"', |
||
95 | $body, |
||
96 | 'KnockoutTextareaField has a class of "textarea text"' |
||
97 | ); |
||
98 | $this->assertContains( |
||
99 | 'data-bind="checked: accessories, setKnockout:{value:\'Zero Gravity Pillow\'}, blah: someOtherFunction"', |
||
100 | $body, |
||
215 |