From 2d04de0377aff41fa12188d7c5edf7dd6a47f1c6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 31 Oct 2012 15:44:57 +0100 Subject: [PATCH] BUG FormField->removeExtraClass() works on indexed arrays Was assuming an associative map, which isn't the case in the current implementations. --- forms/FormField.php | 6 +++--- tests/forms/FormFieldTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/forms/FormField.php b/forms/FormField.php index 143afcb97..7b86b1fd5 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -321,9 +321,9 @@ class FormField extends RequestHandler { * @param $class String */ public function removeExtraClass($class) { - if(isset($this->extraClasses) && array_key_exists($class, $this->extraClasses)) { - unset($this->extraClasses[$class]); - } + $pos = array_search($class, $this->extraClasses); + if($pos !== false) unset($this->extraClasses[$pos]); + return $this; } diff --git a/tests/forms/FormFieldTest.php b/tests/forms/FormFieldTest.php index c19f9afdc..6c53eee5b 100644 --- a/tests/forms/FormFieldTest.php +++ b/tests/forms/FormFieldTest.php @@ -5,6 +5,22 @@ */ class FormFieldTest extends SapphireTest { + public function testAddExtraClass() { + $field = new FormField('MyField'); + $field->addExtraClass('class1'); + $field->addExtraClass('class2'); + $this->assertStringEndsWith('class1 class2', $field->extraClass()); + } + + public function testRemoveExtraClass() { + $field = new FormField('MyField'); + $field->addExtraClass('class1'); + $field->addExtraClass('class2'); + $this->assertStringEndsWith('class1 class2', $field->extraClass()); + $field->removeExtraClass('class1'); + $this->assertStringEndsWith('class2', $field->extraClass()); + } + public function testAttributes() { $field = new FormField('MyField'); $field->setAttribute('foo', 'bar');