1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Tests\Forms; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Forms\TextCheckboxGroupField; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Forms\CheckboxField; |
8
|
|
|
use SilverStripe\Forms\CompositeField; |
9
|
|
|
use SilverStripe\Forms\TextField; |
10
|
|
|
|
11
|
|
|
class TextCheckboxGroupFieldTest extends SapphireTest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var TextCheckboxGroupField |
15
|
|
|
*/ |
16
|
|
|
protected $field; |
17
|
|
|
|
18
|
|
|
protected function setUp(): void |
19
|
|
|
{ |
20
|
|
|
parent::setUp(); |
21
|
|
|
|
22
|
|
|
$this->field = new TextCheckboxGroupField('Title'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testFieldIsAssignedFirstFieldsTitleInConstructor() |
26
|
|
|
{ |
27
|
|
|
$this->assertSame('Title', $this->field->Title()); |
28
|
|
|
$this->assertSame('Title', $this->field->getChildren()->first()->Title()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testFieldReturnsCompositeFieldTemplateOnReadonlyTransformation() |
32
|
|
|
{ |
33
|
|
|
$this->assertSame( |
34
|
|
|
TextCheckboxGroupField::class, |
35
|
|
|
$this->field->getTemplates()[0], |
36
|
|
|
'Uses a custom template by default' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$readonly = $this->field->performReadonlyTransformation(); |
40
|
|
|
|
41
|
|
|
$this->assertSame( |
42
|
|
|
CompositeField::class, |
43
|
|
|
$readonly->getTemplate(), |
44
|
|
|
'Uses CompositeField template for readonly' |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testRemovedFieldsCanDoReadonlyTransformation() |
49
|
|
|
{ |
50
|
|
|
$this->field->removeByName('Title'); |
51
|
|
|
$readonly = $this->field->performReadonlyTransformation(); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(TextCheckboxGroupField::class, $readonly); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|