1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Elements\CountDown\Tests; |
4
|
|
|
|
5
|
|
|
use Dynamic\Elements\CountDown\Elements\ElementCountDown; |
6
|
|
|
use SilverStripe\Core\Injector\Injector; |
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime; |
10
|
|
|
use SilverStripe\ORM\ValidationResult; |
11
|
|
|
use SilverStripe\View\ArrayData; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ElementCountDownTest |
15
|
|
|
* @package Dynamic\Elements\Tests |
16
|
|
|
*/ |
17
|
|
|
class ElementCountDownTest extends SapphireTest |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected static $fixture_file = '../fixtures.yml'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
public function testGetSummary() |
28
|
|
|
{ |
29
|
|
|
/** @var ElementCountDown $endonly */ |
30
|
|
|
$endonly = $this->objFromFixture(ElementCountDown::class, 'endonly'); |
31
|
|
|
$end = $endonly->dbObject('End'); |
32
|
|
|
$this->assertEquals($endonly->getSummary(), "Count down to {$end->Date()} {$end->Time()}"); |
33
|
|
|
|
34
|
|
|
/** @var ElementCountDown $timezone */ |
35
|
|
|
$timezone = $this->objFromFixture(ElementCountDown::class, 'timezone'); |
36
|
|
|
$end = $timezone->dbObject('End'); |
37
|
|
|
$tz = $timezone->dbObject('Timezone'); |
38
|
|
|
$this->assertEquals($timezone->getSummary(), "Count down to {$end->Date()} {$end->Time()} {$tz}"); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetCMSFields() |
42
|
|
|
{ |
43
|
|
|
/** @var ElementCountDown $element */ |
44
|
|
|
$element = $this->objFromFixture(ElementCountDown::class, 'endonly'); |
45
|
|
|
$this->assertInstanceOf(FieldList::class, $element->getCMSFields()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
*/ |
51
|
|
|
public function testGetType() |
52
|
|
|
{ |
53
|
|
|
/** @var ElementCountDown $element */ |
54
|
|
|
$element = $this->objFromFixture(ElementCountDown::class, 'endonly'); |
55
|
|
|
$this->assertEquals($element->getType(), 'Countdown'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* |
60
|
|
|
*/ |
61
|
|
|
public function testValidate() |
62
|
|
|
{ |
63
|
|
|
/** @var ElementCountDown $element */ |
64
|
|
|
$element = ElementCountDown::create(); |
65
|
|
|
$element->Title = 'Element'; |
66
|
|
|
|
67
|
|
|
$valid = $element->validate(); |
68
|
|
|
$this->assertInstanceOf(ValidationResult::class, $valid); |
69
|
|
|
$this->assertTrue($valid->isValid()); |
70
|
|
|
|
71
|
|
|
$element->ID = 351120; |
72
|
|
|
$this->assertFalse($element->validate()->isValid()); |
73
|
|
|
|
74
|
|
|
$element->ID = 0; |
75
|
|
|
$element->write(); |
76
|
|
|
|
77
|
|
|
$element->Sort = 5; |
78
|
|
|
$this->assertTrue($element->validate()->isValid()); |
79
|
|
|
|
80
|
|
|
$element->Title = 'New Title'; |
81
|
|
|
$this->assertFalse($element->validate()->isValid()); |
82
|
|
|
|
83
|
|
|
$element->End = DBDatetime::now(); |
84
|
|
|
$this->assertTrue($element->validate()->isValid()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* |
89
|
|
|
*/ |
90
|
|
|
public function testGetClientConfig() |
91
|
|
|
{ |
92
|
|
|
/** @var ElementCountDown $element */ |
93
|
|
|
$element = $this->objFromFixture(ElementCountDown::class, 'endonly'); |
94
|
|
|
$this->assertInstanceOf(ArrayData::class, $element->getClientConfig()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
*/ |
100
|
|
|
public function testEncodeArrayValues() |
101
|
|
|
{ |
102
|
|
|
/** @var ElementCountDown $element */ |
103
|
|
|
$element = $this->objFromFixture(ElementCountDown::class, 'elapse'); |
104
|
|
|
$config = $element->getClientConfig(); |
105
|
|
|
|
106
|
|
|
$this->assertEquals(json_decode($config->getField('End')), $element->End); |
107
|
|
|
$this->assertEquals(json_decode($config->getField('Elapse')), $element->Elapse); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|