Browse Source

geocode lib

dereuromark 16 years ago
parent
commit
7524f28f0d

+ 3 - 0
README

@@ -4,5 +4,8 @@ NOT YET READY TO USE FOR GENERAL PURPOSES
 Just started to convert to plugin - a lot of corrections neccessary!
 
 
+POSSIBLE DEPENDENCIES
+- http://www.dereuromark.de/2010/06/22/cakephp-bootstrap-goodies/
+
 CODING STANDARDS
 - http://www.dereuromark.de/coding-standards/

File diff suppressed because it is too large
+ 912 - 0
libs/geocode_lib.php


+ 153 - 0
libs/http_socket_lib.php

@@ -0,0 +1,153 @@
+<?php
+
+/**
+ * wrapper for curl,
+ */
+class HttpSocketLib {
+
+	// First tries with curl, then cake, then php
+	var $use = array('curl' => true, 'cake'=> true, 'php' => true);
+	var $debug = null;
+
+	function __construct($use = array()) {
+		if (is_array($use)) {
+			foreach ($use as $key => $value) {
+				if (array_key_exists($key, $this->use)) {
+					$this->use[$key] = $value;
+				}
+			}
+		} elseif (array_key_exists($use, $this->use)) {
+			$this->use[$use] = true;
+			if ($use == 'cake') {
+				$this->use['curl'] = false;
+			} elseif ($use == 'php') {
+				$this->use['curl'] = $this->use['cake'] = false;
+			}
+		}
+	}
+
+	function setError($error) {
+		if (empty($error)) {
+			return;
+		}
+		$this->error[] = $error;
+	}
+
+	function error($asString = true, $separator = ', ') {
+		return implode(', ', $this->error);
+	}
+
+
+	/**
+	 * fetches url with curl if available
+	 * fallbacks: cake and php
+	 * note: expects url with json encoded content
+	 * @access private
+	 **/
+	public function fetch($url, $agent = 'cakephp http socket lib') {
+		if ($this->use['curl'] && function_exists('curl_init')) {
+			$this->debug = 'curl';
+
+			$ch = curl_init();
+			curl_setopt($ch, CURLOPT_URL, $url);
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+			curl_setopt($ch, CURLOPT_USERAGENT, $agent);
+			$response = curl_exec($ch);
+			$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+			curl_close ($ch);
+			if ($status != '200') {
+				$this->setError('Error '.$status);
+				return false;
+			}
+			return $response;
+
+		} elseif($this->use['cake'] && App::import('Core', 'HttpSocket')) {
+			$this->debug = 'cake';
+
+			$HttpSocket = new HttpSocket(array('timeout' => 5));
+			$response = $HttpSocket->get($url);
+			if (empty($response)) { //TODO: status 200?
+				return false;
+			}
+			return $response;
+
+		} elseif($this->use['php'] || true) {
+			$this->debug = 'php';
+
+			$response = file_get_contents($url, 'r');
+			//TODO: status 200?
+			if (empty($response)) {
+				return false;
+			}
+			return $response;
+		}
+	}
+
+
+}
+
+/*
+
+Array
+(
+    [name] => 74523 Deutschland
+    [Status] => Array
+        (
+            [code] => 200
+            [request] => geocode
+        )
+
+    [Placemark] => Array
+        (
+            [id] => p1
+            [address] => 74523, Deutschland
+            [AddressDetails] => Array
+                (
+                    [Accuracy] => 5
+                    [xmlns] => urn:oasis:names:tc:ciq:xsdschema:xAL:2.0
+                    [Country] => Array
+                        (
+                            [CountryNameCode] => DE
+                            [CountryName] => Deutschland
+                            [AdministrativeArea] => Array
+                                (
+                                    [AdministrativeAreaName] => Baden-Württemberg
+                                    [SubAdministrativeArea] => Array
+                                        (
+                                            [SubAdministrativeAreaName] => Schwäbisch Hall
+                                            [PostalCode] => Array
+                                                (
+                                                    [PostalCodeNumber] => 74523
+                                                )
+
+                                        )
+
+                                )
+
+                        )
+
+                )
+
+            [ExtendedData] => Array
+                (
+                    [LatLonBox] => Array
+                        (
+                            [north] => 49.1670260
+                            [south] => 49.0451477
+                            [east] => 9.8756350
+                            [west] => 9.6132550
+                        )
+
+                )
+
+            [Point] => Array
+                (
+                    [coordinates] => 9.7544127,49.1257616,0
+                )
+
+        )
+
+)
+
+*/
+?>

+ 168 - 0
models/behaviors/geocoder.php

