Browse Source

Mock geocoding away.

euromark 11 years ago
parent
commit
c15d7d2339

+ 3 - 1
Lib/GeocodeLib.php

@@ -695,7 +695,9 @@ class GeocodeLib {
 	 * @return mixed
 	 **/
 	protected function _fetch($url, $query) {
-		$this->HttpSocket = new HttpSocket();
+		if (!isset($this->HttpSocket)) {
+			$this->HttpSocket = new HttpSocket();
+		}
 		foreach ($query as $k => $v) {
 			if ($v === '') {
 				unset($query[$k]);

+ 62 - 1
Test/Case/Lib/GeocodeLibTest.php

@@ -2,6 +2,7 @@
 
 App::uses('GeocodeLib', 'Tools.Lib');
 App::uses('MyCakeTestCase', 'Tools.TestSuite');
+App::uses('HttpSocketResponse', 'Network/Http');
 
 # google maps
 Configure::write('Google', array(
@@ -64,6 +65,8 @@ class GeocodeLibTest extends MyCakeTestCase {
 		parent::setUp();
 
 		$this->Geocode = new GeocodeLib();
+
+		$this->mockFilePath = CakePlugin::path('Tools') . 'Test' . DS . 'test_files' . DS . 'google' . DS;
 	}
 
 	public function tearDown() {
@@ -87,7 +90,11 @@ class GeocodeLibTest extends MyCakeTestCase {
 			array(48.8934, 8.70492, 'B294, 75175 Pforzheim, Deutschland')
 		);
 
-		foreach ($coords as $coord) {
+		foreach ($coords as $k => $coord) {
+			if (!$this->isDebug()) {
+				$this->_getMock('reverse' . $k);
+			}
+
 			$is = $this->Geocode->reverseGeocode($coord[0], $coord[1]);
 			$this->assertTrue($is);
 
@@ -111,6 +118,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 	public function testGeocodeInconclusive() {
 		$address = 'Bibersfeld';
 
+		if (!$this->isDebug()) {
+			$this->_getMock('inconclusive', 2);
+		}
+
 		$this->Geocode->setOptions(array('allow_inconclusive' => true, 'min_accuracy' => GeocodeLib::ACC_POSTAL));
 		$is = $this->Geocode->geocode($address);
 		$this->assertTrue($is);
@@ -139,6 +150,11 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testInvalid() {
+		// Dont mock in debug mode (live query), otherwise mock it out
+		if (!$this->isDebug()) {
+			$this->_getMock('invalid');
+		}
+
 		$this->Geocode->setOptions(array('allow_inconclusive' => false));
 		$result = $this->Geocode->geocode('204 HWY 287 SOUTH, CACTUS, TX, 79013');
 		$this->assertFalse($result);
@@ -151,6 +167,9 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 */
 	public function testGeocodeInconclusiveMinAccuracy() {
 		$address = 'Bibersfeld';
+		if (!$this->isDebug()) {
+			$this->_getMock('inconclusive');
+		}
 
 		$this->Geocode->setOptions(array('allow_inconclusive' => true, 'min_accuracy' => GeocodeLib::ACC_STREET));
 		$is = $this->Geocode->geocode($address);
@@ -168,6 +187,9 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 */
 	public function testGeocodeExpect() {
 		$address = 'Bibersfeld';
+		if (!$this->isDebug()) {
+			$this->_getMock('inconclusive');
+		}
 
 		$this->Geocode->setOptions(array(
 			'allow_inconclusive' => true,
@@ -287,6 +309,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testGeocode() {
+		if (!$this->isDebug()) {
+			$this->_getMock('geocode0');
+		}
+
 		$address = '74523 Deutschland';
 		//echo '<h2>'.$address.'</h2>';
 		$is = $this->Geocode->geocode($address);
@@ -301,6 +327,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 		//debug($is);
 		$this->assertTrue(empty($is));
 
+		if (!$this->isDebug()) {
+			$this->_getMock('geocode1');
+		}
+
 		$address = 'Leopoldstraße 100, München';
 		//echo '<h2>'.$address.'</h2>';
 		$is = $this->Geocode->geocode($address);
@@ -317,6 +347,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 		//debug($is);
 		$this->assertTrue(empty($is));
 
+		if (!$this->isDebug()) {
+			$this->_getMock('geocode2');
+		}
+
 		$address = 'Oranienburger Straße 87, 10178 Berlin, Deutschland';
 		//echo '<h2>'.$address.'</h2>';
 		$is = $this->Geocode->geocode($address);
@@ -355,6 +389,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testGeocodeBadApiKey() {
+		if (!$this->isDebug()) {
+			$this->_getMock('apikey');
+		}
+
 		$address = 'Oranienburger Straße 87, 10178 Berlin, Deutschland';
 		$result = $this->Geocode->geocode($address, array('sensor' => false, 'key' => 'testingBadApiKey'));
 		$this->assertFalse($result);
@@ -369,6 +407,10 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testGeocodeInvalid() {
+		if (!$this->isDebug()) {
+			$this->_getMock('zero');
+		}
+
 		$address = 'Hjfjosdfhosj, 78878 Mdfkufsdfk';
 		$result = $this->Geocode->geocode($address);
 		$this->assertFalse($result);
@@ -427,8 +469,13 @@ class GeocodeLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testGeocodeMinAcc() {
+		if (!$this->isDebug()) {
+			$this->_getMock('minacc');
+		}
+
 		// address = postal_code, minimum = street level
 		$address = 'Deutschland';
+
 		$this->Geocode->setOptions(array('min_accuracy' => GeocodeLib::ACC_STREET));
 		$is = $this->Geocode->geocode($address);
 		$this->assertFalse($is);
@@ -543,4 +590,18 @@ class GeocodeLibTest extends MyCakeTestCase {
 		$this->assertEquals($expected, $result);
 	}
 
+	protected function _getMock($type, $count = 1) {
+		$this->Geocode->HttpSocket = $this->getMock('HttpSocket', array('get'));
+		$responseContent = file_get_contents($this->mockFilePath . $type . '.json');
+		$response = new HttpSocketResponse();
+		$response->body = $responseContent;
+		$response->code = 200;
+		$this->Geocode->HttpSocket->response = $response;
+		for ($i = 0; $i < $count; $i++) {
+			$this->Geocode->HttpSocket->expects($this->at($i))
+				->method('get')
+				->will($this->returnValue($response));
+		}
+	}
+
 }

+ 5 - 0
Test/test_files/google/apikey.json

@@ -0,0 +1,5 @@
+{
+   "error_message" : "The provided API key is invalid.",
+   "results" : [],
+   "status" : "REQUEST_DENIED"
+}

+ 69 - 0
Test/test_files/google/geocode0.json

@@ -0,0 +1,69 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "74523",
+               "short_name" : "74523",
+               "types" : [ "postal_code" ]
+            },
+            {
+               "long_name" : "Schwäbisch Hall",
+               "short_name" : "Schwäbisch Hall",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Schwäbisch Hall",
+               "short_name" : "SHA",
+               "types" : [ "administrative_area_level_3", "political" ]
+            },
+            {
+               "long_name" : "Stuttgart",
+               "short_name" : "Süd",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "74523 Schwäbisch Hall, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 49.1670039,
+                  "lng" : 9.875680899999999
+               },
+               "southwest" : {
+                  "lat" : 49.04597,
+                  "lng" : 9.5970288
+               }
+            },
+            "location" : {
+               "lat" : 49.1257616,
+               "lng" : 9.7544127
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 49.1670039,
+                  "lng" : 9.875680899999999
+               },
+               "southwest" : {
+                  "lat" : 49.04597,
+                  "lng" : 9.5970288
+               }
+            }
+         },
+         "postcode_localities" : [ "Braunsbach", "Michelbach an der Bilz", "Schwäbisch Hall" ],
+         "types" : [ "postal_code" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 68 - 0
Test/test_files/google/geocode1.json

@@ -0,0 +1,68 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "100",
+               "short_name" : "100",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "Leopoldstraße",
+               "short_name" : "Leopoldstraße",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Schwabing-Freimann",
+               "short_name" : "Schwabing-Freimann",
+               "types" : [ "sublocality_level_1", "sublocality", "political" ]
+            },
+            {
+               "long_name" : "München",
+               "short_name" : "M",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Oberbayern",
+               "short_name" : "Oberbayern",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Bayern",
+               "short_name" : "BY",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "80802",
+               "short_name" : "80802",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Leopoldstraße 100, 80802 München, Deutschland",
+         "geometry" : {
+            "location" : {
+               "lat" : 48.16485000000001,
+               "lng" : 11.58681
+            },
+            "location_type" : "ROOFTOP",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 48.16619898029151,
+                  "lng" : 11.5881589802915
+               },
+               "southwest" : {
+                  "lat" : 48.16350101970851,
+                  "lng" : 11.5854610197085
+               }
+            }
+         },
+         "types" : [ "street_address" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 68 - 0
Test/test_files/google/geocode2.json

@@ -0,0 +1,68 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "87",
+               "short_name" : "87",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "Oranienburger Straße",
+               "short_name" : "Oranienburger Str.",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Mitte",
+               "short_name" : "Mitte",
+               "types" : [ "sublocality_level_2", "sublocality", "political" ]
+            },
+            {
+               "long_name" : "Bezirk Mitte",
+               "short_name" : "Bezirk Mitte",
+               "types" : [ "sublocality_level_1", "sublocality", "political" ]
+            },
+            {
+               "long_name" : "Berlin",
+               "short_name" : "Berlin",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Berlin",
+               "short_name" : "Berlin",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "10178",
+               "short_name" : "10178",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Oranienburger Straße 87, 10178 Berlin, Deutschland",
+         "geometry" : {
+            "location" : {
+               "lat" : 52.52332999999999,
+               "lng" : 13.40021
+            },
+            "location_type" : "ROOFTOP",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 52.5246789802915,
+                  "lng" : 13.4015589802915
+               },
+               "southwest" : {
+                  "lat" : 52.5219810197085,
+                  "lng" : 13.3988610197085
+               }
+            }
+         },
+         "types" : [ "street_address" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 121 - 0
Test/test_files/google/inconclusive.json

@@ -0,0 +1,121 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "Bibersfeld",
+               "short_name" : "Bibersfeld",
+               "types" : [ "sublocality_level_1", "sublocality", "political" ]
+            },
+            {
+               "long_name" : "Schwäbisch Hall",
+               "short_name" : "Schwäbisch Hall",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Stuttgart",
+               "short_name" : "Süd",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "74523",
+               "short_name" : "74523",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Bibersfeld, 74523 Schwäbisch Hall, Deutschland",
+         "geometry" : {
+            "location" : {
+               "lat" : 49.08035659999999,
+               "lng" : 9.6881269
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 49.0876645,
+                  "lng" : 9.7041343
+               },
+               "southwest" : {
+                  "lat" : 49.0730476,
+                  "lng" : 9.672119499999999
+               }
+            }
+         },
+         "types" : [ "sublocality_level_1", "sublocality", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Bibersfelder Besen Weinstube",
+               "short_name" : "Bibersfelder Besen Weinstube",
+               "types" : [ "point_of_interest", "establishment" ]
+            },
+            {
+               "long_name" : "1",
+               "short_name" : "1",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "Luckenbacher Straße",
+               "short_name" : "Luckenbacher Str.",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Schwäbisch Hall",
+               "short_name" : "Schwäbisch Hall",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Stuttgart",
+               "short_name" : "Süd",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "74523",
+               "short_name" : "74523",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Bibersfelder Besen Weinstube, Luckenbacher Straße 1, 74523 Schwäbisch Hall, Deutschland",
+         "geometry" : {
+            "location" : {
+               "lat" : 49.0821772,
+               "lng" : 9.68801
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 49.0835261802915,
+                  "lng" : 9.689358980291502
+               },
+               "southwest" : {
+                  "lat" : 49.0808282197085,
+                  "lng" : 9.686661019708499
+               }
+            }
+         },
+         "types" : [ "point_of_interest", "school", "establishment" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 261 - 0
Test/test_files/google/invalid.json

@@ -0,0 +1,261 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "Cactus City Hall",
+               "short_name" : "Cactus City Hall",
+               "types" : [ "point_of_interest", "establishment" ]
+            },
+            {
+               "long_name" : "201",
+               "short_name" : "201",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "U.S. 287",
+               "short_name" : "US-287",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Cactus",
+               "short_name" : "Cactus",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Moore County",
+               "short_name" : "Moore County",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Texas",
+               "short_name" : "TX",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "USA",
+               "short_name" : "US",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "79013",
+               "short_name" : "79013",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Cactus City Hall, 201 U.S. 287, Cactus, TX 79013, USA",
+         "geometry" : {
+            "location" : {
+               "lat" : 36.0499078,
+               "lng" : -102.0053272
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 36.0512567802915,
+                  "lng" : -102.0039782197085
+               },
+               "southwest" : {
+                  "lat" : 36.0485588197085,
+                  "lng" : -102.0066761802915
+               }
+            }
+         },
+         "partial_match" : true,
+         "types" : [ "point_of_interest", "establishment" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Cactus Fire Department",
+               "short_name" : "Cactus Fire Department",
+               "types" : [ "point_of_interest", "establishment" ]
+            },
+            {
+               "long_name" : "201",
+               "short_name" : "201",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "U.S. 287",
+               "short_name" : "US-287",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Cactus",
+               "short_name" : "Cactus",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Moore County",
+               "short_name" : "Moore County",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Texas",
+               "short_name" : "TX",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "USA",
+               "short_name" : "US",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "79013",
+               "short_name" : "79013",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Cactus Fire Department, 201 U.S. 287, Cactus, TX 79013, USA",
+         "geometry" : {
+            "location" : {
+               "lat" : 36.0499078,
+               "lng" : -102.0053272
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 36.0512567802915,
+                  "lng" : -102.0039782197085
+               },
+               "southwest" : {
+                  "lat" : 36.0485588197085,
+                  "lng" : -102.0066761802915
+               }
+            }
+         },
+         "partial_match" : true,
+         "types" : [ "fire_station", "point_of_interest", "establishment" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Cactus Police Department",
+               "short_name" : "Cactus Police Department",
+               "types" : [ "point_of_interest", "establishment" ]
+            },
+            {
+               "long_name" : "200",
+               "short_name" : "200",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "U.S. 287",
+               "short_name" : "US-287",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Cactus",
+               "short_name" : "Cactus",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Moore County",
+               "short_name" : "Moore County",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Texas",
+               "short_name" : "TX",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "USA",
+               "short_name" : "US",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "79013",
+               "short_name" : "79013",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Cactus Police Department, 200 U.S. 287, Cactus, TX 79013, USA",
+         "geometry" : {
+            "location" : {
+               "lat" : 36.04991,
+               "lng" : -102.0053283
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 36.05125898029149,
+                  "lng" : -102.0039793197085
+               },
+               "southwest" : {
+                  "lat" : 36.0485610197085,
+                  "lng" : -102.0066772802915
+               }
+            }
+         },
+         "partial_match" : true,
+         "types" : [ "police", "point_of_interest", "establishment" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Cactus City Shop",
+               "short_name" : "Cactus City Shop",
+               "types" : [ "point_of_interest", "establishment" ]
+            },
+            {
+               "long_name" : "201",
+               "short_name" : "201",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "U.S. 287",
+               "short_name" : "US-287",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Cactus",
+               "short_name" : "Cactus",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Moore County",
+               "short_name" : "Moore County",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Texas",
+               "short_name" : "TX",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "USA",
+               "short_name" : "US",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "79013",
+               "short_name" : "79013",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "Cactus City Shop, 201 U.S. 287, Cactus, TX 79013, USA",
+         "geometry" : {
+            "location" : {
+               "lat" : 36.0499089,
+               "lng" : -102.0053278
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 36.0512578802915,
+                  "lng" : -102.0039788197085
+               },
+               "southwest" : {
+                  "lat" : 36.0485599197085,
+                  "lng" : -102.0066767802915
+               }
+            }
+         },
+         "partial_match" : true,
+         "types" : [ "point_of_interest", "establishment" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 43 - 0
Test/test_files/google/minacc.json

@@ -0,0 +1,43 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 55.058347,
+                  "lng" : 15.0418962
+               },
+               "southwest" : {
+                  "lat" : 47.2701115,
+                  "lng" : 5.8663425
+               }
+            },
+            "location" : {
+               "lat" : 51.165691,
+               "lng" : 10.451526
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 55.058347,
+                  "lng" : 15.0418962
+               },
+               "southwest" : {
+                  "lat" : 47.2701115,
+                  "lng" : 5.8663425
+               }
+            }
+         },
+         "types" : [ "country", "political" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 245 - 0
Test/test_files/google/reverse0.json

@@ -0,0 +1,245 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "1134-1200",
+               "short_name" : "1134-1200",
+               "types" : [ "street_number" ]
+            },
+            {
+               "long_name" : "Florida",
+               "short_name" : "Florida",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Retiro",
+               "short_name" : "Retiro",
+               "types" : [ "neighborhood", "political" ]
+            },
+            {
+               "long_name" : "Buenos Aires",
+               "short_name" : "CF",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Ciudad Autónoma de Buenos Aires",
+               "short_name" : "CABA",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Argentinien",
+               "short_name" : "AR",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Florida 1134-1200, Buenos Aires, Ciudad Autónoma de Buenos Aires, Argentinien",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : -34.5936149,
+                  "lng" : -58.37387880000001
+               },
+               "southwest" : {
+                  "lat" : -34.5945235,
+                  "lng" : -58.3744494
+               }
+            },
+            "location" : {
+               "lat" : -34.5944581,
+               "lng" : -58.3744291
+            },
+            "location_type" : "RANGE_INTERPOLATED",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : -34.5927202197085,
+                  "lng" : -58.37281511970851
+               },
+               "southwest" : {
+                  "lat" : -34.5954181802915,
+                  "lng" : -58.37551308029151
+               }
+            }
+         },
+         "types" : [ "street_address" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Retiro",
+               "short_name" : "Retiro",
+               "types" : [ "neighborhood", "political" ]
+            },
+            {
+               "long_name" : "Buenos Aires",
+               "short_name" : "CF",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Autonomen Stadt Buenos Aires",
+               "short_name" : "CABA",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Argentinien",
+               "short_name" : "AR",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Retiro, Buenos Aires, Autonomen Stadt Buenos Aires, Argentinien",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : -34.5795029,
+                  "lng" : -58.365667
+               },
+               "southwest" : {
+                  "lat" : -34.5992928,
+                  "lng" : -58.38790969999999
+               }
+            },
+            "location" : {
+               "lat" : -34.594722,
+               "lng" : -58.37583300000001
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : -34.5795029,
+                  "lng" : -58.365667
+               },
+               "southwest" : {
+                  "lat" : -34.5992928,
+                  "lng" : -58.38790969999999
+               }
+            }
+         },
+         "types" : [ "neighborhood", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Autonomen Stadt Buenos Aires",
+               "short_name" : "CABA",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Argentinien",
+               "short_name" : "AR",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Autonomen Stadt Buenos Aires, Argentinien",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : -34.5316663,
+                  "lng" : -58.3360216
+               },
+               "southwest" : {
+                  "lat" : -34.709049,
+                  "lng" : -58.53126899999999
+               }
+            },
+            "location" : {
+               "lat" : -34.6143048,
+               "lng" : -58.4401655
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : -34.5316663,
+                  "lng" : -58.3360216
+               },
+               "southwest" : {
+                  "lat" : -34.709049,
+                  "lng" : -58.53126899999999
+               }
+            }
+         },
+         "types" : [ "administrative_area_level_1", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Buenos Aires",
+               "short_name" : "CF",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Argentinien",
+               "short_name" : "AR",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Buenos Aires, Argentinien",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : -34.5265464,
+                  "lng" : -58.33514479999999
+               },
+               "southwest" : {
+                  "lat" : -34.7051589,
+                  "lng" : -58.5314522
+               }
+            },
+            "location" : {
+               "lat" : -34.6036844,
+               "lng" : -58.3815591
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : -34.5265464,
+                  "lng" : -58.33514479999999
+               },
+               "southwest" : {
+                  "lat" : -34.7051589,
+                  "lng" : -58.5314522
+               }
+            }
+         },
+         "types" : [ "locality", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Argentinien",
+               "short_name" : "AR",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Argentinien",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : -21.7808136,
+                  "lng" : -53.637481
+               },
+               "southwest" : {
+                  "lat" : -55.0577146,
+                  "lng" : -73.56036019999999
+               }
+            },
+            "location" : {
+               "lat" : -38.416097,
+               "lng" : -63.61667199999999
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : -21.7808136,
+                  "lng" : -53.637481
+               },
+               "southwest" : {
+                  "lat" : -55.0577146,
+                  "lng" : -73.56036019999999
+               }
+            }
+         },
+         "types" : [ "country", "political" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 303 - 0
Test/test_files/google/reverse1.json

@@ -0,0 +1,303 @@
+{
+   "results" : [
+      {
+         "address_components" : [
+            {
+               "long_name" : "B294",
+               "short_name" : "B294",
+               "types" : [ "route" ]
+            },
+            {
+               "long_name" : "Pforzheim",
+               "short_name" : "Pforzheim",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Karlsruhe",
+               "short_name" : "KA",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            },
+            {
+               "long_name" : "75175",
+               "short_name" : "75175",
+               "types" : [ "postal_code" ]
+            }
+         ],
+         "formatted_address" : "B294, 75175 Pforzheim, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 48.8933797,
+                  "lng" : 8.7060979
+               },
+               "southwest" : {
+                  "lat" : 48.8933129,
+                  "lng" : 8.7047872
+               }
+            },
+            "location" : {
+               "lat" : 48.8933602,
+               "lng" : 8.705446
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 48.8946952802915,
+                  "lng" : 8.706791530291502
+               },
+               "southwest" : {
+                  "lat" : 48.8919973197085,
+                  "lng" : 8.704093569708498
+               }
+            }
+         },
+         "types" : [ "route" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "75175",
+               "short_name" : "75175",
+               "types" : [ "postal_code" ]
+            },
+            {
+               "long_name" : "Pforzheim",
+               "short_name" : "Pforzheim",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Karlsruhe",
+               "short_name" : "KA",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "75175 Pforzheim, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 48.90549790000001,
+                  "lng" : 8.750241899999999
+               },
+               "southwest" : {
+                  "lat" : 48.864719,
+                  "lng" : 8.697930899999999
+               }
+            },
+            "location" : {
+               "lat" : 48.88593849999999,
+               "lng" : 8.7208104
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 48.90549790000001,
+                  "lng" : 8.750241899999999
+               },
+               "southwest" : {
+                  "lat" : 48.864719,
+                  "lng" : 8.697930899999999
+               }
+            }
+         },
+         "types" : [ "postal_code" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Pforzheim",
+               "short_name" : "Pforzheim",
+               "types" : [ "locality", "political" ]
+            },
+            {
+               "long_name" : "Karlsruhe",
+               "short_name" : "KA",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Pforzheim, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 48.9297027,
+                  "lng" : 8.808734899999999
+               },
+               "southwest" : {
+                  "lat" : 48.819013,
+                  "lng" : 8.6247957
+               }
+            },
+            "location" : {
+               "lat" : 48.8921862,
+               "lng" : 8.6946286
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 48.9297027,
+                  "lng" : 8.808734899999999
+               },
+               "southwest" : {
+                  "lat" : 48.819013,
+                  "lng" : 8.6247957
+               }
+            }
+         },
+         "types" : [ "locality", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Karlsruhe",
+               "short_name" : "KA",
+               "types" : [ "administrative_area_level_2", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Karlsruhe, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 49.663763,
+                  "lng" : 9.603785499999999
+               },
+               "southwest" : {
+                  "lat" : 48.3005128,
+                  "lng" : 7.959448499999999
+               }
+            },
+            "location" : {
+               "lat" : 48.9540631,
+               "lng" : 8.725925699999999
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 49.663763,
+                  "lng" : 9.603785499999999
+               },
+               "southwest" : {
+                  "lat" : 48.3005128,
+                  "lng" : 7.959448499999999
+               }
+            }
+         },
+         "types" : [ "administrative_area_level_2", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Baden-Württemberg",
+               "short_name" : "BW",
+               "types" : [ "administrative_area_level_1", "political" ]
+            },
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Baden-Württemberg, Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 49.7913278,
+                  "lng" : 10.495573
+               },
+               "southwest" : {
+                  "lat" : 47.5323664,
+                  "lng" : 7.511756799999999
+               }
+            },
+            "location" : {
+               "lat" : 48.6616037,
+               "lng" : 9.350133599999999
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 49.7913278,
+                  "lng" : 10.495573
+               },
+               "southwest" : {
+                  "lat" : 47.5323664,
+                  "lng" : 7.511756799999999
+               }
+            }
+         },
+         "types" : [ "administrative_area_level_1", "political" ]
+      },
+      {
+         "address_components" : [
+            {
+               "long_name" : "Deutschland",
+               "short_name" : "DE",
+               "types" : [ "country", "political" ]
+            }
+         ],
+         "formatted_address" : "Deutschland",
+         "geometry" : {
+            "bounds" : {
+               "northeast" : {
+                  "lat" : 55.058347,
+                  "lng" : 15.0418962
+               },
+               "southwest" : {
+                  "lat" : 47.2701115,
+                  "lng" : 5.8663425
+               }
+            },
+            "location" : {
+               "lat" : 51.165691,
+               "lng" : 10.451526
+            },
+            "location_type" : "APPROXIMATE",
+            "viewport" : {
+               "northeast" : {
+                  "lat" : 55.058347,
+                  "lng" : 15.0418962
+               },
+               "southwest" : {
+                  "lat" : 47.2701115,
+                  "lng" : 5.8663425
+               }
+            }
+         },
+         "types" : [ "country", "political" ]
+      }
+   ],
+   "status" : "OK"
+}

