2016-11-17 00:04:54 +01:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Test\Model\EditableFormField;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
public static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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(), '');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|