Skip to content
Browse files

BUG FormField->removeExtraClass() works on indexed arrays

Was assuming an associative map, which isn't the case
in the current implementations.
  • Loading branch information...
1 parent d342794 commit 2d04de0377aff41fa12188d7c5edf7dd6a47f1c6 @chillu chillu committed
Showing with 19 additions and 3 deletions.
  1. +3 −3 forms/FormField.php
  2. +16 −0 tests/forms/FormFieldTest.php
View
6 forms/FormField.php
@@ -321,9 +321,9 @@ public function addExtraClass($class) {
* @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;
}
View
16 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');

0 comments on commit 2d04de0

Please sign in to comment.
Something went wrong with that request. Please try again.