Completed
Branch AUTOMATED_TESTING (09d9f2)
by Gordon
13:24
created

LatLongFieldTest::testConstructValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4286
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
class LatLongFieldTest extends SapphireTest {
4
	public function testConstructValid() {
5
		$mapField = new LatLongField(array(
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...
6
			new TextField('Lat', 'Latitude'),
7
			new TextField('Lon', 'Longitude'),
8
			new TextField('ZoomLevel', 'Zoom')
9
			),
10
			array('Address')
11
		);
12
13
14
	}
15
16
	public function testConstructOneFieldInvalid() {
17
		try {
18
			$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...
19
				array(
20
					new TextField('Lat', 'Latitude')
21
				)
22
			);
23
			$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...
24
		} catch (Exception $e) {
25
			$expected = 'LatLongField argument 1 must be an array containing at'
26
					  . ' least two FormField objects for Lat/Long values, resp'
27
					  . 'ectively.';
28
			$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...
29
		}
30
	}
31
32
33
	public function testConstructTwoFieldsValid() {
34
		$mapField = new LatLongField(
35
			array(
36
				new TextField('Lat', 'Latitude'),
37
				new TextField('Lon', 'Longitude')
38
			)
39
		);
40
41
		$html = $mapField->FieldHolder();
42
		echo $html;
43
		$this->assertContains(
44
			'<label class="fieldholder-small-label" for="Lat">Latitude</label>',
45
			$html
46
		);
47
		$this->assertContains(
48
			'<input type="text" name="Lat" class="text hide" id="Lat" />',
49
			$html
50
		);
51
		$this->assertContains(
52
			'<label class="fieldholder-small-label" for="Lon">Longitude</label>',
53
			$html
54
		);
55
		$this->assertContains(
56
			'<input type="text" name="Lon" class="text hide" id="Lon" />',
57
			$html
58
		);
59
60
	}
61
62
63
	public function testConstructThreeFieldsValid() {
64
		$mapField = new LatLongField(
65
			array(
66
				new TextField('Lat', 'Latitude'),
67
				new TextField('Lon', 'Longitude'),
68
				new TextField('ZoomLevel', 'Zoom')
69
			)
70
		);
71
72
		$html = $mapField->FieldHolder();
73
		echo $html;
74
		$this->assertContains(
75
			'<label class="fieldholder-small-label" for="Lat">Latitude</label>',
76
			$html
77
		);
78
		$this->assertContains(
79
			'<input type="text" name="Lat" class="text hide" id="Lat" />',
80
			$html
81
		);
82
		$this->assertContains(
83
			'<label class="fieldholder-small-label" for="Lon">Longitude</label>',
84
			$html
85
		);
86
		$this->assertContains(
87
			'<input type="text" name="Lon" class="text hide" id="Lon" />',
88
			$html
89
		);
90
		$this->assertContains(
91
			'<label class="fieldholder-small-label" for="ZoomLevel">Zoom</label>',
92
			$html
93
		);
94
		$this->assertContains(
95
			'<input type="text" name="ZoomLevel" class="text hide" id="ZoomLevel" />',
96
			$html
97
		);
98
	}
99
100
101
	public function testGeocode() {
102
		$this->markTestAsSkipped('TODO');
0 ignored issues
show
Bug introduced by
The method markTestAsSkipped() 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...
103
	}
104
105
106
	public function testSetGuidePoints() {
107
		$mapField = new LatLongField(
108
			array(
109
				new TextField('Lat', 'Latitude'),
110
				new TextField('Lon', 'Longitude'),
111
				new TextField('ZoomLevel', 'Zoom')
112
			)
113
		);
114
		$guidePoints = array(
115
			array('latitude' => 42, 'longitude' => '113.1'),
116
			array('latitude' => 14.9, 'longitude' => '113.2'),
117
			array('latitude' => 42.3, 'longitude' => '113.4'),
118
		);
119
		$mapField->setGuidePoints($guidePoints);
120
121
		$html = $mapField->FieldHolder();
122
		$expected = 'data-GuidePoints="[{&quot;latitude&quot;:42,&quot;longitude&quot;:&quot;113.1&'
123
				  . 'quot;},{&quot;latitude&quot;:14.9,&quot;longitude&quot;:&quot;113.2&quot;},{&q'
124
				  . 'uot;latitude&quot;:42.3,&quot;longitude&quot;:&quot;113.4&quot;}]"';
125
126
		$this->assertContains($expected, $html);
127
	}
128
129
}
130