mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
parent
d0bf02d25f
commit
1743ed1556
@ -23,18 +23,6 @@ class UserFormsCheckboxSetField extends CheckboxSetField
|
|||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getSourceAsArray()
|
|
||||||
{
|
|
||||||
$array = parent::getSourceAsArray();
|
|
||||||
|
|
||||||
return array_values($array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*
|
*
|
||||||
|
29
tests/UserFormsCheckboxSetFieldTest.php
Normal file
29
tests/UserFormsCheckboxSetFieldTest.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class UserFormsCheckboxSetFieldTest extends SapphireTest
|
||||||
|
{
|
||||||
|
public function testValidate() {
|
||||||
|
$field = new UserFormsCheckboxSetField('Field', 'My field', array('One' => 'One', 'Two' => 'Two'));
|
||||||
|
$validator = new RequiredFields();
|
||||||
|
|
||||||
|
// String values
|
||||||
|
$field->setValue('One');
|
||||||
|
$this->assertTrue($field->validate($validator));
|
||||||
|
$field->setValue('One,Two');
|
||||||
|
$this->assertTrue($field->validate($validator));
|
||||||
|
$field->setValue('Three,Four');
|
||||||
|
$this->assertFalse($field->validate($validator));
|
||||||
|
|
||||||
|
// Array values
|
||||||
|
$field->setValue(array('One'));
|
||||||
|
$this->assertTrue($field->validate($validator));
|
||||||
|
$field->setValue(array('One', 'Two'));
|
||||||
|
$this->assertTrue($field->validate($validator));
|
||||||
|
|
||||||
|
// Invalid
|
||||||
|
$field->setValue('Three');
|
||||||
|
$this->assertFalse($field->validate($validator));
|
||||||
|
$field->setValue(array('Three', 'Four'));
|
||||||
|
$this->assertFalse($field->validate($validator));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user