Completed
Push — master ( 4d8653...004cc8 )
by Simon
01:19
created

RangeFieldTest::testGetSetStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\RangeField\Tests;
4
5
use Firesphere\RangeField\RangeField;
6
use SilverStripe\Dev\SapphireTest;
7
8
class RangeFieldTest extends SapphireTest
9
{
10
    public function testDefault()
11
    {
12
        $field = RangeField::create('Test', 'Test');
13
        $this->assertEquals([0], $field->getStart());
14
        $this->assertEquals(0, $field->getMin());
15
        $this->assertEquals(100, $field->getMax());
16
        $this->assertFalse($field->isSnap());
17
        $this->assertEquals([], $field->getRange());
18
    }
19
20
    public function testRange()
21
    {
22
        $rangeField = RangeField::create(
23
            'TestInt',
24
            'Test',
25
            50,
26
            25,
27
            75,
28
            ['min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75]
29
        );
30
31
        $rangeField->Field([]);
32
33
        $expected = [
34
            'start' => [50],
35
            'snap'  => true,
36
            'range' => [
37
                'min' => 25,
38
                '17%' => 33,
39
                '50%' => 50,
40
                '83%' => 66,
41
                'max' => 75
42
            ],
43
            'pips'  => [  // Show a scale with the slider
44
                'mode'    => 'steps',
45
                'stepped' => true,
46
                'density' => 4
47
            ]
48
        ];
49
50
        $this->assertEquals($expected, $rangeField->getData());
51
    }
52
53
    public function testGetSetMin()
54
    {
55
        $field = RangeField::create('Test', 'Test');
56
        
57
        $field->setMin(10);
58
        
59
        $this->assertEquals([10], $field->getMin());
60
    }
61
62
    public function testGetSetMax()
63
    {
64
        $field = RangeField::create('Test', 'Test');
65
        
66
        $field->setMax(10);
67
        
68
        $this->assertEquals(10, $field->getMax());
69
    }
70
    
71
    public function testGetSetRange()
72
    {
73
        $field = RangeField::create('Test', 'Test');
74
75
        $this->assertEquals([], $field->getRange());
76
77
        $field->setRange([
78
            'min' => 25,
79
            '17%' => 33,
80
            '50%' => 50,
81
            '83%' => 66,
82
            'max' => 75
83
        ]);
84
        
85
        $this->assertEquals([
86
            'min' => 25,
87
            '17%' => 33,
88
            '50%' => 50,
89
            '83%' => 66,
90
            'max' => 75
91
        ], $field->getRange());
92
    }
93
94
    public function testGetSetDensity()
95
    {
96
        $field = RangeField::create('Test', 'Test');
97
98
        $this->assertEquals(4, $field->getDensity());
99
100
        $field->setDensity(10);
101
        
102
        $this->assertEquals(10, $field->getDensity());
103
    }
104
105
    public function testIsSetPips()
106
    {
107
        $field = RangeField::create('Test', 'Test');
108
109
        $this->assertTrue($field->isShowPips());
110
111
        $field->setShowPips(false);
112
        
113
        $this->assertFalse($field->isShowPips());
114
    }
115
116
    public function testGetSetStart()
117
    {
118
        $field = RangeField::create('Test', 'Test', [5, 25]);
119
120
        $this->assertEquals([5, 25], $field->getStart());
121
122
        $field = RangeField::create('Test', 'Test');
123
124
        $this->assertEquals([0], $field->getStart());
125
126
        $field->setStart(10);
127
128
        $this->assertEquals([10], $field->getStart());
129
    }
130
}
131