2016-12-13 22:45:42 +01:00
|
|
|
<?php
|
|
|
|
|
2017-08-15 23:31:47 +02:00
|
|
|
namespace SilverStripe\UserForms\Tests\FormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2017-08-11 02:37:03 +02:00
|
|
|
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
|
|
|
}
|