| 1 |  |  | <?php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 3 |  |  | class LatLongFieldTest extends SapphireTest { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	public function testConstructValid() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 		$mapField = new LatLongField(array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 				array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 					new TextField('Lat', 'Latitude') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 				) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			$this->fail('Creation of lat long field should have failed'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 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="[{"latitude":42,"longitude":"113.1&' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 				  . 'quot;},{"latitude":14.9,"longitude":"113.2"},{&q' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 				  . 'uot;latitude":42.3,"longitude":"113.4"}]"'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$this->assertContains($expected, $html); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 127 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 129 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 130 |  |  |  | 
            
                        
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.