mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\UserForms\Tests\FormField;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
use SilverStripe\Forms\RequiredFields;
|
|
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
|
|
|
|
class UserFormsCheckboxSetFieldTest extends SapphireTest
|
|
{
|
|
public function testValidate()
|
|
{
|
|
$field = new UserFormsCheckboxSetField('Field', 'My field', ['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));
|
|
}
|
|
}
|