-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathmap.php
128 lines (109 loc) · 4.35 KB
/
map.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
<?php
include_once dirname(__FILE__) . '/config.php';
// Test cases for php/map.php
// NB 1: Assumes the test user exists and flights.php has been run, so that $flight2[] is already in DB
// NB 2: Trip map tests found under trip.php
// ##TODO## filters
/**
* Check demo user map
*/
class CheckDemoFullUserMap extends WebTestCase {
public function test() {
global $webroot, $settings, $flight2;
$params = array("param" => "true");
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
$this->assertTrue(sizeof($rows) == 6, "Number of rows");
// Statistics
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] > 0, "No demo flights found -- did you add some flights and run sql/update-demo.sql?");
$this->assertTrue($stats[3] == "O", "Public"); // demo flights always full access
$this->assertTrue($stats[5] == "demo", "Username");
}
}
/**
* Check public profile for user
*/
class CheckPublicFullUserMap extends WebTestCase {
public function test() {
global $webroot, $settings, $flight2;
$params = array(
"param" => "true",
"user" => $settings["name"]
);
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
$this->assertTrue(sizeof($rows) == 6, "Number of rows");
// Statistics
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] == 1, "Flight count");
$this->assertTrue(strstr($stats[1], $flight2["distance"]), "Distance");
$this->assertTrue($stats[3] == $settings["privacy"], "Public");
$this->assertTrue($stats[4] == $settings["elite"], "Elite");
$this->assertTrue($stats[5] == "demo", "Username"); // we are not this user!
}
}
/**
* Attempt to view private profile for user (fails)
*/
class CheckPrivateNoPasswordFullUserMap extends WebTestCase {
public function test() {
global $webroot, $settings;
$dbh = db_connect();
$sth = $dbh->prepare("UPDATE users SET public='N', guestpw = ? WHERE name = ?");
$sth->execute([$settings["guestpw"], $settings["name"]]);
$this->assertTrue($sth->rowCount() == 1, "Set profile to private");
$params = array(
"param" => "true",
"guestpw" => "incorrect",
"user" => $settings["name"]
);
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] == "Error", "Private profile blocked");
}
}
/**
* View private profile with correct password
*/
class CheckPrivateGuestPasswordFullUserMap extends WebTestCase {
public function test() {
global $webroot, $settings, $flight2;
$params = array(
"param" => "true",
"guestpw" => $settings["guestpw"],
"user" => $settings["name"]
);
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
// Statistics
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] == 1, "Flight count");
$this->assertTrue(strstr($stats[1], $flight2["distance"]), "Distance");
$this->assertTrue($stats[3] == "N", "Public");
$this->assertTrue($stats[4] == $settings["elite"], "Elite");
$this->assertTrue($stats[5] == "demo", "Username"); // we are not this user!
}
}
/**
* Check logged in user map
*/
class CheckLoggedInFullUserMap extends WebTestCase {
public function test() {
global $webroot, $settings, $flight2;
assert_login($this);
$params = array("param" => "true");
$map = $this->post($webroot . "php/map.php", $params);
$rows = explode("\n", $map);
$this->assertTrue(sizeof($rows) == 6, "Number of rows");
// Statistics
$stats = explode(";", $rows[0]);
$this->assertTrue($stats[0] == 1, "Flight count");
$this->assertTrue(strstr($stats[1], $flight2["distance"]), "Distance");
$this->assertTrue($stats[3] == "O", "Public"); // own flights always full access
$this->assertTrue($stats[4] == $settings["elite"], "Elite");
$this->assertTrue($stats[5] == $settings["name"], "Username");
$this->assertTrue($stats[6] == $settings["editor"], "Editor");
}
}