forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalsearch.php
189 lines (160 loc) · 5.26 KB
/
alsearch.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
<?php
include_once(dirname(__FILE__) . '/config.php');
// Store temporary airline, railway ID
$new_alid = null;
$new_rlid = null;
// Try to add airline before logging in
class RecordAirlineNotLoggedInTest extends WebTestCase {
function test() {
global $webroot, $settings;
$params = array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText("0;");
}
}
// Try to reuse an existing airline's code
class RecordAirlineDuplicateICAOTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline, $new_alid;
login($this);
$params = $airline;
$params["icao"] = "SIA"; // existing airline (Singapore Airlines)
$params += array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;');
}
}
// Add new airline
class RecordNewAirlineTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline, $new_alid;
login($this);
$params = $airline;
$params["action"] = "RECORD";
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('1;');
$cols = preg_split('/[;\n]/', $msg);
if($cols[0] == "1") {
$new_alid = $cols[1];
}
}
}
// Try to record it again
class RecordAirlineDuplicateTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline, $new_alid;
login($this);
$params = $airline;
$params += array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;');
}
}
// Add new railway
class RecordNewRailwayTest extends WebTestCase {
function test() {
global $webroot, $settings, $railway, $new_rlid;
login($this);
$params = $railway;
$params["action"] = "RECORD";
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('1;');
$cols = preg_split('/[;\n]/', $msg);
$new_rlid = $cols[1];
}
}
// Try to add the railway again
class RecordRailwayDuplicateTest extends WebTestCase {
function test() {
global $webroot, $settings, $railway;
login($this);
$params = $railway;
$params["action"] = "RECORD";
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;');
}
}
// Try to edit an airline not belonging to us
class EditWrongAirlineTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline;
login($this);
$params = $airline;
$params["alid"] = 1; // this is presumably not owned by us
$params["icao"] = "ZZZY";
$params += array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;');
}
}
// Try to reuse an existing airline's code
class EditAirlineDuplicateICAOTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline, $new_alid;
login($this);
$params = $airline;
$params["icao"] = "SIA"; // existing airline (Singapore Airlines)
$params["alid"] = $new_alid;
$params += array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;');
}
}
// Try to edit to overwrite existing airline
class EditAirlineSuccessfulTest extends WebTestCase {
function test() {
global $webroot, $settings, $airline, $new_alid;
login($this);
$params = $airline;
$params["alid"] = $new_alid;
$params["name"] = $airline["name"] . " Edited";
$params += array("action" => "RECORD");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('1;');
}
}
// Search by IATA
class SearchAirlineByIATATest extends WebTestCase {
function test() {
global $webroot, $airline;
login($this);
$params = array("iata" => $airline["iata"]);
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;1');
$this->assertText('"name":"' . $airline["name"] . ' Edited"');
$this->assertText('"alias":"' . $airline["alias"] . '"');
$this->assertText('"iata":"' . $airline["iata"] . '"');
$this->assertText('"icao":"'. $airline["icao"] . '"');
$this->assertText('"mode":"'. $airline["mode"] . '"');
$this->assertText('"active":"'. $airline["active"] . '"');
$this->assertText('"callsign":"'. $airline["callsign"] . '"');
}
}
// Search by ICAO
class SearchAirlineByICAOTest extends WebTestCase {
function test() {
global $webroot, $airline;
login($this);
$params = array("icao" => $airline["icao"]);
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;1');
$this->assertText('"name":"' . $airline["name"] . ' Edited"');
$this->assertText('"alias":"' . $airline["alias"] . '"');
$this->assertText('"iata":"' . $airline["iata"] . '"');
$this->assertText('"icao":"'. $airline["icao"] . '"');
}
}
// Search railway by name
class SearchRailwayByNameTest extends WebTestCase {
function test() {
global $webroot, $railway;
login($this);
$params = array("name" => $railway["name"],
"mode" => "T");
$msg = $this->post($webroot . "php/alsearch.php", $params);
$this->assertText('0;1');
$this->assertText('"name":"' . $railway["name"] . '"');
$this->assertText('"alias":"' . $railway["alias"] . '"');
}
}
?>