BUG FormField->removeExtraClass() works on indexed arrays

Was assuming an associative map, which isn't the case
in the current implementations.
This commit is contained in:
Ingo Schommer 2012-10-31 15:44:57 +01:00
parent d342794cfe
commit 2d04de0377
2 changed files with 19 additions and 3 deletions

View File

@ -321,9 +321,9 @@ class FormField extends RequestHandler {
* @param $class String * @param $class String
*/ */
public function removeExtraClass($class) { public function removeExtraClass($class) {
if(isset($this->extraClasses) && array_key_exists($class, $this->extraClasses)) { $pos = array_search($class, $this->extraClasses);
unset($this->extraClasses[$class]); if($pos !== false) unset($this->extraClasses[$pos]);
}
return $this; return $this;
} }

View File

@ -5,6 +5,22 @@
*/ */
class FormFieldTest extends SapphireTest { 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() { public function testAttributes() {
$field = new FormField('MyField'); $field = new FormField('MyField');
$field->setAttribute('foo', 'bar'); $field->setAttribute('foo', 'bar');