From f0b5bfa45987a950095c84ac73b363506f411aca Mon Sep 17 00:00:00 2001 From: Joshua Sherman Date: Fri, 3 Jan 2014 23:45:52 -0500 Subject: [PATCH] Form class tests and updates Still rockin' that XHTML4 nonsense. Updates to HTML5 (sans self closing tags) and added tests. --- classes/Form.php | 18 +--- tests/TODO | 1 - tests/classes/FormTest.php | 176 +++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+), 15 deletions(-) create mode 100644 tests/classes/FormTest.php diff --git a/classes/Form.php b/classes/Form.php index 5c63dbd..ecd747f 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -79,7 +79,7 @@ class Form extends Object $additional .= ' class="' . $classes . '"'; } - return ''; + return ''; } // }}} @@ -250,11 +250,6 @@ class Form extends Object return $this->input($name, $value, $classes, $additional, 'checkbox', $checked); } - // }}} - // {{{ Checkboxes - - // @todo - // }}} // {{{ Radio Button @@ -276,12 +271,7 @@ class Form extends Object } // }}} - // {{{ Radio Buttons - - // @todo - - // }}} - // {{{ Text Area + // {{{ Textarea /** * Textarea @@ -567,7 +557,7 @@ class Form extends Object { $options = $part . '_options'; $selected = 'selected_' . $part; - $html .= ' ' . $this->select($name . '[' . $part . ']', $$options, $$selected, $classes, $additional); + $html .= ($html == '' ? '' : ' ') . $this->select($name . '[' . $part . ']', $$options, $$selected, $classes, $additional); } return $html; @@ -670,7 +660,7 @@ class Form extends Object foreach ($parts as $part => $size) { $html .= ($html != '' ? ' ' : ''); - $html .= ''; + $html .= ''; } return $html; diff --git a/tests/TODO b/tests/TODO index 3a462b3..24c89ed 100644 --- a/tests/TODO +++ b/tests/TODO @@ -1,7 +1,6 @@ Cache Config Database -Form HTML Model Module diff --git a/tests/classes/FormTest.php b/tests/classes/FormTest.php new file mode 100644 index 0000000..46edb00 --- /dev/null +++ b/tests/classes/FormTest.php @@ -0,0 +1,176 @@ +form = Form::getInstance(); + $this->options = [ + '1' => 'one', + '2' => 'two', + '3' => 'three', + ]; + } + + public function testGetInstance() + { + $this->assertInstanceOf('Form', $this->form); + } + + public function testInput() + { + $this->assertEquals( + '', + $this->form->input('name') + ); + } + + public function testHidden() + { + $this->assertEquals( + '', + $this->form->hidden('name') + ); + } + + public function testHiddenInput() + { + $this->assertEquals( + '', + $this->form->hiddenInput('name') + ); + } + + public function testPassword() + { + $this->assertEquals( + '', + $this->form->password('name') + ); + } + + public function testPasswordInput() + { + $this->assertEquals( + '', + $this->form->passwordInput('name') + ); + } + + public function testSubmit() + { + $this->assertEquals( + '', + $this->form->submit('name') + ); + } + + public function testSubmitInput() + { + $this->assertEquals( + '', + $this->form->submitInput('name') + ); + } + + public function testSecurity() + { + $this->assertEquals( + '', + $this->form->security('secret') + ); + } + + public function testSecurityInput() + { + $this->assertEquals( + '', + $this->form->securityInput('secret') + ); + } + + public function testCheckbox() + { + $this->assertEquals( + '', + $this->form->checkbox('name') + ); + } + + public function testRadio() + { + $this->assertEquals( + '', + $this->form->radio('name') + ); + } + + public function testTextarea() + { + $this->assertEquals( + '', + $this->form->textarea('name') + ); + } + + public function testSelect() + { + $this->assertEquals( + '', + $this->form->select('name', $this->options) + ); + } + + public function testOptions() + { + $this->assertEquals( + '', + $this->form->options($this->options) + ); + } + + public function testStateSelect() + { + $this->assertRegExp( + '/^ ', + $this->form->dateSelect() + ); + } + + public function testDOBSelect() + { + $this->assertEquals( + ' ', + $this->form->dobSelect() + ); + } + + public function testPolarSelect() + { + $this->assertEquals( + '', + $this->form->polarSelect() + ); + } + + public function testPhoneInput() + { + $this->assertEquals( + ' ', + $this->form->phoneInput() + ); + } +} + +?>