EditableCountryDropdownFieldTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 23
c 3
b 0
f 0
dl 0
loc 52
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testAllowEmptyTitle() 0 6 1
A testEmptyDefaultValue() 0 17 1
A testGetIcon() 0 5 1
A testDefaultValue() 0 6 1
A testCMSFieldsContainsDefaultValue() 0 8 1
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