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
|
|
|
|