2016-12-13 22:45:42 +01:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Test\FormField;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-08-11 02:20:12 +02:00
|
|
|
use SilverStripe\Forms\RequiredFields;
|
|
|
|
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2016-12-13 22:45:42 +01:00
|
|
|
class UserFormsCheckboxSetFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testValidate() {
|
2017-08-11 02:20:12 +02:00
|
|
|
$field = new UserFormsCheckboxSetField('Field', 'My field', ['One' => 'One', 'Two' => 'Two']);
|
2016-12-13 22:45:42 +01:00
|
|
|
$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));
|
|
|
|
}
|
2017-08-11 02:20:12 +02:00
|
|
|
}
|