-
Notifications
You must be signed in to change notification settings - Fork 395
/
trip.php
166 lines (141 loc) · 4.38 KB
/
trip.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
<?php
include_once dirname(__FILE__) . '/config.php';
// Test cases for php/trip.php
$trid = null;
/**
* Create a new trip without logging in
*/
class NewTripNotLoggedInTest extends WebTestCase {
public function test() {
global $webroot, $trip;
$trip["type"] = "NEW";
$this->post($webroot . "php/trip.php", $trip);
$this->assertText('0;');
}
}
/**
* Create a new trip
*/
class SuccessfulNewTripTest extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
login($this);
$trip["type"] = "NEW";
$msg = $this->post($webroot . "php/trip.php", $trip);
$this->assertText('1;');
$cols = preg_split('/[;\n]/', $msg);
$trid = $cols[1];
}
}
/**
* Try to edit when not logged in
*/
class EditTripWithoutLoggingInTest extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
$trip["type"] = "EDIT";
$trip["trid"] = $trid;
$this->post($webroot . "php/trip.php", $trip);
$this->assertText('0;');
}
}
/**
* Try to manipulate the wrong trip id
*/
class EditWrongTridTripTest extends WebTestCase {
public function test() {
global $webroot, $trip;
login($this);
$trip["type"] = "EDIT";
$trip["trid"] = -1;
$this->post($webroot . "php/trip.php", $trip);
$this->assertText('0;');
}
}
/**
* Check a public trip
*/
class CheckPublicFullTripMap extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
$params = array("param" => "true",
"trid" => $trid);
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
$this->assertTrue(sizeof($rows) == 6, "Number of rows" . sizeof($rows));
// Statistics
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] == 0, "Flight count");
$this->assertTrue(strstr($stats[1], "0"), "Distance");
$this->assertTrue($stats[3] == $trip["privacy"], "Public");
$this->assertTrue($stats[5] == "demo", "Username"); // we are not this user!
}
}
/**
* Change trip settings
*/
class SuccessfulEditTripTest extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
login($this);
$params = array(
"trid" => $trid,
"type" => "EDIT",
"name" => "New AutoTest Trip",
"url" => "http://new.autotest.example",
"privacy" => "N"
);
$msg = $this->post($webroot . "php/trip.php", $params);
$this->assertText('2;');
// Validate changes
$dbh = db_connect();
$sth = $dbh->prepare("SELECT * FROM trips WHERE trid = ?");
$sth->execute([$trid]);
$row = $sth->fetch();
$this->assertTrue($row["name"] == "New AutoTest Trip", "Name");
$this->assertTrue($row["public"] == "N", "Public");
$this->assertTrue($row["url"] == "http://new.autotest.example", "URL");
}
}
/** Check loading a private trip; it should fail */
class CheckPrivateFullTripMap extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
$params = array("param" => "true",
"trid" => $trid);
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode(";", $map);
$this->assertTrue($rows[0] == "Error", "Private trip blocked");
}
}
/**
* Check an invalid Trip ID trip map; it should fail
*/
class CheckNonExistentFullTripMap extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
$params = array("param" => "true",
"trid" => "-1");
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode(";", $map);
$this->assertTrue($rows[0] == "Error", "Invalid trid blocked");
}
}
/**
* Delete trip
*/
class DeleteTripTest extends WebTestCase {
public function test() {
global $webroot, $trip, $trid;
login($this);
$trip["type"] = "DELETE";
$trip["trid"] = $trid;
$msg = $this->post($webroot . "php/trip.php", $trip);
$this->assertText('100;');
// Verify
$dbh = db_connect();
$sth = $dbh->prepare("SELECT * FROM trips WHERE trid = ?");
$sth->execute([$trid]);
$this->assertFalse($sth->fetch(), "Deleting failed");
}
}