1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\DocumentConverter\Tests; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use SilverStripe\DocumentConverter\SettingsField; |
7
|
|
|
use SilverStripe\DocumentConverter\ImportField; |
8
|
|
|
use SilverStripe\Forms\CheckboxField; |
9
|
|
|
use SilverStripe\Forms\DropdownField; |
10
|
|
|
use SilverStripe\Forms\FieldList; |
11
|
|
|
use SilverStripe\Forms\HeaderField; |
12
|
|
|
use SilverStripe\Forms\LiteralField; |
13
|
|
|
use SilverStripe\Forms\TreeDropdownField; |
14
|
|
|
use SilverStripe\View\Requirements; |
15
|
|
|
|
16
|
|
|
class SettingsFieldTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @expectedException InvalidArgumentException |
20
|
|
|
*/ |
21
|
|
|
public function testConstructorThrowsExceptionWhenGivenString() |
22
|
|
|
{ |
23
|
|
|
new SettingsField('exception time!'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @expectedException InvalidArgumentException |
28
|
|
|
*/ |
29
|
|
|
public function testConstructorThrowsExceptionWhenGivenChildren() |
30
|
|
|
{ |
31
|
|
|
new SettingsField(['i', 'don\'t', 'like', 'kids']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testFieldAddsJavascriptRequirements() |
35
|
|
|
{ |
36
|
|
|
// Start with a clean slate (no global state interference) |
37
|
|
|
Requirements::backend()->clear(); |
38
|
|
|
|
39
|
|
|
new SettingsField(); |
40
|
|
|
$javascript = Requirements::backend()->getJavascript(); |
41
|
|
|
$this->assertNotEmpty($javascript); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testFieldListGeneration() |
45
|
|
|
{ |
46
|
|
|
$importField = new SettingsField(); |
47
|
|
|
|
48
|
|
|
$fields = $importField->getChildren(); |
49
|
|
|
$this->assertInstanceOf(FieldList::class, $fields); |
50
|
|
|
|
51
|
|
|
// We don't need to check that all of the fields are there, but just check a couple |
52
|
|
|
$this->assertInstanceOf(LiteralField::class, $fields->fieldByName('FileWarningHeader')); |
53
|
|
|
$innerField = $fields->fieldByName('ImportedFromFile'); |
54
|
|
|
$this->assertInstanceOf(ImportField::class, $innerField); |
55
|
|
|
|
56
|
|
|
// Check the getter works |
57
|
|
|
$this->assertSame($innerField, $importField->getInnerField()); |
58
|
|
|
|
59
|
|
|
// Check the fields have been given has the change tracker disabled |
60
|
|
|
$settingsFields = [ |
61
|
|
|
'SplitHeader' => DropdownField::class, |
62
|
|
|
'KeepSource' => CheckboxField::class, |
63
|
|
|
'ChosenFolderID' => TreeDropdownField::class, |
64
|
|
|
'IncludeTOC' => CheckboxField::class, |
65
|
|
|
'PublishPages' => CheckboxField::class |
66
|
|
|
]; |
67
|
|
|
foreach ($settingsFields as $fieldName => $className) { |
68
|
|
|
$field = $fields->fieldByName( |
69
|
|
|
'DocumentConversionSettings-' . $fieldName |
70
|
|
|
); |
71
|
|
|
$this->assertInstanceOf($className, $field); |
72
|
|
|
$this->assertContains('no-change-track', $field->extraClass()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|