| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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() |
||
| 37 | { |
||
| 38 | parent::setUp(); |
||
| 39 | Config::inst()->update('SSViewer', 'source_file_comments', true); |
||
|
|
|||
| 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"', |
||
| 215 |