LatLongFieldTest::testConstructTwoFieldsValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 18
cts 18
cp 1
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
class LatLongFieldTest extends SapphireTest
4
{
5 1
    public function testConstructValid()
6
    {
7 1
        $mapField = new LatLongField(
0 ignored issues
show
Unused Code introduced by
$mapField is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
8 1
            array(
9 1
            new TextField('Lat', 'Latitude'),
10 1
            new TextField('Lon', 'Longitude'),
11 1
            new TextField('ZoomLevel', 'Zoom'),
12 1
            ),
13 1
            array('Address')
14 1
        );
15
    }
16 1
17
    public function testConstructOneFieldInvalid()
18
    {
19 1
        try {
20
            $mapField = new LatLongField(
0 ignored issues
show
Unused Code introduced by
$mapField is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
21 1
                array(
22
                    new TextField('Lat', 'Latitude'),
23 1
                )
24
            );
25 1
            $this->fail('Creation of lat long field should have failed');
0 ignored issues
show
Bug introduced by
The method fail() does not seem to exist on object<LatLongFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        } catch (Exception $e) {
27
            $expected = 'LatLongField argument 1 must be an array containing at'
28 1
                      .' least two FormField objects for Lat/Long values, resp'
29 1
                      .'ectively.';
30
            $this->assertEquals($expected, $e->getMessage());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<LatLongFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31 1
        }
32
    }
33 4
34
    public function testConstructTwoFieldsValid()
35 1
    {
36
        $mapField = new LatLongField(
37 1
            array(
38 1
                new TextField('Lat', 'Latitude'),
39
                new TextField('Lon', 'Longitude'),
40 1
            )
41
        );
42 1
43 1
        $html = $mapField->FieldHolder();
44 1
        $this->assertContains(
45
            '<label class="fieldholder-small-label" for="Lat">Latitude</label>',
46 1
            $html
47 4
        );
48 1
        $this->assertContains(
49
            '<input type="text" name="Lat" class="text hide" id="Lat" />',
50 1
            $html
51 1
        );
52 1
        $this->assertContains(
53
            '<label class="fieldholder-small-label" for="Lon">Longitude</label>',
54 1
            $html
55 1
        );
56 1
        $this->assertContains(
57
            '<input type="text" name="Lon" class="text hide" id="Lon" />',
58 1
            $html
59 1
        );
60
    }
61 1
62
    public function testConstructThreeFieldsValid()
63 1
    {
64
        $mapField = new LatLongField(
65 1
            array(
66 1
                new TextField('Lat', 'Latitude'),
67 1
                new TextField('Lon', 'Longitude'),
68
                new TextField('ZoomLevel', 'Zoom'),
69 1
            )
70
        );
71 1
72 1
        $html = $mapField->FieldHolder();
73 1
        $this->assertContains(
74
            '<label class="fieldholder-small-label" for="Lat">Latitude</label>',
75 1
            $html
76 1
        );
77 1
        $this->assertContains(
78
            '<input type="text" name="Lat" class="text hide" id="Lat" />',
79 1
            $html
80 1
        );
81 1
        $this->assertContains(
82
            '<label class="fieldholder-small-label" for="Lon">Longitude</label>',
83 1
            $html
84 1
        );
85 1
        $this->assertContains(
86
            '<input type="text" name="Lon" class="text hide" id="Lon" />',
87 1
            $html
88 1
        );
89 1
        $this->assertContains(
90
            '<label class="fieldholder-small-label" for="ZoomLevel">Zoom</label>',
91 1
            $html
92 1
        );
93 1
        $this->assertContains(
94 1
            '<input type="text" name="ZoomLevel" class="text hide" id="ZoomLevel" />',
95 1
            $html
96 1
        );
97
    }
98
99
    public function testGeocode()
100
    {
101
        $this->markTestSkipped('TODO');
102
    }
103 1
104
    public function testSetGuidePoints()
105 1
    {
106
        $mapField = new LatLongField(
107 1
            array(
108 1
                new TextField('Lat', 'Latitude'),
109 1
                new TextField('Lon', 'Longitude'),
110
                new TextField('ZoomLevel', 'Zoom'),
111 1
            )
112
        );
113 1
        $guidePoints = array(
114 1
            array('latitude' => 42, 'longitude' => '113.1'),
115 1
            array('latitude' => 14.9, 'longitude' => '113.2'),
116 1
            array('latitude' => 42.3, 'longitude' => '113.4'),
117 1
        );
118
        $mapField->setGuidePoints($guidePoints);
119 1
120
        $html = $mapField->FieldHolder();
121
        $expected = 'data-GuidePoints="[{&quot;latitude&quot;:42,&quot;longitude&quot;:&quot;113.1&'
122 1
                  .'quot;},{&quot;latitude&quot;:14.9,&quot;longitude&quot;:&quot;113.2&quot;},{&q'
123
                  .'uot;latitude&quot;:42.3,&quot;longitude&quot;:&quot;113.4&quot;}]"';
124 1
125 1
        $this->assertContains($expected, $html);
126
    }
127
}
128