Completed
Push — master ( c8ac60...2e19d1 )
by Simon
01:15
created

RangeFieldTest::testSnap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 57
rs 9.6818
cc 1
eloc 41
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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'  => false,
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 testSnap()
54
    {
55
        $rangeField = RangeField::create(
56
            'TestInt',
57
            'Test',
58
            50,
59
            25,
60
            75,
61
            ['min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75]
62
        );
63
64
        $rangeField->setSnap(true);
65
66
        $rangeField->Field([]);
67
68
        $expected = [
69
            'start' => [50],
70
            'snap'  => true,
71
            'range' => [
72
                'min' => 25,
73
                '17%' => 33,
74
                '50%' => 50,
75
                '83%' => 66,
76
                'max' => 75
77
            ],
78
            'pips'  => [  // Show a scale with the slider
79
                'mode'    => 'steps',
80
                'stepped' => true,
81
                'density' => 4
82
            ]
83
        ];
84
85
        $this->assertEquals($expected, $rangeField->getData());
86
        $rangeField->setStep(1);
87
88
        $rangeField->Field([]);
89
90
        $expected = [
91
            'start' => [50],
92
            'snap'  => false,
93
            'step'  => 1,
94
            'range' => [
95
                'min' => 25,
96
                '17%' => 33,
97
                '50%' => 50,
98
                '83%' => 66,
99
                'max' => 75
100
            ],
101
            'pips'  => [  // Show a scale with the slider
102
                'mode'    => 'steps',
103
                'stepped' => true,
104
                'density' => 4
105
            ]
106
        ];
107
108
        $this->assertEquals($expected, $rangeField->getData());
109
    }
110
111
    public function testGetSetMin()
112
    {
113
        $field = RangeField::create('Test', 'Test');
114
115
        $field->setMin(10);
116
117
        $this->assertEquals(10, $field->getMin());
118
    }
119
120
    public function testGetSetStep()
121
    {
122
        $field = RangeField::create('Test', 'Test');
123
124
        $field->setStep(10);
125
126
        $this->assertEquals(10, $field->getStep());
127
    }
128
129
    public function testGetSetMax()
130
    {
131
        $field = RangeField::create('Test', 'Test');
132
133
        $field->setMax(10);
134
135
        $this->assertEquals(10, $field->getMax());
136
    }
137
138
    public function testGetSetRange()
139
    {
140
        $field = RangeField::create('Test', 'Test');
141
142
        $this->assertEquals([], $field->getRange());
143
144
        $field->setRange([
145
            'min' => 25,
146
            '17%' => 33,
147
            '50%' => 50,
148
            '83%' => 66,
149
            'max' => 75
150
        ]);
151
152
        $this->assertEquals([
153
            'min' => 25,
154
            '17%' => 33,
155
            '50%' => 50,
156
            '83%' => 66,
157
            'max' => 75
158
        ], $field->getRange());
159
    }
160
161
    public function testGetSetDensity()
162
    {
163
        $field = RangeField::create('Test', 'Test');
164
165
        $this->assertEquals(4, $field->getDensity());
166
167
        $field->setDensity(10);
168
169
        $this->assertEquals(10, $field->getDensity());
170
    }
171
172
    public function testIsSetPips()
173
    {
174
        $field = RangeField::create('Test', 'Test');
175
176
        $this->assertTrue($field->isShowPips());
177
178
        $field->setShowPips(false);
179
180
        $this->assertFalse($field->isShowPips());
181
    }
182
183
    public function testIsSetSnap()
184
    {
185
        $field = RangeField::create('Test', 'Test');
186
187
        $this->assertFalse($field->isSnap());
188
189
        $field->setSnap(true);
190
191
        $this->assertTrue($field->isSnap());
192
    }
193
194
    public function testGetSetStart()
195
    {
196
        $field = RangeField::create('Test', 'Test', [5, 25]);
197
198
        $this->assertEquals([5, 25], $field->getStart());
199
200
        $field = RangeField::create('Test', 'Test');
201
202
        $this->assertEquals([0], $field->getStart());
203
204
        $field->setStart(10);
205
206
        $this->assertEquals([10], $field->getStart());
207
    }
208
}
209