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