Completed
Pull Request — master (#647)
by Robbie
20:35 queued 18:30
created

EditableDropdownTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testFormField() 0 21 2
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\Model\EditableFormField;
4
5
use SilverStripe\UserForms\Model\EditableFormField\EditableDropdown;
6
use SilverStripe\Dev\SapphireTest;
7
8
/**
9
 * Tests the {@see EditableDropdown} class
10
 */
11
class EditableDropdownTest extends SapphireTest
12
{
13
    protected static $fixture_file = '../EditableFormFieldTest.yml';
14
15
    /**
16
     * Tests that the field sets the empty string if set
17
     */
18
    public function testFormField()
19
    {
20
        if (!$dropdown = EditableDropdown::get()->filter('UseEmptyString', true)->first()) {
21
            $dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
22
23
            $dropdown->UseEmptyString = true;
24
            $dropdown->EmptyString = 'My Default Empty String';
25
            $dropdown->write();
26
        }
27
28
        $field = $dropdown->getFormField();
29
        $this->assertEquals($field->getEmptyString(), 'My Default Empty String');
30
31
        $alternateDropdown = $this->objFromFixture(EditableDropdown::class, 'department-dropdown');
32
        $formField = $alternateDropdown->getFormField();
33
        $this->assertFalse($formField->getHasEmptyDefault());
34
35
        $alternateDropdown->UseEmptyString = true;
36
        $alternateDropdown->write();
37
        $this->assertEquals($formField->getEmptyString(), '');
38
    }
39
}
40