@@ -0,0 +1,168 @@
+<?php
+
+class GeocoderBehavior extends ModelBehavior {
+	/**
+	 * Contain settings indexed by model name.
+	 *
+	 * @var array
+	 * @access private
+	 */
+	var $__settings = array();
+
+	var $log = true; // log successfull results to geocode.log (errors will be logged to error.log in either case)
+
+/*
+accuracy:
+0 	Unbekannter Ort. (Seit 2.59)
+1 	Land. (Seit 2.59)
+2 	Bundesland/Bundesstaat, Provinz, Präfektur usw. (Seit 2.59)
+3 	Bezirk, Gemeinde usw. (Seit 2.59)
+4 	Ortschaft (Stadt, Dorf). (Seit 2.59)
+5 	Postleitzahl (PLZ). (Seit 2.59)
+6 	Straße. (Seit 2.59)
+7 	Kreuzung. (Seit 2.59)
+8 	Adresse. (Seit 2.59)
+*/
+	/**
+	 * Initiate behavior for the model using specified settings. Available settings:
+	 *
+	 * - label: 	(array | string, optional) set to the field name that contains the
+	 * 				string from where to generate the slug, or a set of field names to
+	 * 				concatenate for generating the slug. DEFAULTS TO: title
+	 *
+	 * - real:		(boolean, optional) if set to true then field names defined in
+	 * 				label must exist in the database table. DEFAULTS TO: true
+	 *
+	 * - accuracy: see above
+	 *
+	 * @param object $Model Model using the behaviour
+	 * @param array $settings Settings to override for model.
+	 * @access public
+	 */
+	function setup(&$Model, $settings = array()) {
+		$default = array('real' => true, 'address' => array('street','zip','city'), 'lat'=>'lat','lng'=>'lng','formatted_address' => null, 'min_accuracy' => 4, 'allow_inconclusive' => false, 'host' => 'us', 'language' => 'de', 'region'=> '', 'bounds' => '', 'overwrite' => false);
+
+		if (!isset($this->__settings[$Model->alias])) {
+			$this->__settings[$Model->alias] = $default;
+		}
+
+		$this->__settings[$Model->alias] = array_merge($this->__settings[$Model->alias], ife(is_array($settings), $settings, array()));
+	}
+
+	/**
+	 * Run before a model is saved, used to set up slug for model.
+	 *
+	 * @param object $Model Model about to be saved.
+	 * @return boolean true if save should proceed, false otherwise
+	 * @access public
+	 */
+	function beforeSave(&$Model) {
+		$return = parent::beforeSave($Model);
+
+		// Make address fields an array
+
+		if (!is_array($this->__settings[$Model->alias]['address'])) {
+			$addressfields = array($this->__settings[$Model->alias]['address']);
+		} else {
+			$addressfields = $this->__settings[$Model->alias]['address'];
+		}
+		$addressfields = array_unique($addressfields);
+
+		// Make sure all address fields are available
+
+		if ($this->__settings[$Model->alias]['real']) {
+			foreach($addressfields as $field) {
+				if (!$Model->hasField($field)) {
+					return $return;
+				}
+			}
+		}
+
+		$adressdata = array();
+		foreach($addressfields as $field) {
+			if (!empty($Model->data[$Model->alias][$field])) {
+					$adressdata[] = ife(!empty($label), ' ', '') . $Model->data[$Model->alias][$field];
+			}
+		}
+
+		// See if we should request a geocode
+		if ((!$this->__settings[$Model->alias]['real'] || ($Model->hasField($this->__settings[$Model->alias]['lat']) && $Model->hasField($this->__settings[$Model->alias]['lng']))) && ($this->__settings[$Model->alias]['overwrite'] || (empty($Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']]) || ($Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']]==0 && $Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']]==0)))) {
+			$geocode = $this->__geocode($adressdata, $this->__settings[$Model->alias]);
+			// Now set the geocode as part of the model data to be saved, making sure that
+			// we are on the white list of fields to be saved
+			//pr ($Model->whitelist); die();
+			if (!empty($Model->whitelist) && (!in_array($this->__settings[$Model->alias]['lat'], $Model->whitelist) || !in_array($this->__settings[$Model->alias]['lng'], $Model->whitelist))) {
+				/** HACK to prevent 0 inserts if not wanted! just use whitelist now to narrow fields down - 2009-03-18 ms */
+				//$Model->whitelist[] = $this->__settings[$Model->alias]['lat'];
+				//$Model->whitelist[] = $this->__settings[$Model->alias]['lng'];
+				return $return;
+			}
+
+			# if both are 0, thats not valid, otherwise continue
+			if (!empty($geocode['lat']) || !empty($geocode['lng'])) { /** HACK to prevent 0 inserts of incorrect runs - 2009-04-07 ms */
+				$Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']] = $geocode['lat'];
+				$Model->data[$Model->alias][$this->__settings[$Model->alias]['lng']] = $geocode['lng'];
+			} else {
+				if (isset($Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']])) {
+					unset($Model->data[$Model->alias][$this->__settings[$Model->alias]['lat']]);
+				}
+				if (isset($Model->data[$Model->alias][$this->__settings[$Model->alias]['lng']])) {
+					unset($Model->data[$Model->alias][$this->__settings[$Model->alias]['lng']]);
+				}
+			}
+
+			if(!empty($this->__settings[$Model->alias]['formatted_address'])){
+				$Model->data[$Model->alias][$this->__settings[$Model->alias]['formatted_address']] = $geocode['formatted_address'];
+			} else {
+				if (isset($Model->data[$Model->alias][$this->__settings[$Model->alias]['formatted_address']])) {
+					unset($Model->data[$Model->alias][$this->__settings[$Model->alias]['formatted_address']]);
+				}
+			}
+
+			if (!empty($geocode['inconclusive'])) {
+				$Model->data[$Model->alias]['inconclusive'] = $geocode['inconclusive'];
+				$Model->data[$Model->alias]['results'] = $geocode['results'];
+			}
+
+			# correct country id if neccessary
+			if (in_array('country_name', $this->__settings[$Model->alias]['address'])) {
+
+				if (!empty($geocode['country']) && in_array($geocode['country'], ($countries = Country::addressList()))) {
+					$countries = array_shift(array_keys($countries, $geocode['country']));
+					$Model->data[$Model->alias]['country'] = $countries;
+				} else {
+					$Model->data[$Model->alias]['country'] = 0;
+				}
+			}
+		}
+		return $return;
+	}
+
+
+	function __geocode($addressfields, $options = array()) {
+
+		$address = implode(' ', $addressfields);
+		App::import('Lib', 'Tools.GeocodeLib');
+
+		$this->Geocode = new GeocodeLib(array('min_accuracy'=>$options['min_accuracy'], 'allow_inconclusive'=>$options['allow_inconclusive'], 'host'=>$options['host']));
+
+		$settings = array('language'=>$options['language']);
+		if (!$this->Geocode->geocode($address, $settings)) {
+			return array('lat'=>0,'lng'=>0,'official_address'=>'');
+		}
+
+		$res = $this->Geocode->getResult();
+
+		if (isset($res[0])) {
+			$res = $res[0];
+
+		}
+         //TODO: rename to formatted_address
+		# hack
+		$res['official_address'] = $res['formatted_address'];
+
+		return $res;
+	}
+
+}
+?>

+ 125 - 0
tests/cases/behaviors/geocoder.test.php

@@ -0,0 +1,125 @@
+<?php
+
+App::import('Behavior', 'Tools.Geocoder');
+
+class GeocoderTestCase extends CakeTestCase {
+
+	var $fixtures = array(
+		'core.comment'
+	);
+
+
+	function startTest() {
+		$this->Comment =& ClassRegistry::init('Comment');
+
+
+		$this->Comment->Behaviors->attach('Geocoder', array('real'=>false));
+	}
+
+	function testBasic() {
+		// accuracy >= 5
+		$data = array(
+			'street' => 'Krebenweg 2',
+			'zip' => '74523',
+			'city' => 'Bibersfeld'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($res);
+		$this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
+		// accuracy = 4
+		$data = array(
+	 		//'street' => 'Leopoldstraße',
+			'city' => 'München'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
+
+		echo returns($res);
+		$this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
+
+	}
+
+	function testMinAccLow() {
+		$this->Comment->Behaviors->detach('Geocoder');
+		$this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>0));
+		// accuracy = 1
+		$data = array(
+	 		//'street' => 'Leopoldstraße',
+			'city' => 'Deutschland'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
+
+		echo returns($res);
+
+		//echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
+		$this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
+
+	}
+
+	function testMinAccHigh() {
+		$this->Comment->Behaviors->detach('Geocoder');
+		$this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>4));
+		// accuracy = 1
+		$data = array(
+	 		//'street' => 'Leopoldstraße',
+			'city' => 'Deutschland'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
+
+		echo returns($res);
+
+		//echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
+		$this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
+
+	}
+
+
+	function testMinInc() {
+		$this->Comment->Behaviors->detach('Geocoder');
+		$this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>4));
+		// accuracy = 1
+		$data = array(
+	 		//'street' => 'Leopoldstraße',
+			'city' => 'Neustadt'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
+
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
+
+		echo returns($res);
+
+		//echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
+		$this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
+
+	}
+
+	function testMinIncAllowed() {
+		$this->Comment->Behaviors->detach('Geocoder');
+		$this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'allow_inconclusive'=>true));
+		// accuracy = 1
+		$data = array(
+	 		//'street' => 'Leopoldstraße',
+			'city' => 'Neustadt'
+		);
+		$res = $this->Comment->save($data);
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
+
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->url()).BR;
+
+		echo returns($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
+
+		echo returns($res);
+
+		//echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
+		$this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
+
+	}
+
+
+}
+
+
+

