From 77975a982c776f8c989284a11122b18364001d4c Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 May 2015 23:35:02 -0400 Subject: [PATCH 1/4] Failing test for removeClass() on element. --- tests/FormBuilderTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 424e378..5cc6b3b 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -526,6 +526,13 @@ public function testAgainstXSSAttacksInBoundModels() $this->assertEquals($expected, $result); } + public function testRemoveClass() + { + $expected = ''; + $result = (string)$this->form->text('food')->addClass('sandwich pizza')->removeClass('sandwich')->removeClass('pizza'); + $this->assertEquals($expected, $result); + } + private function getStubObject() { $obj = new stdClass; From 38a7a9c4557e254b114ab72513dde59019d4c4a5 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 29 May 2015 23:41:31 -0400 Subject: [PATCH 2/4] Improvement to make removeClass() pass. --- src/AdamWathan/Form/Elements/Element.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/AdamWathan/Form/Elements/Element.php b/src/AdamWathan/Form/Elements/Element.php index fd7875d..16e6a72 100644 --- a/src/AdamWathan/Form/Elements/Element.php +++ b/src/AdamWathan/Form/Elements/Element.php @@ -55,7 +55,13 @@ public function removeClass($class) if (! isset($this->attributes['class'])) { return $this; } + $class = trim(str_replace($class, '', $this->attributes['class'])); + if ($class == '') { + $this->removeAttribute('class'); + return $this; + } + $this->setAttribute('class', $class); return $this; } From a2ffd747e307d5caae80eaba0f20bd87796f5466 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Sat, 30 May 2015 00:12:13 -0400 Subject: [PATCH 3/4] Failing test for public type() getter on element. --- tests/FormBuilderTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/FormBuilderTest.php b/tests/FormBuilderTest.php index 5cc6b3b..fceb5ad 100644 --- a/tests/FormBuilderTest.php +++ b/tests/FormBuilderTest.php @@ -533,6 +533,13 @@ public function testRemoveClass() $this->assertEquals($expected, $result); } + public function testGetTypeAttribute() + { + $expected = 'radio'; + $result = $this->form->radio('fm-transmission')->type(); + $this->assertEquals($expected, $result); + } + private function getStubObject() { $obj = new stdClass; From a72b70021284a2c03fc1a4d6cdd5ebacb62a8beb Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Sat, 30 May 2015 00:12:56 -0400 Subject: [PATCH 4/4] Adding type() getter on element. --- src/AdamWathan/Form/Elements/Element.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AdamWathan/Form/Elements/Element.php b/src/AdamWathan/Form/Elements/Element.php index 16e6a72..9fee38b 100644 --- a/src/AdamWathan/Form/Elements/Element.php +++ b/src/AdamWathan/Form/Elements/Element.php @@ -18,6 +18,11 @@ protected function removeAttribute($attribute) unset($this->attributes[$attribute]); } + public function type() + { + return $this->attributes['type']; + } + public function data($attribute, $value) { $this->setAttribute('data-'.$attribute, $value);