-
Notifications
You must be signed in to change notification settings - Fork 399
/
planes.php
66 lines (53 loc) · 2.1 KB
/
planes.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
<?php
include_once dirname(__FILE__) . '/config.php';
// Test cases for php/submit.php plane related functionality
// NB: Assumes the test user exists and there are no flights entered yet (run settings.php first!)
$plid = null; // global for newly added flight
/**
* Add a new plane
*/
class AddNewPlaneTest extends WebTestCase {
public function test() {
global $webroot, $settings, $flight, $plid;
assert_login($this);
$dbh = db_connect();
$flight2 = $flight; // this creates a new array copy because PHP is cray-cray
$flight2["plane"] = "Boeingbus XYZ";
$flight2["note"] = "Firstplane";
$msg = $this->post($webroot . "php/submit.php", $flight2);
$this->assertText('1;');
// Check the PLID of the newly-added flight
$sth = $dbh->prepare("SELECT plid FROM flights WHERE note = ?");
$sth->execute([$flight2["note"]]);
$row = $sth->fetch();
$plid = $row["plid"];
$this->assertTrue($plid != null && $plid != "");
// Add a new flights with the same plane, but with random whitespace
$flight3 = $flight2;
$flight3["plane"] = " Boeingbus XYZ ";
$flight3["note"] = "Secondplane";
$msg = $this->post($webroot . "php/submit.php", $flight3);
$this->assertText('1;');
// Check that new plid was reused
$sth = $dbh->prepare("SELECT plid FROM flights WHERE note = ?");
$sth->execute([$flight3["note"]]);
$row = $sth->fetch();
$plid2 = $row["plid"];
$this->assertEqual($plid, $plid2);
}
}
/**
* Not an actual test, just cleaning up
*/
class DeleteExtraPlanesTest extends WebTestCase {
public function test() {
global $settings, $plid;
$dbh = db_connect();
$sth = $dbh->prepare("DELETE FROM flights WHERE plid = ?");
$sth->execute([$plid]);
$this->assertTrue($sth->rowCount() >= 1, "Flight deleted");
$sth = $dbh->prepare("DELETE FROM planes WHERE name = 'Boeingbus XYZ'");
$sth->execute();
$this->assertTrue($sth->rowCount() >= 1, "Plane deleted");
}
}