@@ -200,20 +200,136 @@ public function testGeoMaxDistanceWithUnits()
200
200
$ query ->withinMiles ('location ' , $ point , 10.0 );
201
201
$ results = $ query ->find ();
202
202
$ this ->assertEquals (0 , count ($ results ));
203
-
204
203
}
205
204
206
- public function testBadLatitude () {
207
- $ this ->setExpectedException ('\Parse\ParseException ' ,
208
- 'Latitude must be within range [-90.0, 90.0] ' );
205
+ public function testBadLatitude ()
206
+ {
207
+ $ this ->setExpectedException (
208
+ '\Parse\ParseException ' ,
209
+ 'Latitude must be within range [-90.0, 90.0] '
210
+ );
209
211
new ParseGeoPoint (-180 , 32 );
210
-
211
212
}
212
213
213
- public function testBadLongitude () {
214
- $ this ->setExpectedException ('\Parse\ParseException ' ,
215
- 'Longitude must be within range [-180.0, 180.0] ' );
214
+ public function testBadLongitude ()
215
+ {
216
+ $ this ->setExpectedException (
217
+ '\Parse\ParseException ' ,
218
+ 'Longitude must be within range [-180.0, 180.0] '
219
+ );
216
220
new ParseGeoPoint (32 , -360 );
221
+ }
222
+
223
+ public function testWithinPolygonOpenPath ()
224
+ {
225
+ $ inbound = ParseObject::create ('TestObject ' );
226
+ $ onbound = ParseObject::create ('TestObject ' );
227
+ $ outbound = ParseObject::create ('TestObject ' );
228
+
229
+ $ inbound ->set ('location ' , new ParseGeoPoint (1 , 1 ));
230
+ $ onbound ->set ('location ' , new ParseGeoPoint (10 , 10 ));
231
+ $ outbound ->set ('location ' , new ParseGeoPoint (20 , 20 ));
232
+
233
+ ParseObject::saveAll ([$ inbound , $ onbound , $ outbound ]);
234
+
235
+ $ points = [
236
+ new ParseGeoPoint (0 , 0 ),
237
+ new ParseGeoPoint (0 , 10 ),
238
+ new ParseGeoPoint (10 , 10 ),
239
+ new ParseGeoPoint (10 , 0 )
240
+ ];
241
+ $ query = new ParseQuery ('TestObject ' );
242
+ $ query ->withinPolygon ('location ' , $ points );
243
+ $ results = $ query ->find ();
244
+ $ this ->assertEquals (2 , count ($ results ));
245
+ }
217
246
247
+ public function testWithinPolygonClosedPath ()
248
+ {
249
+ $ inbound = ParseObject::create ('TestObject ' );
250
+ $ onbound = ParseObject::create ('TestObject ' );
251
+ $ outbound = ParseObject::create ('TestObject ' );
252
+
253
+ $ inbound ->set ('location ' , new ParseGeoPoint (1 , 1 ));
254
+ $ onbound ->set ('location ' , new ParseGeoPoint (10 , 10 ));
255
+ $ outbound ->set ('location ' , new ParseGeoPoint (20 , 20 ));
256
+
257
+ ParseObject::saveAll ([$ inbound , $ onbound , $ outbound ]);
258
+
259
+ $ points = [
260
+ new ParseGeoPoint (0 , 0 ),
261
+ new ParseGeoPoint (0 , 10 ),
262
+ new ParseGeoPoint (10 , 10 ),
263
+ new ParseGeoPoint (10 , 0 ),
264
+ new ParseGeoPoint (0 , 0 )
265
+ ];
266
+ $ query = new ParseQuery ('TestObject ' );
267
+ $ query ->withinPolygon ('location ' , $ points );
268
+ $ results = $ query ->find ();
269
+ $ this ->assertEquals (2 , count ($ results ));
270
+ }
271
+
272
+ public function testWithinPolygonEmpty ()
273
+ {
274
+ $ obj = ParseObject::create ('TestObject ' );
275
+ $ obj ->set ('location ' , new ParseGeoPoint (1.5 , 1.5 ));
276
+ $ obj ->save ();
277
+
278
+ $ this ->setExpectedException (
279
+ '\Parse\ParseException ' ,
280
+ 'bad $geoWithin value; $polygon should contain at least 3 GeoPoints '
281
+ );
282
+ $ query = new ParseQuery ('TestObject ' );
283
+ $ query ->withinPolygon ('location ' , []);
284
+ $ query ->find ();
285
+ }
286
+
287
+ public function testWithinPolygonTwoGeoPoints ()
288
+ {
289
+ $ obj = ParseObject::create ('TestObject ' );
290
+ $ obj ->set ('location ' , new ParseGeoPoint (1.5 , 1.5 ));
291
+ $ obj ->save ();
292
+
293
+ $ this ->setExpectedException (
294
+ '\Parse\ParseException ' ,
295
+ 'bad $geoWithin value; $polygon should contain at least 3 GeoPoints '
296
+ );
297
+ $ points = [
298
+ new ParseGeoPoint (0 , 0 ),
299
+ new ParseGeoPoint (10 , 10 )
300
+ ];
301
+ $ query = new ParseQuery ('TestObject ' );
302
+ $ query ->withinPolygon ('location ' , $ points );
303
+ $ query ->find ();
304
+ }
305
+
306
+ public function testWithinPolygonNonArray ()
307
+ {
308
+ $ obj = ParseObject::create ('TestObject ' );
309
+ $ obj ->set ('location ' , new ParseGeoPoint (1.5 , 1.5 ));
310
+ $ obj ->save ();
311
+
312
+ $ this ->setExpectedException (
313
+ '\Parse\ParseException ' ,
314
+ 'bad $geoWithin value; $polygon should contain at least 3 GeoPoints '
315
+ );
316
+ $ query = new ParseQuery ('TestObject ' );
317
+ $ query ->withinPolygon ('location ' , 1234 );
318
+ $ query ->find ();
319
+ }
320
+
321
+ public function testWithinPolygonInvalidArray ()
322
+ {
323
+ $ obj = ParseObject::create ('TestObject ' );
324
+ $ obj ->set ('location ' , new ParseGeoPoint (1.5 , 1.5 ));
325
+ $ obj ->save ();
326
+
327
+ $ this ->setExpectedException (
328
+ '\Parse\ParseException ' ,
329
+ 'bad $geoWithin value; $polygon should contain at least 3 GeoPoints '
330
+ );
331
+ $ query = new ParseQuery ('TestObject ' );
332
+ $ query ->withinPolygon ('location ' , [$ obj ]);
333
+ $ query ->find ();
218
334
}
219
335
}
0 commit comments