forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
top10.php
108 lines (83 loc) · 3.23 KB
/
top10.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
<?php
include_once(dirname(__FILE__) . '/config.php');
//
// Test cases for php/top10.php
// NB: Assumes the test user exists and flights.php has been run, so that $flight2[] is already in DB
//
$fid = null; // global for newly-added flight
// Check default (flight count) Top 10 stats
class CheckTop10FlightCountStats extends WebTestCase {
function test() {
global $webroot, $settings, $flight2;
assert_login($this);
$top10 = $this->post($webroot . "php/top10.php");
$rows = preg_split('/\n/', $top10);
$this->assertTrue(sizeof($rows) == 4);
// Top 10 routes
$routes = $rows[0];
$this->assertPattern("/," . $flight2["src_apid"] . ",/", $routes);
$this->assertPattern("/," . $flight2["dst_apid"] . ",1/", $routes);
// Top 10 airports
$airports = $rows[1];
$this->assertPattern("/,1," . $flight2["src_apid"] . "/", $airports);
$this->assertPattern("/,1," . $flight2["dst_apid"] . "/", $airports);
// Top 10 airlines
$airlines = $rows[2];
$this->assertPattern("/,1," . $flight2["alid"] . "/", $airlines);
// Top 10 planes
$planes = $rows[3];
$this->assertPattern("/" . $flight2["plane"] . ",1/", $planes);
}
}
// Check flight count Top 10 stats with airline filtering
class CheckTop10AirlineFilteredFlightCountStats extends WebTestCase {
function test() {
global $webroot, $settings, $flight2;
assert_login($this);
$filter = array("alid" => $flight2["alid"]);
$top10 = $this->post($webroot . "php/top10.php", $filter);
$rows = preg_split('/\n/', $top10);
$this->assertTrue(sizeof($rows) == 4);
// Top 10 routes
$routes = $rows[0];
$this->assertPattern("/," . $flight2["src_apid"] . ",/", $routes);
$this->assertPattern("/," . $flight2["dst_apid"] . ",1/", $routes);
// Top 10 airports
$airports = $rows[1];
$this->assertPattern("/,1," . $flight2["src_apid"] . "/", $airports);
$this->assertPattern("/,1," . $flight2["dst_apid"] . "/", $airports);
// Top 10 airlines
$airlines = $rows[2];
$this->assertPattern("/,1," . $flight2["alid"] . "/", $airlines);
// Top 10 planes
$planes = $rows[3];
$this->assertPattern("/" . $flight2["plane"] . ",1/", $planes);
}
}
// Check by-distance Top 10 stats
class CheckTop10DistanceStats extends WebTestCase {
function test() {
global $webroot, $settings, $flight2;
assert_login($this);
$params = array("mode" => "D");
$top10 = $this->post($webroot . "php/top10.php", $params);
$rows = preg_split('/\n/', $top10);
$this->assertTrue(sizeof($rows) == 4);
$distance = $flight2["distance"];
// Top 10 routes
$routes = $rows[0];
$this->assertPattern("/," . $flight2["src_apid"] . ",/", $routes);
$this->assertPattern("/," . $flight2["dst_apid"] . ",$distance/", $routes);
// Top 10 airports
$airports = $rows[1];
$this->assertPattern("/,$distance," . $flight2["src_apid"] . "/", $airports);
$this->assertPattern("/,$distance," . $flight2["dst_apid"] . "/", $airports);
// Top 10 airlines
$airlines = $rows[2];
$this->assertPattern("/,$distance," . $flight2["alid"] . "/", $airlines);
// Top 10 planes
$planes = $rows[3];
$this->assertPattern("/" . $flight2["plane"] . ",$distance/", $planes);
}
}
?>