Skip to content

Commit a3a17fa

Browse files
committed
Add unit tests for new setAddressdetails method.
1 parent aa671f6 commit a3a17fa

4 files changed

+108
-0
lines changed

tests/NominatimTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,81 @@ public function testJsonSearch()
194194
$this->assertEquals($place[0]->osm_type, 'node');
195195
}
196196

197+
/**
198+
* Test JSON search
199+
*
200+
* @return void
201+
*/
202+
public function testJsonSearchWithAddressDetailsSet()
203+
{
204+
$mock = new HTTP_Request2_Adapter_Mock();
205+
$mock->addResponse(
206+
fopen(__DIR__ . '/responses/searchwaddrressdetailsset.json', 'rb')
207+
);
208+
209+
$osm = new Services_OpenStreetMap(array('adapter' => $mock));
210+
211+
$nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
212+
$nominatim->setFormat('json');
213+
$nominatim->setAddressdetails(1);
214+
$place = $nominatim->search('135, Pilkington Avenue, Birmingham', 1);
215+
$this->assertObjectHasAttribute(
216+
'address',
217+
$place[0],
218+
'place does not have address attribute exists?'
219+
);
220+
}
221+
222+
/**
223+
* Test JSON search
224+
*
225+
* @return void
226+
*/
227+
public function testJsonSearchWithAddressDetailsOff()
228+
{
229+
$mock = new HTTP_Request2_Adapter_Mock();
230+
$mock->addResponse(
231+
fopen(__DIR__ . '/responses/searchwaddrressdetailssoff.json', 'rb')
232+
);
233+
234+
$osm = new Services_OpenStreetMap(array('adapter' => $mock));
235+
236+
$nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
237+
$nominatim->setFormat('json');
238+
$nominatim->setAddressdetails(0);
239+
$place = $nominatim->search('135, Pilkington Avenue, Birmingham', 1);
240+
$this->assertObjectNotHasAttribute(
241+
'address',
242+
$place[0],
243+
'address attribute should not exist'
244+
);
245+
}
246+
/**
247+
* Test JSON search
248+
*
249+
* @return void
250+
*/
251+
public function testJsonSearchWithAddressDetailsNotSpecified()
252+
{
253+
$mock = new HTTP_Request2_Adapter_Mock();
254+
$mock->addResponse(
255+
fopen(__DIR__ . '/responses/searchwaddrressdetailsnotset.json', 'rb')
256+
);
257+
258+
//$osm = new Services_OpenStreetMap(array('adapter' => $mock));
259+
$osm = new Services_OpenStreetMap();
260+
261+
$nominatim = new Services_OpenStreetMap_Nominatim($osm->getTransport());
262+
$nominatim->setFormat('json');
263+
$nominatim->setAddressdetails(0);
264+
$place = $nominatim->search('135, Pilkington Avenue, Birmingham', 1);
265+
$this->assertObjectNotHasAttribute(
266+
'address',
267+
$place[0],
268+
'address attribute should not exist'
269+
);
270+
}
271+
197272
/**
198273
* Test searching for a placename as Gaeilge.
199274
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 27 May 2016 13:12:55 GMT
3+
Server: Apache/2.4.7 (Ubuntu)
4+
X-Powered-By: PHP/5.5.9-1ubuntu4.17
5+
Access-Control-Allow-Methods: OPTIONS,GET
6+
Access-Control-Max-Age: 8640000
7+
Access-Control-Allow-Origin: *
8+
Connection: close
9+
Content-Type: application/json; charset=UTF-8
10+
11+
[{"place_id":"78506474","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"90394480","boundingbox":["52.5487473","52.5488481","-1.8165129","-1.8163463"],"lat":"52.5487921","lon":"-1.8164307339635","display_name":"135, Pilkington Avenue, Sutton Coldfield, Maney, Birmingham, West Midlands, England, B72 1LH, UK","class":"building","type":"yes","importance":0.301}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 27 May 2016 13:12:55 GMT
3+
Server: Apache/2.4.7 (Ubuntu)
4+
X-Powered-By: PHP/5.5.9-1ubuntu4.17
5+
Access-Control-Allow-Methods: OPTIONS,GET
6+
Access-Control-Max-Age: 8640000
7+
Access-Control-Allow-Origin: *
8+
Connection: close
9+
Content-Type: application/json; charset=UTF-8
10+
11+
[{"place_id":"78506474","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"90394480","boundingbox":["52.5487473","52.5488481","-1.8165129","-1.8163463"],"lat":"52.5487921","lon":"-1.8164307339635","display_name":"135, Pilkington Avenue, Sutton Coldfield, Maney, Birmingham, West Midlands, England, B72 1LH, UK","class":"building","type":"yes","importance":0.301,"address":{"house_number":"135","road":"Pilkington Avenue","suburb":"Sutton Coldfield","hamlet":"Maney","city":"Birmingham","state_district":"West Midlands","state":"England","postcode":"B72 1LH","country":"UK","country_code":"gb"}}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 27 May 2016 13:12:55 GMT
3+
Server: Apache/2.4.7 (Ubuntu)
4+
X-Powered-By: PHP/5.5.9-1ubuntu4.17
5+
Access-Control-Allow-Methods: OPTIONS,GET
6+
Access-Control-Max-Age: 8640000
7+
Access-Control-Allow-Origin: *
8+
Connection: close
9+
Content-Type: application/json; charset=UTF-8
10+
11+
[{"place_id":"78506474","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"90394480","boundingbox":["52.5487473","52.5488481","-1.8165129","-1.8163463"],"lat":"52.5487921","lon":"-1.8164307339635","display_name":"135, Pilkington Avenue, Sutton Coldfield, Maney, Birmingham, West Midlands, England, B72 1LH, UK","class":"building","type":"yes","importance":0.301}]

0 commit comments

Comments
 (0)