From faaefc1b820567bf41c3b105ac1cb62f50528ef6 Mon Sep 17 00:00:00 2001 From: Joshua Sherman Date: Sun, 12 Jan 2014 13:56:52 -0500 Subject: [PATCH] Getting coverage to 100% on these classes Also found a bug in the Form class that would bork phone numbers with dashes in them. Even though the Form class is going to go away eventually I wanted to fix the issue. --- classes/Form.php | 3 +- tests/classes/ConvertTest.php | 2 + tests/classes/FileTest.php | 25 +++++-- tests/classes/FormTest.php | 130 ++++++++++++++++++++++++++++++++-- tests/classes/StringTest.php | 5 ++ tests/classes/TimeTest.php | 10 +++ 6 files changed, 164 insertions(+), 11 deletions(-) diff --git a/classes/Form.php b/classes/Form.php index 014a045..ca5d3d9 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -327,7 +327,7 @@ class Form extends Object $additional .= ' class="' . $classes . '"'; } - return ''; + return ''; } // }}} @@ -629,6 +629,7 @@ class Form extends Object } else { + $value = str_replace('-', '', $value); $value = array( 'area_code' => substr($value, 0, 3), 'prefix' => substr($value, 3, 3), diff --git a/tests/classes/ConvertTest.php b/tests/classes/ConvertTest.php index 132f88a..28450a6 100644 --- a/tests/classes/ConvertTest.php +++ b/tests/classes/ConvertTest.php @@ -17,7 +17,9 @@ class ConvertTest extends PHPUnit_Framework_TestCase [['foo', 'bar'], false, '<0>foo<1>bar'], [['foo', 'bar'], true, "<0>foo\n<1>bar\n"], [['foo' => 'bar'], false, 'bar'], + [['foo' => 'b & r'], false, ''], [['children' => ['child' => ['foo', 'bar']]], false, 'foobar'], + [['children' => ['child' => ['foo & bar']]], false, ''], [['children' => ['child' => ['foo', 'bar']]], true, "\n\tfoo\n\tbar\n\n"], ]; } diff --git a/tests/classes/FileTest.php b/tests/classes/FileTest.php index 06cdb8a..86e61c8 100644 --- a/tests/classes/FileTest.php +++ b/tests/classes/FileTest.php @@ -2,14 +2,29 @@ class FileTest extends PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() + { + // Using actual filesystem because you can't chdir with vfs:// + $directory = '/tmp/pickles-fs/filetest/test/test'; + + if (!file_exists($directory)) + { + mkdir($directory, 0777, true); + } + } + + public static function tearDownAfterClass() + { + File::removeDirectory('/tmp/pickles-fs'); + } + public function testRemoveDirectory() { - $directory = SITE_PATH . 'test/test/test/'; + $directory = '/tmp/pickles-fs/filetest/'; - mkdir($directory, 0777, true); - touch(SITE_PATH . 'test/ing'); - touch(SITE_PATH . 'test/test/ing'); - touch(SITE_PATH . 'test/test/test/ing'); + touch($directory . 'ing'); + touch($directory . 'test/ing'); + touch($directory . 'test/test/ing'); File::removeDirectory($directory); diff --git a/tests/classes/FormTest.php b/tests/classes/FormTest.php index 46edb00..112ae25 100644 --- a/tests/classes/FormTest.php +++ b/tests/classes/FormTest.php @@ -28,6 +28,22 @@ class FormTest extends PHPUnit_Framework_TestCase ); } + public function testInputWithClasses() + { + $this->assertEquals( + '', + $this->form->input('name', null, 'foo bar') + ); + } + + public function testInputWithAdditional() + { + $this->assertEquals( + '', + $this->form->input('name', null, null, 'test="ing"') + ); + } + public function testHidden() { $this->assertEquals( @@ -100,6 +116,14 @@ class FormTest extends PHPUnit_Framework_TestCase ); } + public function testCheckboxChecked() + { + $this->assertEquals( + '', + $this->form->checkbox('name', null, true) + ); + } + public function testRadio() { $this->assertEquals( @@ -116,14 +140,46 @@ class FormTest extends PHPUnit_Framework_TestCase ); } + public function testTextareaWithClasses() + { + $this->assertEquals( + '', + $this->form->textarea('name', null, 'foo bar') + ); + } + + public function testTextareaWithAdditional() + { + $this->assertEquals( + '', + $this->form->textarea('name', null, null, 'test="ing"') + ); + } + public function testSelect() { $this->assertEquals( - '', + '', $this->form->select('name', $this->options) ); } + public function testSelectWithClasses() + { + $this->assertEquals( + '', + $this->form->select('name', $this->options, null, 'foo bar') + ); + } + + public function testSelectWithAdditional() + { + $this->assertEquals( + '', + $this->form->select('name', $this->options, null, null, 'test="ing"') + ); + } + public function testOptions() { $this->assertEquals( @@ -132,10 +188,34 @@ class FormTest extends PHPUnit_Framework_TestCase ); } + public function testOptionsWithMissingSelected() + { + $this->assertEquals( + '', + $this->form->options($this->options, 4) + ); + } + + public function testOptionsOptGroup() + { + $this->assertEquals( + '', + $this->form->options(['group' => $this->options]) + ); + } + + public function testOptionsOptGroupSelected() + { + $this->assertEquals( + '', + $this->form->options(['group' => $this->options], 2) + ); + } + public function testStateSelect() { $this->assertRegExp( - '/^