5 require_once(CONST_BasePath.'/lib/AddressDetails.php');
 
   8 function chksql($oSql, $sMsg = 'Database request failed')
 
  13 class AddressDetailsTest extends \PHPUnit\Framework\TestCase
 
  16     protected function setUp()
 
  18         // How the fixture got created
 
  20         // 1) search for '10 downing street'
 
  21         // https://nominatim.openstreetmap.org/details.php?osmtype=R&osmid=1879842
 
  23         // 2) find place_id in the local database
 
  24         // SELECT place_id, name FROM placex WHERE osm_type='R' AND osm_id=1879842;
 
  26         // 3) set postgresql to non-align output, e.g. psql -A or \a in the CLI
 
  29         // SELECT row_to_json(row,true) FROM (
 
  30         //   SELECT *, get_name_by_language(name, ARRAY['name:en']) as localname
 
  31         //   FROM get_addressdata(194663412,10)
 
  32         //   ORDER BY rank_address DESC, isaddress DESC
 
  35         // 5) copy&paste into file. Add commas between records
 
  37         $json = file_get_contents(CONST_BasePath.'/test/php/fixtures/address_details_10_downing_street.json');
 
  38         $data = json_decode($json, true);
 
  40         $this->oDbStub = $this->getMockBuilder(\DB::class)
 
  41                               ->setMethods(array('getAll'))
 
  43         $this->oDbStub->method('getAll')
 
  47     public function testGetLocaleAddress()
 
  49         $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
 
  50         $expected = join(', ', array(
 
  63         $this->assertEquals($expected, $oAD->getLocaleAddress());
 
  66     public function testGetAddressDetails()
 
  68         $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
 
  69         $this->assertEquals(18, count($oAD->getAddressDetails(true)));
 
  70         $this->assertEquals(12, count($oAD->getAddressDetails(false)));
 
  73     public function testGetAddressNames()
 
  75         $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
 
  77                      'attraction' => '10 Downing Street',
 
  78                      'house_number' => '10',
 
  79                      'road' => 'Downing Street',
 
  80                      'neighbourhood' => 'St. James\'s',
 
  81                      'suburb' => 'Covent Garden',
 
  83                      'state_district' => 'Greater London',
 
  85                      'postcode' => 'SW1A 2AA',
 
  86                      'country' => 'United Kingdom',
 
  87                      'country_code' => 'gb'
 
  90         $this->assertEquals($expected, $oAD->getAddressNames());
 
  93     public function testGetAdminLevels()
 
  95         $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
 
  97                      'level8' => 'Westminster',
 
  99                      'level5' => 'Greater London',
 
 100                      'level4' => 'England',
 
 101                      'level2' => 'United Kingdom'
 
 103         $this->assertEquals($expected, $oAD->getAdminLevels());
 
 106     public function testDebugInfo()
 
 108         $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
 
 109         $this->assertTrue(is_array($oAD->debugInfo()));
 
 110         $this->assertEquals(18, count($oAD->debugInfo()));