Passed
Pull Request — master (#8)
by Matthew
13:52
created

ElementCountDownTest::testValidate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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\View\ArrayData;
9
10
/**
11
 * Class ElementCountDownTest
12
 * @package Dynamic\Elements\Tests
13
 */
14
class ElementCountDownTest extends SapphireTest
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $fixture_file = '../fixtures.yml';
20
21
    /**
22
     *
23
     */
24
    public function testGetType()
25
    {
26
        /** @var ElementCountDown $object */
27
        $element = $this->objFromFixture(ElementCountDown::class, 'endonly');
0 ignored issues
show
Unused Code introduced by
The assignment to $element is dead and can be removed.
Loading history...
28
        $this->assertEquals($object->getType(), 'Count Down');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $object seems to be never defined.
Loading history...
29
    }
30
31
    public function testValidate()
32
    {
33
        /** @var ElementCountDown $object */
34
        $element = $this->objFromFixture(ElementCountDown::class, 'endonly');
35
        $this->assertTrue($element->validate()->isValid());
36
37
        $element = $this->objFromFixture(ElementCountDown::class, 'invalid');
38
        $this->assertFalse($element->validate()->isValid());
39
40
    }
41
42
    /**
43
     *
44
     */
45
    public function testGetClientConfig()
46
    {
47
        /** @var ElementCountDown $object */
48
        $element = $this->objFromFixture(ElementCountDown::class, 'endonly');
49
        $this->assertInstanceOf(ArrayData::class, $element->getClientConfig());
50
    }
51
52
    /**
53
     *
54
     */
55
    public function testEncodeArrayValues()
56
    {
57
        /** @var ElementCountDown $object */
58
        $element = $this->objFromFixture(ElementCountDown::class, 'elapse');
59
        $config = $element->getClientConfig();
60
61
        $this->assertEquals(json_decode($config->getField('End')), $element->End);
62
        $this->assertEquals(json_decode($config->getField('Elapse')), $element->Elapse);
63
    }
64
}
65