Passed
Pull Request — master (#749)
by Daniel
06:06
created

EditableDropdownTest::testDuplicate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
    public function testAllowEmptyTitle()
41
    {
42
        /** @var EditableDropdown $field */
43
        $field = EditableDropdown::create();
44
        $field->Name = 'EditableFormField_123456';
45
        $this->assertEmpty($field->getFormField()->Title());
46
    }
47
48
    public function testDuplicate()
49
    {
50
        /** @var EditableDropdown $dropdown */
51
        $dropdown = $this->objFromFixture(EditableDropdown::class, 'basic-dropdown');
52
        $this->assertCount(2, $dropdown->Options());
0 ignored issues
show
Bug introduced by
The method Options() does not exist on SilverStripe\UserForms\M...mField\EditableDropdown. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $this->assertCount(2, $dropdown->/** @scrutinizer ignore-call */ Options());
Loading history...
53
54
        $duplicatedDropdown = $dropdown->duplicate();
55
        $this->assertSame($dropdown->Options()->count(), $duplicatedDropdown->Options()->count());
0 ignored issues
show
Bug introduced by
The method count() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as DOMNodeList or Threaded or SimpleXMLElement or DOMNamedNodeMap or Thread or Worker or Stackable or MongoGridFSCursor or ResourceBundle or SilverStripe\ORM\SS_List or SilverStripe\View\ViewableData or PHPUnit_Framework_TestSuite or SilverStripe\ORM\Map or Symfony\Component\Finder\Finder or SebastianBergmann\CodeCoverage\Node\Directory or ArrayObject or SplDoublyLinkedList or HttpMessage or HttpRequestPool or PHP_CodeSniffer\Files\FileList or SplFixedArray or SplObjectStorage or SQLiteResult or Imagick or SplPriorityQueue or MongoCursor or SplHeap or MongoGridFSCursor or CachingIterator or PHP_Token_Stream or Phar or ArrayIterator or GlobIterator or Phar or Phar or RecursiveCachingIterator or RecursiveArrayIterator or SimpleXMLIterator or Phar. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $this->assertSame($dropdown->Options()->/** @scrutinizer ignore-call */ count(), $duplicatedDropdown->Options()->count());
Loading history...
56
    }
57
}
58