SortableUploadFieldTest::testSchemaDefaults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.9332
1
<?php
2
3
namespace Bummzack\SortableFile\Tests;
4
5
use Bummzack\SortableFile\Forms\SortableUploadField;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\Form;
10
use SilverStripe\Forms\FormAction;
11
12
/**
13
 * Test basic field functionality, such as properties etc.
14
 * @package Bummzack\SortableFile\Tests
15
 */
16
class SortableUploadFieldTest extends SapphireTest
17
{
18
    protected static $fixture_file = 'SortableUploadFieldTest.yml';
19
20
    public function testSchemaDefaults()
21
    {
22
        $field = SortableUploadField::create('Files');
23
24
        // Setup a dummy form, so that `getSchemaDataDefaults` doesn't error out
25
        Controller::config()->set('url_segment', 'dummy');
26
        Form::create(
27
            Controller::curr(),
28
            'TestForm',
29
            FieldList::create($field),
30
            FieldList::create(FormAction::create('test'))
31
        );
32
33
        $data = $field->getSchemaDataDefaults();
34
35
        $this->assertArrayHasKey('sortable', $data);
36
        $this->assertTrue($data['sortable']);
37
    }
38
39
    public function testSortColumn()
40
    {
41
        $field = SortableUploadField::create('Files');
42
43
        $this->assertEquals('SortOrder', $field->getSortColumn(), 'Default value should be "SortOrder"');
44
45
        $field->setSortColumn('Sort');
46
47
        $this->assertEquals('Sort', $field->getSortColumn(), 'Changed value should be "Sort"');
48
    }
49
}
50