+ 4 - 0
Test/test_files/google/zero.json

@@ -0,0 +1,4 @@
+{
+   "results" : [],
+   "status" : "ZERO_RESULTS"
+}

+ 14 - 2
TestSuite/MyCakeTestCase.php

@@ -29,7 +29,7 @@ abstract class MyCakeTestCase extends CakeTestCase {
 	 * @param bool $showHtml
 	 * @return void
 	 */
-	public static function debug($data, $force = false, $showHtml = null) {
+	protected static function debug($data, $force = false, $showHtml = null) {
 		if (!empty($_GET['debug']) || !empty($_SERVER['argv']) && (in_array('-v', $_SERVER['argv'], true) || in_array('-vv', $_SERVER['argv'], true))) {
 			if ($showHtml === null && php_sapi_name() === 'cli') {
 				$showHtml = true;
@@ -55,7 +55,7 @@ abstract class MyCakeTestCase extends CakeTestCase {
 	 * @param bool $force Should the output be flushed (forced)
 	 * @return void
 	 */
-	public static function out($data, $plain = false, $force = false) {
+	protected static function out($data, $plain = false, $force = false) {
 		if (php_sapi_name() === 'cli') {
 			return;
 		}
@@ -70,6 +70,18 @@ abstract class MyCakeTestCase extends CakeTestCase {
 		ob_flush();
 	}
 
+	/**
+	 * MyCakeTestCase::isDebug()
+	 *
+	 * @return bool Success
+	 */
+	protected static function isDebug() {
+		if (!empty($_GET['debug']) || !empty($_SERVER['argv']) && in_array('--debug', $_SERVER['argv'], true)) {
+			return true;
+		}
+		return false;
+	}
+
 	protected function _basePath($full = false) {
 		$phpSelf = $_SERVER['PHP_SELF'];
 		if (strpos($phpSelf, 'webroot/test.php') !== false) {