+ 244 - 0
tests/cases/libs/geocode_lib.test.php

@@ -0,0 +1,244 @@
+<?php
+
+App::import('Lib', 'Tools.GeocodeLib');
+
+# google maps
+Configure::write('Google', array(
+	'key' => 'ABQIAAAAk-aSeht5vBRyVc9CjdBKLRRnhS8GMCOqu88EXp1O-QqtMSdzHhQM4y1gkHFQdUvwiZgZ6jaKlW40kw',	//local
+	'api' => '2.x',
+	'zoom' => 16,
+	'lat' => null,
+	'lng' => null,
+	'type' => 'G_NORMAL_MAP'
+));
+
+class GeocodeLibTestCase extends CakeTestCase {
+
+	function setUp() {
+		$this->GeocodeLib = new GeocodeLib();
+		$this->assertTrue(is_object($this->GeocodeLib));
+	}
+
+	function TearDown() {
+		unset($this->GeocodeLib);
+	}
+
+
+	function testDistance() {
+		$coords = array(
+			array('name'=>'MUC/Pforzheim (269km road, 2:33h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>48.8934, 'lng'=>8.70492), 'd'=>228),
+			array('name'=>'MUC/London (1142km road, 11:20h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>51.508, 'lng'=>-0.124688), 'd'=>919),
+			array('name'=>'MUC/NewYork (--- road, ---h)', 'x'=>array('lat'=>48.1391, 'lng'=>11.5802), 'y'=>array('lat'=>40.700943, 'lng'=>-73.853531), 'd'=>6479)
+		);
+
+		foreach ($coords as $coord) {
+			$is = $this->GeocodeLib->distance($coord['x'], $coord['y']);
+			echo $coord['name'].':';
+			pr('is: '.$is.' - expected: '.$coord['d']);
+			$this->assertEqual($coord['d'], $is);
+		}
+
+	}
+
+	function testConvert() {
+		$values = array(
+			array(3, 'M', 'K', 4.828032),
+			array(3, 'K', 'M', 1.86411358),
+			array(100000, 'I', 'K', 2.54),
+		);
+		foreach ($values as $value) {
+			$is = $this->GeocodeLib->convert($value[0], $value[1], $value[2]);
+			echo $value[0].$value[1].' in '.$value[2].':';
+			pr('is: '.returns($is).' - expected: '.$value[3]);
+			$this->assertEqual($value[3], round($is, 8));
+		}
+	}
+
+
+	function testUrl() {
+		$is = $this->GeocodeLib->url();
+		pr($is);
+		$this->assertTrue(!empty($is) &&  startsWith($is, 'http://maps.google.com/maps/api/geocode/xml?'));
+	}
+
+
+	function testFetch() {
+		$url = 'http://maps.google.com/maps/api/geocode/xml?sensor=false&address=74523';
+		$is = $this->GeocodeLib->_fetch($url);
+		//echo returns($is);
+
+		$this->assertTrue(!empty($is) && substr($is, 0, 38) == '<?xml version="1.0" encoding="UTF-8"?>');
+
+		$url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=74523';
+		$is = $this->GeocodeLib->_fetch($url);
+		//echo returns($is);
+		$this->assertTrue(!empty($is) && substr($is, 0, 1) == '{');
+
+	}
+
+	function testSetParams() {
+
+	}
+
+
+	function testSetOptions() {
+		$this->GeocodeLib->setOptions(array('host'=>'xx'));
+		# should remain ".com"
+		$res = $this->GeocodeLib->url();
+		pr($res);
+
+		$this->GeocodeLib->setOptions(array('host'=>'de'));
+		# should now be ".de"
+		$res = $this->GeocodeLib->url();
+		pr($res);
+
+		# now DE
+
+	}
+
+
+	function testGeocode() {
+		$address = '74523 Deutschland';
+		echo '<h3>'.$address.'</h3>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+
+		$address = 'Leopoldstraße 100, München';
+		echo '<h3>'.$address.'</h3>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+
+		$address = 'Oranienburger Straße 87, 10178 Berlin, Deutschland';
+		echo '<h3>'.$address.'</h3>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertTrue($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->getResult();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(empty($is));
+
+	}
+
+	function testGeocodeInvalid() {
+		$address = 'Hjfjosdfhosj, 78878 Mdfkufsdfk';
+		echo '<h3>'.$address.'</h3>';
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		pr($this->GeocodeLib->debug());
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+	}
+
+
+	function testGeocodeMinAcc() {
+		$address = 'Deutschland';
+		echo '<h3>'.$address.'</h3>';
+		$this->GeocodeLib->setOptions(array('min_accuracy'=>3));
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+	}
+
+
+	function testGeocodeInconclusive() {
+		// seems like there is no inconclusive result anymore!!!
+
+
+		$address = 'Neustadt';
+		echo '<h3>'.$address.'</h3>';
+
+		# allow_inconclusive = TRUE
+		$this->GeocodeLib->setOptions(array('allow_inconclusive'=>true));
+		$is = $this->GeocodeLib->geocode($address);
+		echo 'debug:';
+		pr($this->GeocodeLib->debug());
+		echo 'debug end';
+		$this->assertTrue($is);
+
+		$res = $this->GeocodeLib->getResult();
+		pr($res);
+		$this->assertTrue(count($res) === 10);
+
+		$is = $this->GeocodeLib->isInconclusive();
+		$this->assertTrue($is);
+
+
+		# allow_inconclusive = FALSE
+		$this->GeocodeLib->setOptions(array('allow_inconclusive'=>false));
+		$is = $this->GeocodeLib->geocode($address);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		$is = $this->GeocodeLib->error();
+		echo returns($is);
+		$this->assertTrue(!empty($is));
+
+	}
+
+
+	function testReverseGeocode() {
+		$coords = array(
+			array(-34.594445, -58.37446, 'Florida 1134-1200, Buenos Aires, Capital Federal, Argentinien'),
+			array(48.8934, 8.70492, 'Bahnhofplatz 1, 75175 Pforzheim, Deutschland')
+		);
+
+		foreach ($coords as $coord) {
+			$is = $this->GeocodeLib->reverseGeocode($coord[0], $coord[1]);
+			echo returns($is);
+			$this->assertTrue($is);
+
+			$is = $this->GeocodeLib->getResult();
+			$this->assertTrue(!empty($is));
+			echo returns($is);
+			$address = isset($is[0]) ? $is[0]['formatted_address'] : $is['formatted_address'];
+			$this->assertEqual($coord[2], $address);
+		}
+
+	}
+
+
+
+
+	function testGetResult() {
+
+	}
+
+}
+?>

+ 66 - 0
tests/cases/libs/http_socket_lib.test.php

@@ -0,0 +1,66 @@
+<?php
+
+App::import('Lib', 'Tools.HttpSocketLib');
+
+class HttpSocketLibTestCase extends CakeTestCase {
+
+	function setUp() {
+		$this->HttpSocketLib = new HttpSocketLib();
+		$this->assertTrue(is_object($this->HttpSocketLib));
+	}
+
+	function TearDown() {
+		unset($this->HttpSocketLib);
+	}
+
+	function testFetch() {
+
+		$url = 'http://maps.google.de';
+		$is = $this->HttpSocketLib->fetch($url);
+		//echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$url = 'http://sscfmaps.sfdgoogle.eede';
+		$is = $this->HttpSocketLib->fetch($url);
+		echo returns($is);
+		$this->assertFalse($is);
+
+		$error = $this->HttpSocketLib->error();
+		echo returns($error);
+		$this->assertTrue(!empty($error));
+
+		$this->assertEqual($this->HttpSocketLib->debug, 'curl');
+
+	}
+
+
+	function testFetchPhp() {
+		$this->HttpSocketLib = new HttpSocketLib('php');
+
+		$url = 'http://maps.google.ch';
+		$is = $this->HttpSocketLib->fetch($url);
+		//echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$this->assertEqual($this->HttpSocketLib->debug, 'php');
+
+	}
+
+
+	function testFetchCake() {
+		$this->HttpSocketLib = new HttpSocketLib('cake');
+
+		$url = 'http://maps.google.at';
+		$is = $this->HttpSocketLib->fetch($url);
+		//echo returns($is);
+		$this->assertTrue(!empty($is));
+
+		$this->assertEqual($this->HttpSocketLib->debug, 'cake');
+	}
+
+
+
+
+
+}
+?>