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(), '');
|
|
|
|
}
|
2018-03-23 04:18:32 +01:00
|
|
|
|
|
|
|
public function testAllowEmptyTitle()
|
|
|
|
{
|
|
|
|
/** @var EditableDropdown $field */
|
|
|
|
$field = EditableDropdown::create();
|
|
|
|
$field->Name = 'EditableFormField_123456';
|
|
|
|
$this->assertEmpty($field->getFormField()->Title());
|
|
|
|
}
|
2018-03-22 23:43:50 +01:00
|
|
|
|
|
|
|
public function testDuplicate()
|
|
|
|
{
|
|
|
|
/** @var EditableDropdown $dropdown */
|
|
|
|
$dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
|
|
|
|
$this->assertCount(2, $dropdown->Options());
|
|
|
|
|
|
|
|
$duplicatedDropdown = $dropdown->duplicate();
|
|
|
|
$this->assertSame($dropdown->Options()->count(), $duplicatedDropdown->Options()->count());
|
|
|
|
}
|
2016-11-17 00:04:54 +01:00
|
|
|
}
|