-
Notifications
You must be signed in to change notification settings - Fork 395
/
apsearch.php
231 lines (203 loc) · 7.44 KB
/
apsearch.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
include_once dirname(__FILE__) . '/config.php';
// Store temporary airport ID
$new_apid = null;
/**
* Check that we can load up the country data
*/
class LoadCountriesTest extends WebTestCase {
public function test() {
global $webroot;
$params = array();
$this->post($webroot . "php/countries.php", $params);
$this->assertText('AF;Afghanistan');
$this->assertText('ZI;Zimbabwe');
}
}
/**
* Try to add an airport before logging in
*/
class RecordAirportNotLoggedInTest extends WebTestCase {
public function test() {
global $webroot;
$params = array("action" => "RECORD", "unittest" => "true");
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '0');
}
}
/**
* Add new airport
*/
class RecordNewAirportTest extends WebTestCase {
public function test() {
global $webroot, $airport, $new_apid;
login($this);
$params = $airport;
$params["action"] = "RECORD";
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
$new_apid = $json["apid"];
}
}
/**
* Try to add it again
*/
class RecordAirportDuplicateTest extends WebTestCase {
public function test() {
global $webroot, $airport;
login($this);
$params = $airport;
$params += array("action" => "RECORD", "unittest" => "true");
$msg = $this->post($webroot . "php/apsearch.php", $params);
$this->assertText('Add airport AutoTest Airport (ZZZ/ZZZZ)');
$this->assertText('New airport addition suggestion submitted by autotest:');
$this->assertText("[name] => " . $airport["name"]);
}
}
/**
* Try to edit an airport not belonging to us
*/
class EditWrongAirportTest extends WebTestCase {
public function test() {
global $webroot, $airport;
login($this);
$params = $airport;
$params["apid"] = 1;
$params["icao"] = "ZZZY";
$params += array("action" => "RECORD", "unittest" => "true");
$msg = $this->post($webroot . "php/apsearch.php", $params);
$this->assertText('Update airport AutoTest Airport (ZZZ/ZZZY)');
$this->assertText('New airport edit suggestion submitted by autotest:');
$this->assertText("[icao] => " . $params["icao"]);
$this->assertText("[icao] => " . $airport["icao"]);
}
}
/**
* Try to reuse an existing airport's code
*/
class EditAirportDuplicateICAOTest extends WebTestCase {
public function test() {
global $webroot, $airport, $new_apid;
login($this);
$params = $airport;
$params["icao"] = "WSSS"; // existing airport (Singapore)
$params["apid"] = $new_apid;
$params += array("action" => "RECORD", "unittest" => "true");
$msg = $this->post($webroot . "php/apsearch.php", $params);
$this->assertText('Update airport AutoTest Airport (ZZZ/WSSS)');
$this->assertText('New airport edit suggestion submitted by autotest:');
$this->assertText("[name] => " . $airport["name"]);
$this->assertText("[name] => Changi Intl");
}
}
/**
* Try to edit to overwrite existing airport
*/
class EditAirportSuccessfulTest extends WebTestCase {
public function test() {
global $webroot, $airport, $new_apid;
login($this);
$params = $airport;
$params["apid"] = $new_apid;
$params["name"] = $airport["name"] . " Edited";
$params += array("action" => "RECORD", "unittest" => "true");
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
}
}
/**
* Add new location with null codes
*/
class RecordNewNullCodePlaceTest extends WebTestCase {
public function test() {
global $webroot, $settings, $airport, $new_apid;
login($this);
$params = array(
'name' => 'AutoTest Nullport',
'city' => 'Testville',
'country' => 'Nullistan',
'iata' => '',
'icao' => '',
'x' => '42.424',
'y' => '69.696',
'elevation' => '123',
'timezone' => '-5.5',
'dst' => 'Z'
);
$params["action"] = "RECORD";
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
$null_apid = $json["apid"];
$params = array("apid" => $null_apid,
"action" => "LOAD");
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
$this->assertEqual($json['max'], 1);
$this->assertText('"iata":null');
$this->assertText('"icao":null');
}
}
/**
* Load a single airport
*/
class LoadAirportByApidTest extends WebTestCase {
public function test() {
global $webroot, $airport, $new_apid;
login($this);
$params = array(
"apid" => $new_apid,
"action" => "LOAD"
);
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
$this->assertEqual($json['max'], 1);
$this->assertText('"name":"' . $airport["name"] . ' Edited"');
$this->assertText('"city":"' . $airport["city"] . '"');
$this->assertText('"country":"' . $airport["country"] . '"');
$this->assertText('"iata":"' . $airport["iata"] . '"');
$this->assertText('"icao":"' . $airport["icao"] . '"');
$this->assertText('"x":"' . $airport["x"] . '"');
$this->assertText('"y":"' . $airport["y"] . '"');
$this->assertText('"elevation":"' . $airport["elevation"] . '"');
$this->assertText('"timezone":"' . $airport["timezone"] . '"');
$this->assertText('"dst":"' . $airport["dst"] . '"');
$this->assertText('"ap_uid":"own"');
}
}
/**
* Load a single airport
*/
class LoadAirportByInvalidApidTest extends WebTestCase {
public function test() {
global $webroot;
$params = array(
"apid" => "garbage",
"action" => "LOAD"
);
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '0');
}
}
/**
* Search OpenFlights DB by IATA code (of just-added airport)
*/
class SearchAirportOFDBByIATATest extends WebTestCase {
public function test() {
global $webroot, $airport;
login($this);
$params = array("iata" => $airport["iata"]);
$json = json_decode($this->post($webroot . "php/apsearch.php", $params), true);
$this->assertEqual($json['status'], '1');
$this->assertText('"name":"' . $airport["name"] . ' Edited"');
$this->assertText('"city":"' . $airport["city"] . '"');
$this->assertText('"country":"' . $airport["country"] . '"');
$this->assertText('"iata":"' . $airport["iata"] . '"');
$this->assertText('"icao":"'. $airport["icao"] . '"');
$this->assertText('"x":"' . $airport["x"] . '"');
$this->assertText('"y":"' . $airport["y"] . '"');
$this->assertText('"elevation":"' . $airport["elevation"] . '"');
$this->assertText('"timezone":"' . $airport["timezone"] . '"');
$this->assertText('"dst":"' . $airport["dst"] . '"');
$this->assertText('"ap_uid":"own"');
}
}