| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- App::uses('GeocoderBehavior', 'Tools.Model/Behavior');
- App::uses('Set', 'Utility');
- //App::uses('Model', 'Model');
- App::uses('AppModel', 'Model');
- class GeocoderBehaviorTest extends CakeTestCase {
- public $fixtures = array(
- 'core.comment'
- );
- public function startTest() {
- $this->Comment = ClassRegistry::init('Comment');
- $this->Comment->Behaviors->attach('Tools.Geocoder', array('real'=>false));
- }
- public function testBasic() {
- echo '<h3>'.__FUNCTION__.'</h3>';
-
- $data = array(
- 'street' => 'Krebenweg 22',
- 'zip' => '74523',
- 'city' => 'Bibersfeld'
- );
- $res = $this->Comment->save($data);
- debug($res);
- $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']) && round($res['Comment']['lat']) === 49.0 && round($res['Comment']['lng']) === 10.0);
- // accuracy = 4
-
-
- # inconclusive
- $data = array(
- //'street' => 'Leopoldstraße',
- 'city' => 'München'
- );
- $res = $this->Comment->save($data);
- $this->assertEquals('', $this->Comment->Behaviors->Geocoder->Geocode->error());
- debug($res);
- $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
- $this->assertEquals('München, Deutschland', $res['Comment']['geocoder_result']['formatted_address']);
-
- $data = array(
- 'city' => 'Bibersfeld'
- );
- $res = $this->Comment->save($data);
- debug($res);
- $this->assertTrue(!empty($res));
- $this->assertEquals('', $this->Comment->Behaviors->Geocoder->Geocode->error());
- }
- public function testMinAccLow() {
- echo '<h3>'.__FUNCTION__.'</h3>';
-
- $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);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($res);
- //debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
- }
- public function testMinAccHigh() {
- echo '<h3>'.__FUNCTION__.'</h3>';
-
- $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);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($res);
- //debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
- }
- public function testMinInc() {
- echo '<h3>'.__FUNCTION__.'</h3>';
-
- $this->Comment->Behaviors->detach('Geocoder');
- $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>GeocodeLib::ACC_SUBLOC));
-
- $this->assertEquals(GeocodeLib::ACC_SUBLOC, $this->Comment->Behaviors->Geocoder->settings['Comment']['min_accuracy']);
-
- // accuracy = 1
- $data = array(
- //'street' => 'Leopoldstraße',
- 'city' => 'Neustadt'
- );
- $res = $this->Comment->save($data);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
- debug($res);
- //debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
- }
- public function testMinIncAllowed() {
- echo '<h3>'.__FUNCTION__.'</h3>';
-
- $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);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($this->Comment->Behaviors->Geocoder->Geocode->url()).BR;
- debug($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
- debug($res);
- //debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
- }
- public function testExpect() {
- $this->Comment->Behaviors->detach('Geocoder');
- $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'expect'=>array('postal_code')));
- // accuracy = 1
- $data = array(
- //'street' => 'Leopoldstraße',
- 'city' => 'Bibersfeld'
- );
- $res = $this->Comment->save($data);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($res);
- debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(empty($res['Comment']['lat']) && empty($res['Comment']['lng']));
- $data = array(
- //'street' => 'Leopoldstraße',
- 'city' => '74523'
- );
- $res = $this->Comment->save($data);
- debug($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
- debug($res);
- //debug($this->Comment->Behaviors->Geocoder->Geocode->debug());
- $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
- }
- }
|