| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?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']));
- }
- }
|