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->getMin()); |
14
|
|
|
$this->assertEquals(100, $field->getMax()); |
15
|
|
|
$this->assertFalse($field->isSnap()); |
16
|
|
|
$this->assertEquals([], $field->getRange()); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testRange() |
20
|
|
|
{ |
21
|
|
|
$rangeField = RangeField::create( |
22
|
|
|
'TestInt', |
23
|
|
|
'Test', |
24
|
|
|
25, |
25
|
|
|
75, |
26
|
|
|
['min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75] |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$rangeField->Field([]); |
30
|
|
|
|
31
|
|
|
$expected = [ |
32
|
|
|
'start' => [25], |
33
|
|
|
'snap' => true, |
34
|
|
|
'range' => [ |
35
|
|
|
'min' => 25, |
36
|
|
|
'17%' => 33, |
37
|
|
|
'50%' => 50, |
38
|
|
|
'83%' => 66, |
39
|
|
|
'max' => 75 |
40
|
|
|
], |
41
|
|
|
'pips' => [ // Show a scale with the slider |
42
|
|
|
'mode' => 'steps', |
43
|
|
|
'stepped' => true, |
44
|
|
|
'density' => 4 |
45
|
|
|
] |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
$this->assertEquals($expected, $rangeField->getData()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetSetMin() |
52
|
|
|
{ |
53
|
|
|
$field = RangeField::create('Test', 'Test'); |
54
|
|
|
|
55
|
|
|
$field->setMin(10); |
56
|
|
|
|
57
|
|
|
$this->assertEquals([10], $field->getMin()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetSetMax() |
61
|
|
|
{ |
62
|
|
|
$field = RangeField::create('Test', 'Test'); |
63
|
|
|
|
64
|
|
|
$field->setMax(10); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(10, $field->getMax()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetSetRange() |
70
|
|
|
{ |
71
|
|
|
$field = RangeField::create('Test', 'Test'); |
72
|
|
|
|
73
|
|
|
$this->assertEquals([], $field->getRange()); |
74
|
|
|
|
75
|
|
|
$field->setRange([ |
76
|
|
|
'min' => 25, |
77
|
|
|
'17%' => 33, |
78
|
|
|
'50%' => 50, |
79
|
|
|
'83%' => 66, |
80
|
|
|
'max' => 75 |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
$this->assertEquals([ |
84
|
|
|
'min' => 25, |
85
|
|
|
'17%' => 33, |
86
|
|
|
'50%' => 50, |
87
|
|
|
'83%' => 66, |
88
|
|
|
'max' => 75 |
89
|
|
|
], $field->getRange()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testGetSetDensity() |
93
|
|
|
{ |
94
|
|
|
$field = RangeField::create('Test', 'Test'); |
95
|
|
|
|
96
|
|
|
$this->assertEquals(4, $field->getDensity()); |
97
|
|
|
|
98
|
|
|
$field->setDensity(10); |
99
|
|
|
|
100
|
|
|
$this->assertEquals(10, $field->getDensity()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testIsSetPips() |
104
|
|
|
{ |
105
|
|
|
$field = RangeField::create('Test', 'Test'); |
106
|
|
|
|
107
|
|
|
$this->assertTrue($field->isShowPips()); |
108
|
|
|
|
109
|
|
|
$field->setShowPips(false); |
110
|
|
|
|
111
|
|
|
$this->assertFalse($field->isShowPips()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|