testEmptyDefaultValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9666
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\UserForms\Model\EditableFormField\EditableCountryDropdownField;
8
9
class EditableCountryDropdownFieldTest extends SapphireTest
10
{
11
    public function testGetIcon()
12
    {
13
        $field = new EditableCountryDropdownField;
14
15
        $this->assertContains('/images/editabledropdown.png', $field->getIcon());
16
    }
17
18
    public function testAllowEmptyTitle()
19
    {
20
        /** @var EditableCountryDropdownField $field */
21
        $field = EditableCountryDropdownField::create();
22
        $field->Name = 'EditableFormField_123456';
23
        $this->assertEmpty($field->getFormField()->Title());
24
    }
25
26
    public function testCMSFieldsContainsDefaultValue()
27
    {
28
        /** @var EditableCountryDropdownField $field */
29
        $field = EditableCountryDropdownField::create();
30
        $cmsFields = $field->getCMSFields();
31
        $defaultField = $cmsFields->dataFieldByName('Default');
32
        $this->assertNotNull($defaultField);
33
        $this->assertInstanceOf(DropdownField::class, $defaultField);
34
    }
35
36
    public function testDefaultValue()
37
    {
38
        /** @var EditableCountryDropdownField $field */
39
        $field = EditableCountryDropdownField::create();
40
        $field->Default = 'nz';
41
        $this->assertEquals($field->getFormField()->Value(), 'nz');
42
    }
43
44
    public function testEmptyDefaultValue()
45
    {
46
        /** @var EditableCountryDropdownField $field */
47
        $field = EditableCountryDropdownField::create();
48
49
        /** @var DropdownField $formField */
50
        $formField = $field->getFormField();
51
        $this->assertFalse($formField->getHasEmptyDefault());
52
        $this->assertEmpty($formField->getEmptyString());
53
54
        $field->UseEmptyString = true;
55
        $field->EmptyString = '--- empty ---';
56
57
        /** @var DropdownField $formField */
58
        $formField = $field->getFormField();
59
        $this->assertTrue($formField->getHasEmptyDefault());
60
        $this->assertEquals($formField->getEmptyString(), $field->EmptyString);
61
    }
62
}
63