forked from cihadoge/parse-php-sdk-for-codeigniter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParseGeoBoxTest.php
More file actions
156 lines (126 loc) · 4.85 KB
/
Copy pathParseGeoBoxTest.php
File metadata and controls
156 lines (126 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseGeoPoint;
use Parse\ParseException;
require_once 'ParseTestHelper.php';
class ParseGeoBoxTest extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
ParseTestHelper::setUp();
}
public function setUp()
{
ParseTestHelper::clearClass("TestObject");
}
public function tearDown()
{
ParseTestHelper::tearDown();
}
public function testGeoBox()
{
$caltrainStationLocation = new ParseGeoPoint(37.776346, -122.394218);
$caltrainStation = ParseObject::create('TestObject');
$caltrainStation->set('location', $caltrainStationLocation);
$caltrainStation->set('name', 'caltrain');
$caltrainStation->save();
$santaClaraLocation = new ParseGeoPoint(37.325635, -121.945753);
$santaClara = new ParseObject('TestObject');
$santaClara->set('location', $santaClaraLocation);
$santaClara->set('name', 'santa clara');
$santaClara->save();
$southwestOfSF = new ParseGeoPoint(37.708813, -122.526398);
$northeastOfSF = new ParseGeoPoint(37.822802, -122.373962);
// Try a correct query
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $southwestOfSF, $northeastOfSF);
$objectsInSF = $query->find();
$this->assertEquals(1, count($objectsInSF));
$this->assertEquals('caltrain', $objectsInSF[0]->get('name'));
// Switch order of args, should fail because it crosses the dateline
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $northeastOfSF, $southwestOfSF);
try {
$results = $query->find();
$this->assertTrue(FALSE, 'Query should fail because it crosses dateline');
} catch (ParseException $e) {
}
$northwestOfSF = new ParseGeoPoint(37.822802, -122.526398);
$southeastOfSF = new ParseGeoPoint(37.708813, -122.373962);
// Switch just longitude, should fail because it crosses the dateline
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $southeastOfSF, $northwestOfSF);
try {
$query->find();
$this->assertTrue(FALSE, 'Query should fail because it crosses dateline');
} catch (ParseException $e) {
}
// Switch just the latitude, should fail because it doesnt make sense
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $northwestOfSF, $southeastOfSF);
try {
$query->find();
$this->assertTrue(FALSE, 'Query should fail because it makes no sense');
} catch (ParseException $e) {
}
}
public function testGeoBoxSmallNearDateLine()
{
$nearWestOfDateLine = new ParseGeoPoint(0, 175);
$nearWestObject = ParseObject::create('TestObject');
$nearWestObject->set('location', $nearWestOfDateLine);
$nearWestObject->set('name', 'near west');
$nearWestObject->set('order', 1);
$nearWestObject->save();
$nearEastOfDateLine = new ParseGeoPoint(0, -175);
$nearEastObject = ParseObject::create('TestObject');
$nearEastObject->set('location', $nearEastOfDateLine);
$nearEastObject->set('name', 'near east');
$nearEastObject->set('order', 2);
$nearEastObject->save();
$farWestOfDateLine = new ParseGeoPoint(0, 165);
$farWestObject = ParseObject::create('TestObject');
$farWestObject->set('location', $farWestOfDateLine);
$farWestObject->set('name', 'far west');
$farWestObject->set('order', 3);
$farWestObject->save();
$farEastOfDateLine = new ParseGeoPoint(0, -165);
$farEastObject = ParseObject::create('TestObject');
$farEastObject->set('location', $farEastOfDateLine);
$farEastObject->set('name', 'far east');
$farEastObject->set('order', 4);
$farEastObject->save();
$southwestOfDateLine = new ParseGeoPoint(-10, 170);
$northeastOfDateLine = new ParseGeoPoint(10, -170);
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $southwestOfDateLine, $northeastOfDateLine);
$query->ascending('order');
try {
$query->find();
$this->assertTrue(FALSE, 'Query should fail for crossing the date line.');
} catch (ParseException $e) {
}
}
public function testGeoBoxTooLarge()
{
$centerPoint = new ParseGeoPoint(0, 0);
$center = ParseObject::create('TestObject');
$center->set('location', $centerPoint);
$center->save();
$southwest = new ParseGeoPoint(-89, -179);
$northeast = new ParseGeoPoint(89, 179);
// This is an interesting test case because mongo can actually handle this
// kind of query, but
// if one actually happens, it's probably that the developer switches the
// two points.
$query = new ParseQuery('TestObject');
$query->withinGeoBox('location', $southwest, $northeast);
try {
$query->find();
$this->assertTrue(FALSE, 'Query should fail for being too large.');
} catch (ParseException $e) {
}
}
}