2016-11-17 00:04:54 +01:00
|
|
|
<?php
|
|
|
|
|
2017-08-15 23:31:47 +02:00
|
|
|
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2016-11-17 00:04:54 +01:00
|
|
|
/**
|
|
|
|
* Tests the {@see EditableDropdown} class
|
|
|
|
*/
|
|
|
|
class EditableDropdownTest extends SapphireTest
|
|
|
|
{
|
2017-08-11 02:20:12 +02:00
|
|
|
protected static $fixture_file = '../EditableFormFieldTest.yml';
|
2016-11-17 00:04:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the field sets the empty string if set
|
|
|
|
*/
|
|
|
|
public function testFormField()
|
|
|
|
{
|
|
|
|
if (!$dropdown = EditableDropdown::get()->filter('UseEmptyString', true)->first()) {
|
2017-08-09 01:55:09 +02:00
|
|
|
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
|
2016-11-17 00:04:54 +01:00
|
|
|
|
|
|
|
$dropdown->UseEmptyString = true;
|
|
|
|
$dropdown->EmptyString = 'My Default Empty String';
|
|
|
|
$dropdown->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
$field = $dropdown->getFormField();
|
|
|
|
$this->assertEquals($field->getEmptyString(), 'My Default Empty String');
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
$alternateDropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown');
|
2016-11-17 00:04:54 +01:00
|
|
|
$formField = $alternateDropdown->getFormField();
|
|
|
|
$this->assertFalse($formField->getHasEmptyDefault());
|
|
|
|
|
|
|
|
$alternateDropdown->UseEmptyString = true;
|
|
|
|
$alternateDropdown->write();
|
|
|
|
$this->assertEquals($formField->getEmptyString(), '');
|
|
|
|
}
|
|
|
|
}
|