-
Notifications
You must be signed in to change notification settings - Fork 395
/
submit.php
202 lines (170 loc) · 6.29 KB
/
submit.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
<?php
include_once dirname(__FILE__) . '/config.php';
// Test cases for php/submit.php and php/flights.php
// NB: Assumes the test user exists and there are no flights entered yet (run settings.php first!)
$fid = null; // global for newly added flight
/**
* Try to add a flight when not logged in
*/
class AddSingleFlightWithoutLoggingInTest extends WebTestCase {
public function test() {
global $webroot, $flight;
$msg = $this->post($webroot . "php/submit.php", $flight);
$this->assertText('Not logged in');
}
}
/**
* Add loop flight (src==dest)
*/
class AddLoopFlightTest extends WebTestCase {
public function test() {
global $webroot, $loopflight;
assert_login($this);
$msg = $this->post($webroot . "php/submit.php", $loopflight);
$this->assertText('1;');
// Check that one flight was added
$map = $this->post($webroot . "php/map.php");
$cols = preg_split('/[;\n]/', $map);
$this->assertTrue($cols[0] == "1", "Flight count should be 1");
}
}
/**
* Add multiple flights at once
*/
class AddMultiFlightTest extends WebTestCase {
public function test() {
global $webroot, $multiflight;
assert_login($this);
$msg = $this->post($webroot . "php/submit.php", $multiflight);
$this->assertText('1;');
// Check that flights were added
$map = $this->post($webroot . "php/map.php");
$cols = preg_split('/[;\n]/', $map);
$this->assertTrue($cols[0] == 1 + $multiflight["multi"], "Flight count should be " . $multiflight["multi"] + 1);
}
}
/**
* Not an actual test, just cleaning up
*/
class DeleteExtraFlightsTest extends WebTestCase {
public function test() {
global $settings;
$dbh = db_connect();
$sth = $dbh->prepare("DELETE FROM flights WHERE uid IN (SELECT uid FROM users WHERE name = ?)");
$sth->execute([$settings["name"]]);
$this->assertTrue($sth->rowCount() >= 1, "Flights deleted");
}
}
/**
* Add a single flight
*/
class AddSingleFlightTest extends WebTestCase {
public function test() {
global $webroot, $flight, $fid;
assert_login($this);
$msg = $this->post($webroot . "php/submit.php", $flight);
$this->assertText('1;');
// Check that one flight was added
$map = $this->post($webroot . "php/map.php");
$cols = preg_split('/[;\n]/', $map);
$this->assertTrue($cols[0] == "1", "One flight recorded");
// Get the ID of the newly added flight
$dbh = db_connect();
$sth = $dbh->prepare("SELECT fid FROM flights WHERE note = ?");
$sth->execute([$flight["note"]]);
$row = $sth->fetch();
$fid = $row["fid"];
$this->assertTrue($fid != null && $fid != "");
}
}
/**
* Fetch and validate newly added flight
*/
class FetchAddSingleFlightTest extends WebTestCase {
public function test() {
global $webroot, $flight, $fid;
assert_login($this);
$params = array("fid" => $fid);
$msg = $this->post($webroot . "php/flights.php", $params);
$this->assertText($flight["src_date"]);
$this->assertText($flight["src_apid"]);
$this->assertText($flight["dst_apid"]);
$this->assertText($flight["alid"]);
$this->assertText($flight["duration"]);
$this->assertText($flight["distance"]);
$this->assertText($flight["number"]);
$this->assertText($flight["plane"]);
$this->assertText($flight["seat"]);
$this->assertText($flight["type"]);
$this->assertText($flight["class"]);
$this->assertText($flight["reason"]);
$this->assertText($flight["registration"]);
$this->assertText($flight["note"]);
$this->assertText($flight["src_time_formatted"]);
}
}
/**
* Edit new flight, altering all fields into flight2
*/
class EditFlightTest extends WebTestCase {
public function test() {
global $webroot, $flight2, $fid;
assert_login($this);
$params = $flight2;
$params["fid"] = $fid;
$msg = $this->post($webroot . "php/submit.php", $params);
$this->assertText('2;');
}
}
/**
* Fetch and validate newly added flight
*/
class FetchEditedFlightTest extends WebTestCase {
public function test() {
global $webroot, $flight2, $fid;
assert_login($this);
$params = array("fid" => $fid);
$msg = $this->post($webroot . "php/flights.php", $params);
$this->assertText($flight2["src_date"]);
$this->assertText($flight2["src_apid"]);
$this->assertText($flight2["dst_apid"]);
$this->assertText($flight2["alid"]);
$this->assertText($flight2["duration"]);
$this->assertText($flight2["distance"]);
$this->assertText($flight2["number"]);
$this->assertText($flight2["plane"]);
$this->assertText($flight2["seat"]);
$this->assertText($flight2["type"]);
$this->assertText($flight2["class"]);
$this->assertText($flight2["reason"]);
$this->assertText($flight2["registration"]);
$this->assertText($flight2["note"]);
$this->assertText($flight2["src_time"]);
}
}
/**
* CSV export and validate edited flight
*/
class CSVExportFlightTest extends WebTestCase {
public function test() {
global $webroot, $flight2;
assert_login($this);
$params = array("export" => "export");
$msg = $this->get($webroot . "php/flights.php", $params);
$this->assertText($flight2["src_date"] . " " . $flight2["src_time"] . ":00,");
$this->assertText($flight2["alid"] . ",");
$this->assertText($flight2["duration"] . ",");
$this->assertText($flight2["distance"] . ",");
$this->assertText($flight2["number"] . ",");
$this->assertText($flight2["plane"] . ",");
$this->assertText($flight2["seat"] . ",");
$this->assertText($flight2["type"] . ",");
$this->assertText($flight2["class"] . ",");
$this->assertText($flight2["reason"] . ",");
$this->assertText($flight2["registration"] . ",");
$this->assertText($flight2["note"]); // may or may not be quote-wrapped
$this->assertText($flight2["src_apid"] . ",");
$this->assertText($flight2["dst_apid"] . ",");
$this->assertText($flight2["alid"] . ",");
}
}