From 42c0854e00d6bb3346883d122b444fbf15a13ecb Mon Sep 17 00:00:00 2001 From: Drew <5396418+djh101@users.noreply.github.com> Date: Thu, 10 May 2018 10:15:15 -0700 Subject: [PATCH] Add range, month, week. (#520) * Added range, month, week. * Added URL test. * Removed duplicate function testFormFile. --- src/FormBuilder.php | 54 +++++++++++++++++++++++++++++++++++++++ tests/FormBuilderTest.php | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 2d7a214..ef91817 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -329,6 +329,20 @@ class FormBuilder return $this->input('password', $name, '', $options); } + /** + * Create a range input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function range($name, $value = null, $options = []) + { + return $this->input('range', $name, $value, $options); + } + /** * Create a hidden input field. * @@ -464,6 +478,10 @@ class FormBuilder */ public function time($name, $value = null, $options = []) { + if ($value instanceof DateTime) { + $value = $value->format('H:i'); + } + return $this->input('time', $name, $value, $options); } @@ -481,6 +499,24 @@ class FormBuilder return $this->input('url', $name, $value, $options); } + /** + * Create a week input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function week($name, $value = null, $options = []) + { + if ($value instanceof DateTime) { + $value = $value->format('Y-\WW'); + } + + return $this->input('week', $name, $value, $options); + } + /** * Create a file input field. * @@ -982,6 +1018,24 @@ class FormBuilder return $this->input('image', $name, null, $attributes); } + /** + * Create a month input field. + * + * @param string $name + * @param string $value + * @param array $options + * + * @return \Illuminate\Support\HtmlString + */ + public function month($name, $value = null, $options = []) + { + if ($value instanceof DateTime) { + $value = $value->format('Y-m'); + } + + return $this->input('month', $name, $value, $options); + } + /** * Create a color input field. * diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 5e15afd..e53f007 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -229,6 +229,17 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase $this->assertEquals('', $form2); } + public function testFormRange() + { + $form1 = $this->formBuilder->range('foo'); + $form2 = $this->formBuilder->range('foo', 1); + $form3 = $this->formBuilder->range('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + public function testFormHidden() { $form1 = $this->formBuilder->hidden('foo'); @@ -240,6 +251,18 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase $this->assertEquals('', $form3); } + public function testFormMonth() + { + $form1 = $this->formBuilder->month('foo'); + $form2 = $this->formBuilder->month('foo', \Carbon\Carbon::now()); + $form3 = $this->formBuilder->month('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', + $form2); + $this->assertEquals('', $form3); + } + public function testFormSearch() { $form1 = $this->formBuilder->search('foo'); @@ -310,6 +333,29 @@ class FormBuilderTest extends PHPUnit\Framework\TestCase $this->assertEquals('', $form3); } + public function testFormUrl() + { + $form1 = $this->formBuilder->url('foo'); + $form2 = $this->formBuilder->url('foo', 'http://foobar.com'); + $form3 = $this->formBuilder->url('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', $form2); + $this->assertEquals('', $form3); + } + + public function testFormWeek() + { + $form1 = $this->formBuilder->week('foo'); + $form2 = $this->formBuilder->week('foo', \Carbon\Carbon::now()); + $form3 = $this->formBuilder->week('foo', null, ['class' => 'span2']); + + $this->assertEquals('', $form1); + $this->assertEquals('', + $form2); + $this->assertEquals('', $form3); + } + public function testFormFile() { $form1 = $this->formBuilder->file('foo');