From 72dbf5ddeba229dfa349f9e10818ea83c4039e04 Mon Sep 17 00:00:00 2001 From: crynobone Date: Tue, 6 Nov 2012 16:35:29 +0800 Subject: [PATCH] Add full code coverage for Laravel\Form Signed-off-by: crynobone --- laravel/tests/cases/blade.test.php | 1 - laravel/tests/cases/form.test.php | 447 +++++++++++++++++++++++++++++ 2 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 laravel/tests/cases/form.test.php diff --git a/laravel/tests/cases/blade.test.php b/laravel/tests/cases/blade.test.php index 861ce115..fb60cc21 100644 --- a/laravel/tests/cases/blade.test.php +++ b/laravel/tests/cases/blade.test.php @@ -117,5 +117,4 @@ public function testRendersAreCompiledCorrectly() $this->assertEquals("", Blade::compile_string($blade2)); } - } \ No newline at end of file diff --git a/laravel/tests/cases/form.test.php b/laravel/tests/cases/form.test.php new file mode 100644 index 00000000..e812ad2d --- /dev/null +++ b/laravel/tests/cases/form.test.php @@ -0,0 +1,447 @@ + 'UTF-16', 'class' => 'form')); + $form4 = Form::open('foobar', 'DELETE', array('class' => 'form')); + + $this->assertEquals('
', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of opening a secure form + * + * @group laravel + */ + public function testOpeningFormSecure() + { + $form1 = Form::open_secure('foobar', 'GET'); + $form2 = Form::open_secure('foobar', 'POST'); + $form3 = Form::open_secure('foobar', 'PUT', array('accept-charset' => 'UTF-16', 'class' => 'form')); + $form4 = Form::open_secure('foobar', 'DELETE', array('class' => 'form')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of opening a form for files + * + * @group laravel + */ + public function testOpeningFormForFile() + { + $form1 = Form::open_for_files('foobar', 'GET'); + $form2 = Form::open_for_files('foobar', 'POST'); + $form3 = Form::open_for_files('foobar', 'PUT', array('accept-charset' => 'UTF-16', 'class' => 'form')); + $form4 = Form::open_for_files('foobar', 'DELETE', array('class' => 'form')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of opening a secure form for files + * + * @group laravel + */ + public function testOpeningFormSecureForFile() + { + $form1 = Form::open_secure_for_files('foobar', 'GET'); + $form2 = Form::open_secure_for_files('foobar', 'POST'); + $form3 = Form::open_secure_for_files('foobar', 'PUT', array('accept-charset' => 'UTF-16', 'class' => 'form')); + $form4 = Form::open_secure_for_files('foobar', 'DELETE', array('class' => 'form')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of closing a form + * + * @group laravel + */ + public function testClosingForm() + { + $this->assertEquals('
', Form::close()); + } + + /** + * Test the compilation of form label + * + * @group laravel + */ + public function testFormLabel() + { + $form1 = Form::label('foo', 'Foobar'); + $form2 = Form::label('foo', 'Foobar', array('class' => 'control-label')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + } + + /** + * Test the compilation of form input + * + * @group laravel + */ + public function testFormInput() + { + $form1 = Form::input('text', 'foo'); + $form2 = Form::input('text', 'foo', 'foobar'); + $form3 = Form::input('date', 'foobar', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + + /** + * Test the compilation of form text + * + * @group laravel + */ + public function testFormText() + { + $form1 = Form::input('text', 'foo'); + $form2 = Form::text('foo'); + $form3 = Form::text('foo', 'foobar'); + $form4 = Form::text('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form password + * + * @group laravel + */ + public function testFormPassword() + { + $form1 = Form::input('password', 'foo'); + $form2 = Form::password('foo'); + $form3 = Form::password('foo', array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + } + + /** + * Test the compilation of form hidden + * + * @group laravel + */ + public function testFormHidden() + { + $form1 = Form::input('hidden', 'foo'); + $form2 = Form::hidden('foo'); + $form3 = Form::hidden('foo', 'foobar'); + $form4 = Form::hidden('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form search + * + * @group laravel + */ + public function testFormSearch() + { + $form1 = Form::input('search', 'foo'); + $form2 = Form::search('foo'); + $form3 = Form::search('foo', 'foobar'); + $form4 = Form::search('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form email + * + * @group laravel + */ + public function testFormEmail() + { + $form1 = Form::input('email', 'foo'); + $form2 = Form::email('foo'); + $form3 = Form::email('foo', 'foobar'); + $form4 = Form::email('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form telephone + * + * @group laravel + */ + public function testFormTelephone() + { + $form1 = Form::input('tel', 'foo'); + $form2 = Form::telephone('foo'); + $form3 = Form::telephone('foo', 'foobar'); + $form4 = Form::telephone('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form url + * + * @group laravel + */ + public function testFormUrl() + { + $form1 = Form::input('url', 'foo'); + $form2 = Form::url('foo'); + $form3 = Form::url('foo', 'foobar'); + $form4 = Form::url('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form number + * + * @group laravel + */ + public function testFormNumber() + { + $form1 = Form::input('number', 'foo'); + $form2 = Form::number('foo'); + $form3 = Form::number('foo', 'foobar'); + $form4 = Form::number('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form date + * + * @group laravel + */ + public function testFormDate() + { + $form1 = Form::input('date', 'foo'); + $form2 = Form::date('foo'); + $form3 = Form::date('foo', 'foobar'); + $form4 = Form::date('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form file + * + * @group laravel + */ + public function testFormFile() + { + $form1 = Form::input('file', 'foo'); + $form2 = Form::file('foo'); + $form3 = Form::file('foo', array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals($form1, $form2); + $this->assertEquals('', $form3); + } + + /** + * Test the compilation of form textarea + * + * @group laravel + */ + public function testFormTextarea() + { + $form1 = Form::textarea('foo'); + $form2 = Form::textarea('foo', 'foobar'); + $form3 = Form::textarea('foo', null, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + + /** + * Test the compilation of form select + * + * @group laravel + */ + public function testFormSelect() + { + $select1 = array( + 'foobar' => 'Foobar', + 'hello' => 'Hello World', + ); + + $select2 = array( + 'foo' => array( + 'foobar' => 'Foobar', + ), + 'hello' => 'Hello World', + ); + + $form1 = Form::select('foo'); + $form2 = Form::select('foo', $select1, 'foobar'); + $form3 = Form::select('foo', $select1, null, array('class' => 'span2')); + $form4 = Form::select('foo', $select2, 'foobar'); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form checkbox + * + * @group laravel + */ + public function testFormCheckbox() + { + $form1 = Form::input('checkbox', 'foo'); + $form2 = Form::checkbox('foo'); + $form3 = Form::checkbox('foo', 'foobar', true); + $form4 = Form::checkbox('foo', 'foobar', false, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form date + * + * @group laravel + */ + public function testFormRadio() + { + $form1 = Form::input('radio', 'foo'); + $form2 = Form::radio('foo'); + $form3 = Form::radio('foo', 'foobar', true); + $form4 = Form::radio('foo', 'foobar', false, array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + $this->assertEquals('', $form4); + } + + /** + * Test the compilation of form submit + * + * @group laravel + */ + public function testFormSubmit() + { + $form1 = Form::submit('foo'); + $form2 = Form::submit('foo', array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + } + + /** + * Test the compilation of form reset + * + * @group laravel + */ + public function testFormReset() + { + $form1 = Form::reset('foo'); + $form2 = Form::reset('foo', array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + } + + /** + * Test the compilation of form image + * + * @group laravel + */ + public function testFormImage() + { + $form1 = Form::image('foo/bar', 'foo'); + $form2 = Form::image('foo/bar', 'foo', array('class' => 'span2')); + $form3 = Form::image('http://google.com/foobar', 'foobar'); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + + } + + /** + * Test the compilation of form button + * + * @group laravel + */ + public function testFormButton() + { + $form1 = Form::button('foo'); + $form2 = Form::button('foo', array('class' => 'span2')); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + } +} \ No newline at end of file