geocoder.test.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. App::import('Behavior', 'Tools.Geocoder');
  3. class GeocoderTestCase extends CakeTestCase {
  4. var $fixtures = array(
  5. 'core.comment'
  6. );
  7. function startTest() {
  8. $this->Comment =& ClassRegistry::init('Comment');
  9. $this->Comment->Behaviors->attach('Geocoder', array('real'=>false));
  10. }
  11. function testBasic() {
  12. // accuracy >= 5
  13. $data = array(
  14. 'street' => 'Krebenweg 2',
  15. 'zip' => '74523',
  16. 'city' => 'Bibersfeld'
  17. );
  18. $res = $this->Comment->save($data);
  19. echo returns($res);
  20. $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
  21. // accuracy = 4
  22. $data = array(
  23. //'street' => 'Leopoldstraße',
  24. 'city' => 'München'
  25. );
  26. $res = $this->Comment->save($data);
  27. echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
  28. echo returns($res);
  29. $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
  30. }
  31. function testMinAccLow() {
  32. $this->Comment->Behaviors->detach('Geocoder');
  33. $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>0));
  34. // accuracy = 1
  35. $data = array(
  36. //'street' => 'Leopoldstraße',
  37. 'city' => 'Deutschland'
  38. );
  39. $res = $this->Comment->save($data);
  40. echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
  41. echo returns($res);
  42. //echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
  43. $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
  44. }
  45. function testMinAccHigh() {
  46. $this->Comment->Behaviors->detach('Geocoder');
  47. $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>4));
  48. // accuracy = 1
  49. $data = array(
  50. //'street' => 'Leopoldstraße',
  51. 'city' => 'Deutschland'
  52. );
  53. $res = $this->Comment->save($data);
  54. echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
  55. echo returns($res);
  56. //echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
  57. $this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
  58. }
  59. function testMinInc() {
  60. $this->Comment->Behaviors->detach('Geocoder');
  61. $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'min_accuracy'=>4));
  62. // accuracy = 1
  63. $data = array(
  64. //'street' => 'Leopoldstraße',
  65. 'city' => 'Neustadt'
  66. );
  67. $res = $this->Comment->save($data);
  68. echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
  69. echo returns($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
  70. echo returns($res);
  71. //echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
  72. $this->assertTrue(!isset($res['Comment']['lat']) && !isset($res['Comment']['lng']));
  73. }
  74. function testMinIncAllowed() {
  75. $this->Comment->Behaviors->detach('Geocoder');
  76. $this->Comment->Behaviors->attach('Geocoder', array('real'=>false, 'allow_inconclusive'=>true));
  77. // accuracy = 1
  78. $data = array(
  79. //'street' => 'Leopoldstraße',
  80. 'city' => 'Neustadt'
  81. );
  82. $res = $this->Comment->save($data);
  83. echo returns($this->Comment->Behaviors->Geocoder->Geocode->error()).BR;
  84. echo returns($this->Comment->Behaviors->Geocoder->Geocode->url()).BR;
  85. echo returns($this->Comment->Behaviors->Geocoder->Geocode->getResult()).BR;
  86. echo returns($res);
  87. //echo returns($this->Comment->Behaviors->Geocoder->Geocode->debug());
  88. $this->assertTrue(!empty($res['Comment']['lat']) && !empty($res['Comment']['lng']));
  89. }
  90. }