5 require_once(CONST_LibDir.'/init-website.php');
6 require_once(CONST_LibDir.'/AddressDetails.php');
9 class AddressDetailsTest extends \PHPUnit\Framework\TestCase
12 protected function setUp(): void
14 // How the fixture got created
16 // 1) search for '10 downing street'
17 // https://nominatim.openstreetmap.org/details.php?osmtype=R&osmid=1879842
19 // 2) find place_id in the local database
20 // SELECT place_id, name FROM placex WHERE osm_type='R' AND osm_id=1879842;
22 // 3) set postgresql to non-align output, e.g. psql -A or \a in the CLI
25 // SELECT row_to_json(row,true) FROM (
26 // SELECT *, get_name_by_language(name, ARRAY['name:en']) as localname
27 // FROM get_addressdata(194663412,10)
28 // ORDER BY rank_address DESC, isaddress DESC
31 // 5) copy&paste into file. Add commas between records
33 $json = file_get_contents(CONST_DataDir.'/test/php/fixtures/address_details_10_downing_street.json');
34 $data = json_decode($json, true);
36 $this->oDbStub = $this->getMockBuilder(\DB::class)
37 ->setMethods(array('getAll'))
39 $this->oDbStub->method('getAll')
43 public function testGetLocaleAddress()
45 $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
46 $expected = join(', ', array(
59 $this->assertEquals($expected, $oAD->getLocaleAddress());
62 public function testGetAddressDetails()
64 $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
65 $this->assertEquals(18, count($oAD->getAddressDetails(true)));
66 $this->assertEquals(12, count($oAD->getAddressDetails(false)));
69 public function testGetAddressNames()
71 $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
73 'tourism' => '10 Downing Street',
74 'house_number' => '10',
75 'road' => 'Downing Street',
76 'neighbourhood' => 'St. James\'s',
77 'suburb' => 'Covent Garden',
79 'state_district' => 'Greater London',
81 'postcode' => 'SW1A 2AA',
82 'country' => 'United Kingdom',
83 'country_code' => 'gb'
86 $this->assertEquals($expected, $oAD->getAddressNames());
89 public function testGetAdminLevels()
91 $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
93 'level8' => 'Westminster',
95 'level5' => 'Greater London',
96 'level4' => 'England',
97 'level2' => 'United Kingdom'
99 $this->assertEquals($expected, $oAD->getAdminLevels());
102 public function testDebugInfo()
104 $oAD = new AddressDetails($this->oDbStub, 194663412, 10, 'en');
105 $this->assertTrue(is_array($oAD->debugInfo()));
106 $this->assertEquals(18, count($oAD->debugInfo()));