|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class LatLongFieldTest extends SapphireTest |
|
4
|
|
|
{ |
|
5
|
1 |
|
public function testConstructValid() |
|
6
|
|
|
{ |
|
7
|
1 |
|
$mapField = new LatLongField( |
|
|
|
|
|
|
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( |
|
|
|
|
|
|
21
|
1 |
|
array( |
|
22
|
|
|
new TextField('Lat', 'Latitude'), |
|
23
|
1 |
|
) |
|
24
|
|
|
); |
|
25
|
1 |
|
$this->fail('Creation of lat long field should have failed'); |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
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="[{"latitude":42,"longitude":"113.1&' |
|
122
|
1 |
|
.'quot;},{"latitude":14.9,"longitude":"113.2"},{&q' |
|
123
|
|
|
.'uot;latitude":42.3,"longitude":"113.4"}]"'; |
|
124
|
1 |
|
|
|
125
|
1 |
|
$this->assertContains($expected, $html); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.