2017-11-02 22:44:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2018-04-29 11:33:05 +02:00
|
|
|
use SilverStripe\Forms\DropdownField;
|
2017-11-02 22:44:45 +01:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableCountryDropdownField;
|
|
|
|
|
|
|
|
class EditableCountryDropdownFieldTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testGetIcon()
|
|
|
|
{
|
|
|
|
$field = new EditableCountryDropdownField;
|
|
|
|
|
|
|
|
$this->assertContains('/images/editabledropdown.png', $field->getIcon());
|
|
|
|
}
|
2018-03-23 04:18:32 +01:00
|
|
|
|
|
|
|
public function testAllowEmptyTitle()
|
|
|
|
{
|
|
|
|
/** @var EditableCountryDropdownField $field */
|
|
|
|
$field = EditableCountryDropdownField::create();
|
|
|
|
$field->Name = 'EditableFormField_123456';
|
|
|
|
$this->assertEmpty($field->getFormField()->Title());
|
|
|
|
}
|
2018-04-29 11:33:05 +02:00
|
|
|
|
|
|
|
public function testCMSFieldsContainsDefaultValue()
|
|
|
|
{
|
|
|
|
/** @var EditableCountryDropdownField $field */
|
|
|
|
$field = EditableCountryDropdownField::create();
|
|
|
|
$cmsFields = $field->getCMSFields();
|
|
|
|
$defaultField = $cmsFields->dataFieldByName('Default');
|
|
|
|
$this->assertNotNull($defaultField);
|
|
|
|
$this->assertInstanceOf(DropdownField::class, $defaultField);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaultValue()
|
|
|
|
{
|
|
|
|
/** @var EditableCountryDropdownField $field */
|
|
|
|
$field = EditableCountryDropdownField::create();
|
|
|
|
$field->Default = 'nz';
|
|
|
|
$this->assertEquals($field->getFormField()->Value(), 'nz');
|
|
|
|
}
|
2018-05-01 06:07:03 +02:00
|
|
|
|
|
|
|
public function testEmptyDefaultValue()
|
|
|
|
{
|
|
|
|
/** @var EditableCountryDropdownField $field */
|
|
|
|
$field = EditableCountryDropdownField::create();
|
|
|
|
|
|
|
|
/** @var DropdownField $formField */
|
|
|
|
$formField = $field->getFormField();
|
|
|
|
$this->assertFalse($formField->getHasEmptyDefault());
|
|
|
|
$this->assertEmpty($formField->getEmptyString());
|
|
|
|
|
|
|
|
$field->UseEmptyString = true;
|
|
|
|
$field->EmptyString = '--- empty ---';
|
|
|
|
|
|
|
|
/** @var DropdownField $formField */
|
|
|
|
$formField = $field->getFormField();
|
|
|
|
$this->assertTrue($formField->getHasEmptyDefault());
|
|
|
|
$this->assertEquals($formField->getEmptyString(), $field->EmptyString);
|
|
|
|
}
|
2017-11-02 22:44:45 +01:00
|
|
|
}
|