From f53e4522574e201796d5526b5f9e06e0ca506abb Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Tue, 12 Sep 2023 14:56:24 +0100 Subject: [PATCH] Various test related cleanup --- test/client/AirportSearchTest.php | 13 ++-- test/client/OpenFlightsSeleniumTestCase.php | 6 +- test/client/WebLoginTest.php | 13 ++-- test/client/WebMapPublicTest.php | 9 ++- test/server/README.md | 2 +- test/server/alsearch.php | 50 ++++++++++---- test/server/apsearch.php | 44 +++++++++---- test/server/autocomplete.php | 72 ++++++++++++--------- test/server/cleanup.php | 16 +++-- test/server/config.php | 23 ++++--- test/server/flights.php | 5 +- test/server/helper.php | 6 +- test/server/import.php | 20 ++++-- test/server/login.php | 18 ++++-- test/server/map.php | 31 ++++++--- test/server/planes.php | 11 ++-- test/server/routes.php | 44 +++++++++---- test/server/settings.php | 34 +++++++--- test/server/stats.php | 9 +-- test/server/submit.php | 41 ++++++++---- test/server/top10.php | 61 ++++++++++------- test/server/trip.php | 36 +++++++---- 22 files changed, 367 insertions(+), 197 deletions(-) diff --git a/test/client/AirportSearchTest.php b/test/client/AirportSearchTest.php index 2e78d930..773e1cdc 100644 --- a/test/client/AirportSearchTest.php +++ b/test/client/AirportSearchTest.php @@ -1,10 +1,9 @@ open("/html/apsearch"); @@ -21,8 +20,7 @@ public function testAnonAirportSearch() $this->assertValue("airport", $airport['name']); } - public function testAnonAirportSearchPreload() - { + public function testAnonAirportSearchPreload() { global $airport; $apid = db_apid(db_connect()); @@ -42,8 +40,7 @@ public function testAnonAirportSearchPreload() $this->assertValue("iata", ""); } - public function testLoggedInAirportEdit() - { + public function testLoggedInAirportEdit() { global $settings, $airport; $this->open('/'); diff --git a/test/client/OpenFlightsSeleniumTestCase.php b/test/client/OpenFlightsSeleniumTestCase.php index 2906a846..df1c3be3 100644 --- a/test/client/OpenFlightsSeleniumTestCase.php +++ b/test/client/OpenFlightsSeleniumTestCase.php @@ -4,14 +4,12 @@ include_once dirname(__FILE__) . '/../server/config.php'; -class OpenFlightsSeleniumTestCase extends Selenium2TestCase -{ +class OpenFlightsSeleniumTestCase extends Selenium2TestCase { protected $captureScreenshotOnFailure = true; protected $screenshotPath = '/tmp/screenshots'; protected $screenshotUrl = '/tmp/screenshots'; - protected function setUp(): void - { + protected function setUp(): void { $this->setBrowser('*firefox /Applications/Firefox.app/Contents/MacOS/firefox-bin'); $this->setBrowserUrl('http://openflights.local/'); $this->setSpeed(100); diff --git a/test/client/WebLoginTest.php b/test/client/WebLoginTest.php index 563f08b0..a26a3da0 100644 --- a/test/client/WebLoginTest.php +++ b/test/client/WebLoginTest.php @@ -1,10 +1,9 @@ open('/'); @@ -28,8 +27,7 @@ public function testFailedLogin() $this->click('close'); } - public function testSuccessfulLogin() - { + public function testSuccessfulLogin() { global $settings; $this->open('/'); @@ -45,8 +43,7 @@ public function testSuccessfulLogin() $this->verifyTextPresent("Add new flights"); } - public function testReload() - { + public function testReload() { global $settings; $this->open('/'); diff --git a/test/client/WebMapPublicTest.php b/test/client/WebMapPublicTest.php index b4e9cf6a..39563807 100644 --- a/test/client/WebMapPublicTest.php +++ b/test/client/WebMapPublicTest.php @@ -1,10 +1,9 @@ open("/user/" . $settings['name']); @@ -24,7 +23,7 @@ public function testPublicUserMapAsAnonymous() $this->click('link=Decatur Aviation'); $this->verifyTextPresent($settings['name'] . "'s flights on Decatur Aviation"); - # Back to main map + # Back to the main map $this->select('Airlines', 'label=All carriers'); $this->verifyTextPresent($settings['name'] . "'s flights"); } diff --git a/test/server/README.md b/test/server/README.md index c3a48de9..5e169182 100644 --- a/test/server/README.md +++ b/test/server/README.md @@ -6,7 +6,7 @@ This test suite validates PHP calls and MySQL database content. 1. `php composer.phar install` 2. Configure `config.php` 3. Run `php settings.php` to populate test user -4. Then run eg. `php login.php` to test login cases, _or_ +4. Then run e.g. `php login.php` to test login cases, _or_ 5. Load `/test/server/test_all.php` in a browser to test all. NOTE: Many cases are dependent on each other. Generally, run settings.php first, all cases afterward, and cleanup.php last. diff --git a/test/server/alsearch.php b/test/server/alsearch.php index 15a5d9c9..a0d8654e 100644 --- a/test/server/alsearch.php +++ b/test/server/alsearch.php @@ -6,7 +6,9 @@ $new_alid = null; $new_rlid = null; -// Try to add airline before logging in +/** + * Try to add airline before logging in + */ class RecordAirlineNotLoggedInTest extends WebTestCase { public function test() { global $webroot; @@ -17,7 +19,9 @@ public function test() { } } -// Try to reuse an existing airline's code +/** + * Try to reuse an existing airline's code + */ class RecordAirlineDuplicateICAOTest extends WebTestCase { public function test() { global $webroot, $airline; @@ -31,7 +35,9 @@ public function test() { } } -// Add new airline +/** + * Add new airline + */ class RecordNewAirlineTest extends WebTestCase { public function test() { global $webroot, $airline, $new_alid; @@ -49,7 +55,9 @@ public function test() { } } -// Try to record it again +/** + * Try to record it again + */ class RecordAirlineDuplicateTest extends WebTestCase { public function test() { global $webroot, $airline; @@ -62,7 +70,9 @@ public function test() { } } -// Add new railway +/** + * Add new railway + */ class RecordNewRailwayTest extends WebTestCase { public function test() { global $webroot, $railway, $new_rlid; @@ -78,7 +88,9 @@ public function test() { } } -// Try to add the railway again +/** + * Try to add the railway again + */ class RecordRailwayDuplicateTest extends WebTestCase { public function test() { global $webroot, $railway; @@ -91,14 +103,16 @@ public function test() { } } -// Try to edit an airline not belonging to us +/** + * Try to edit an airline not belonging to us + */ class EditWrongAirlineTest extends WebTestCase { public function test() { global $webroot, $airline; login($this); $params = $airline; - $params["alid"] = 1; // this is presumably not owned by us + $params["alid"] = 1; // this airline should not be "owned" by this user $params["icao"] = "ZZZY"; $params += array("action" => "RECORD"); $msg = $this->post($webroot . "php/alsearch.php", $params); @@ -106,7 +120,9 @@ public function test() { } } -// Try to reuse an existing airline's code +/** + * Try to reuse an existing airline's code + */ class EditAirlineDuplicateICAOTest extends WebTestCase { public function test() { global $webroot, $airline, $new_alid; @@ -121,7 +137,9 @@ public function test() { } } -// Try to edit to overwrite existing airline +/** + * Try to edit to overwrite existing airline + */ class EditAirlineSuccessfulTest extends WebTestCase { public function test() { global $webroot, $airline, $new_alid; @@ -137,7 +155,9 @@ public function test() { } -// Search by IATA +/** + * Search for an airline by IATA code + */ class SearchAirlineByIATATest extends WebTestCase { public function test() { global $webroot, $airline; @@ -156,7 +176,9 @@ public function test() { } } -// Search by ICAO +/** + * Search for an airline by ICAO code + */ class SearchAirlineByICAOTest extends WebTestCase { public function test() { global $webroot, $airline; @@ -172,7 +194,9 @@ public function test() { } } -// Search railway by name +/** + * Search railway by name + */ class SearchRailwayByNameTest extends WebTestCase { public function test() { global $webroot, $railway; diff --git a/test/server/apsearch.php b/test/server/apsearch.php index 0a0cbcec..33171c8b 100644 --- a/test/server/apsearch.php +++ b/test/server/apsearch.php @@ -5,7 +5,9 @@ // Store temporary airport ID $new_apid = null; -// Check that we can load up the country data +/** + * Check that we can load up the country data + */ class LoadCountriesTest extends WebTestCase { public function test() { global $webroot; @@ -17,7 +19,9 @@ public function test() { } } -// Try to add airport before logging in +/** + * Try to add an airport before logging in + */ class RecordAirportNotLoggedInTest extends WebTestCase { public function test() { global $webroot; @@ -28,7 +32,9 @@ public function test() { } } -// Add new airport +/** + * Add new airport + */ class RecordNewAirportTest extends WebTestCase { public function test() { global $webroot, $airport, $new_apid; @@ -42,7 +48,9 @@ public function test() { } } -// Try to add it again +/** + * Try to add it again + */ class RecordAirportDuplicateTest extends WebTestCase { public function test() { global $webroot, $airport; @@ -58,7 +66,9 @@ public function test() { } } -// Try to edit an airport not belonging to us +/** + * Try to edit an airport not belonging to us + */ class EditWrongAirportTest extends WebTestCase { public function test() { global $webroot, $airport; @@ -77,7 +87,9 @@ public function test() { } } -// Try to reuse an existing airport's code +/** + * Try to reuse an existing airport's code + */ class EditAirportDuplicateICAOTest extends WebTestCase { public function test() { global $webroot, $airport, $new_apid; @@ -95,7 +107,9 @@ public function test() { } } -// Try to edit to overwrite existing airport +/** + * Try to edit to overwrite existing airport + */ class EditAirportSuccessfulTest extends WebTestCase { public function test() { global $webroot, $airport, $new_apid; @@ -111,7 +125,9 @@ public function test() { } } -// Add new location with null codes +/** + * Add new location with null codes + */ class RecordNewNullCodePlaceTest extends WebTestCase { public function test() { global $webroot, $settings, $airport, $new_apid; @@ -144,7 +160,9 @@ public function test() { } } -// Load a single airport +/** + * Load a single airport + */ class LoadAirportByApidTest extends WebTestCase { public function test() { global $webroot, $airport, $new_apid; @@ -171,7 +189,9 @@ public function test() { } } -// Load a single airport +/** + * Load a single airport + */ class LoadAirportByInvalidApidTest extends WebTestCase { public function test() { global $webroot; @@ -185,7 +205,9 @@ public function test() { } } -// Search OpenFlights DB by IATA (of just-added airport) +/** + * Search OpenFlights DB by IATA code (of just-added airport) + */ class SearchAirportOFDBByIATATest extends WebTestCase { public function test() { global $webroot, $airport; diff --git a/test/server/autocomplete.php b/test/server/autocomplete.php index 44333be7..7d43c9a2 100644 --- a/test/server/autocomplete.php +++ b/test/server/autocomplete.php @@ -4,11 +4,9 @@ // Testing the tests: curl -v http://localhost:8080/php/autocomplete.php -d qs=STRING -// -// MULTISEARCH -// - -// Search for string found in both airport and airline name +/** + * Search for string found in both airport and airline name + */ class MultiSearchSharedLongStringTest extends WebTestCase { public function test() { global $webroot, $qs_string; @@ -23,7 +21,9 @@ public function test() { } } -// Search for string found only in airport name +/** + * Search for string found only in airport name + */ class MultiSearchAirportOnlyLongStringTest extends WebTestCase { public function test() { global $webroot; @@ -36,7 +36,9 @@ public function test() { } } -// Search for string found in only airline name +/** + * Search for string found in only airline name + */ class MultiSearchAirlineOnlyLongStringTest extends WebTestCase { public function test() { global $webroot; @@ -49,7 +51,9 @@ public function test() { } } -// Search for airport by IATA +/** + * Search for airport by IATA + */ class MultiSearchAirportIATATest extends WebTestCase { public function test() { global $webroot, $airport; @@ -62,7 +66,9 @@ public function test() { } } -// Search for airline by IATA +/** + * Search for airline by IATA + */ class MultiSearchAirlineIATATest extends WebTestCase { public function test() { global $webroot; @@ -75,11 +81,9 @@ public function test() { } } -// -// AIRPORTS -// - -// Single airport search by short city name +/** + * Single airport search by short city name + */ class SingleAirportShortCityCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -90,7 +94,9 @@ public function test() { } } -// Single airport search by long city name +/** + * Single airport search by long city name + */ class SingleAirportCityLongCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -101,7 +107,9 @@ public function test() { } } -// Single airport search by IATA code +/** + * Single airport search by IATA code + */ class SingleAirportIATACompleteTest extends WebTestCase { public function test() { global $webroot, $airport; @@ -112,7 +120,9 @@ public function test() { } } -// Single airport search by ICAO code +/** + * Single airport search by ICAO code + */ class SingleAirportICAOCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -123,7 +133,9 @@ public function test() { } } -// Ensure that autocompleted entries still match after minor edits +/** + * Ensure that autocompleted entries still match after minor edits + */ class SingleAirportQueryTrimTest extends WebTestCase { public function test() { global $webroot; @@ -142,11 +154,9 @@ public function test() { } } -// -// AIRLINES -// - -// Single airline search by name +/** + * Single airline search by name + */ class SingleAirlineNameCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -158,7 +168,9 @@ public function test() { } } -// Single airline search by alias +/** + * Single airline search by alias + */ class SingleAirlineAliasCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -170,7 +182,9 @@ public function test() { } } -// Single airline search by IATA code +/** + * Single airline search by IATA code + */ class SingleAirlineIATACompleteTest extends WebTestCase { public function test() { global $webroot; @@ -182,7 +196,9 @@ public function test() { } } -// Single airline search by ICAO code +/** + * Single airline search by ICAO code + */ class SingleAirlineICAOCompleteTest extends WebTestCase { public function test() { global $webroot; @@ -194,10 +210,6 @@ public function test() { } } -// -// PLANES -// - class SinglePlaneMajorNameCompleteTest extends WebTestCase { public function test() { global $webroot; diff --git a/test/server/cleanup.php b/test/server/cleanup.php index 8c9aab21..9ea3f84b 100644 --- a/test/server/cleanup.php +++ b/test/server/cleanup.php @@ -2,7 +2,9 @@ include_once dirname(__FILE__) . '/config.php'; -// Not an actual test, just cleaning up +/** + * Not an actual test, just cleaning up + */ class DeleteFlightsTest extends WebTestCase { public function test() { global $settings; @@ -14,7 +16,9 @@ public function test() { } } -// Not an actual test, just cleaning up +/** + * Not an actual test, just cleaning up + */ class DeleteAirportTest extends WebTestCase { public function test() { global $settings; @@ -26,7 +30,9 @@ public function test() { } } -// Not an actual test, just cleaning up +/** + * Not an actual test, just cleaning up + */ class DeleteAirlinesTest extends WebTestCase { public function test() { global $settings; @@ -38,7 +44,9 @@ public function test() { } } -// Not an actual test, just cleaning up +/** + * Not an actual test, just cleaning up + */ class DeleteUserTest extends WebTestCase { public function test() { global $settings; diff --git a/test/server/config.php b/test/server/config.php index 11add5c1..5654dcf8 100644 --- a/test/server/config.php +++ b/test/server/config.php @@ -3,7 +3,7 @@ require_once dirname(__FILE__) . '/../../vendor/simpletest/simpletest/autorun.php'; require_once dirname(__FILE__) . '/../../vendor/simpletest/simpletest/web_tester.php' ; -// Address of OpenFlights install +// URL of the OpenFlights install $webroot = 'http://localhost:8080/'; // Path to OpenFlights upload directory @@ -180,9 +180,16 @@ // *** END OF CONFIGURATION *** -// Login -// Use default settings unless name/password are given as arguments - +/** + * Use default settings unless name/password are given as arguments + * + * @param $case + * @param $name + * @param $password + * @param $challenge + * + * @return mixed + */ function login($case, $name = null, $password = null, $challenge = null) { global $webroot, $settings; @@ -215,7 +222,7 @@ function assert_login($case) { } /** - * Get a connection to the database + * Get a connection to the database. * * @return PDO OpenFlights test suite DB handler */ @@ -231,7 +238,7 @@ function db_connect() { } /** - * Get test user's UID + * Get test user's UID. * * @param $dbh PDO OpenFlights test suite DB handler * @return string UID of test user @@ -245,10 +252,10 @@ function db_uid($dbh) { } /** - * Get apid of test airport + * Get the Airport ID of a test airport * * @param $dbh PDO OpenFlights test suite DB handler - * @return string APID of test airport + * @return string Airport ID of test airport */ function db_apid($dbh) { global $airport; diff --git a/test/server/flights.php b/test/server/flights.php index 6ad16316..98eef3a1 100644 --- a/test/server/flights.php +++ b/test/server/flights.php @@ -2,10 +2,11 @@ include_once dirname(__FILE__) . '/config.php'; -// // Test cases for php/flights.php -// Check demo user map +/** + * Check demo user map + */ class BlockAnonExportCase extends WebTestCase { public function test() { global $webroot; diff --git a/test/server/helper.php b/test/server/helper.php index 45420bfa..b8719d8c 100644 --- a/test/server/helper.php +++ b/test/server/helper.php @@ -4,9 +4,7 @@ // Requires: none -// // HELPER -// require_once dirname(__FILE__) . '/../../php/helper.php'; @@ -79,7 +77,9 @@ public function test() { } } -// ##TODO## Extend +/** + * @todo Extend + */ class GcDistanceTest extends UnitTestCase { public function test() { $dbh = db_connect(); diff --git a/test/server/import.php b/test/server/import.php index da675900..31e4e583 100644 --- a/test/server/import.php +++ b/test/server/import.php @@ -57,7 +57,9 @@ public function test() { } } -// Import a normal set of FM flights +/** + * Import a normal set of Flight Memory flights + */ class ImportFlightMemoryStandardTest extends WebTestCase { public function test() { cleanup(); @@ -72,7 +74,9 @@ public function test() { } } -// Import a set of FM flights with data in km +/** + * Import a set of FM flights with data in km + */ class ImportFlightMemoryKilometerTest extends WebTestCase { public function test() { cleanup(); @@ -87,7 +91,9 @@ public function test() { } } -// Import a set of FM flights with Latin1 data +/** + * Import a set of FM flights with Latin1 data + */ class ImportFlightMemoryLatin1Test extends WebTestCase { public function test() { cleanup(); @@ -102,7 +108,9 @@ public function test() { } } -// Import a set of FM flights with new airlines +/** + * Import a set of FM flights with new airlines + */ class ImportFlightMemoryNewAirlinesTest extends WebTestCase { public function test() { cleanup(); @@ -117,7 +125,9 @@ public function test() { } } -// Import a set of FM flights using slightly tweaked 2015 format +/** + * Import a set of FM flights using slightly tweaked 2015 format + */ class ImportFlightMemoryNewStyleTest extends WebTestCase { public function test() { cleanup(); diff --git a/test/server/login.php b/test/server/login.php index 9b77889d..a7b1636b 100644 --- a/test/server/login.php +++ b/test/server/login.php @@ -1,11 +1,11 @@ prepare("UPDATE users SET public='N', guestpw = ? WHERE name = ?"); @@ -72,14 +77,18 @@ public function test() { } } -// View private profile with correct password +/** + * 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"]); + $params = array( + "param" => "true", + "guestpw" => $settings["guestpw"], + "user" => $settings["name"] + ); $map = $this->post($webroot . "php/map.php", $params); $rows = explode("\n", $map); @@ -93,7 +102,9 @@ public function test() { } } -// Check logged in user map +/** + * Check logged in user map + */ class CheckLoggedInFullUserMap extends WebTestCase { public function test() { global $webroot, $settings, $flight2; diff --git a/test/server/planes.php b/test/server/planes.php index 8d041489..f41846a8 100644 --- a/test/server/planes.php +++ b/test/server/planes.php @@ -1,13 +1,14 @@ prepare("SELECT DISTINCT src_apid,dst_apid FROM routes WHERE src_ap = ?"); + $sth = $dbh->prepare("SELECT DISTINCT src_apid, dst_apid FROM routes WHERE src_ap = ?"); $sth->execute([$route["core_ap_iata"]]); $rows = $sth->rowCount(); $this->assertTrue($rows >= 1, "No routes found"); @@ -43,14 +47,16 @@ public function test() { } } -// Fetch route map for core airport with airline filter +/** + * Fetch the route map for core airport with airline filter + */ class RouteMapCoreAirportFilteredTest extends WebTestCase { public function test() { global $webroot, $route; // First figure out the correct results $dbh = db_connect(); - $sth = $dbh->prepare("SELECT DISTINCT src_apid,dst_apid,alid FROM routes WHERE src_ap = ? AND airline = ?"); + $sth = $dbh->prepare("SELECT DISTINCT src_apid, dst_apid, alid FROM routes WHERE src_ap = ? AND airline = ?"); $sth->execute([$route["core_ap_iata"], $route["core_ap_filter_iata"]]); $rows = $sth->rowCount(); $this->assertTrue($rows >= 1, "No routes found"); @@ -78,7 +84,9 @@ public function test() { } } -// Airport with no routes -- should still display itself! +/** + * Airport with no routes -- should still display itself! + */ class RouteMapNoRouteAirportTest extends WebTestCase { public function test() { global $webroot, $route; @@ -108,7 +116,9 @@ public function test() { } } -// Invalid airport ID +/** + * Invalid airport ID + */ class RouteMapInvalidAirportTest extends WebTestCase { public function test() { global $webroot, $route; @@ -119,7 +129,9 @@ public function test() { } } -// Fetch route map for core airline +/** + * Fetch the route map for core airline + */ class RouteMapCoreAirlineTest extends WebTestCase { public function test() { global $webroot, $route; @@ -150,14 +162,16 @@ public function test() { } } -// Fetch route map for core airline +/** + * Fetch route map for core airline + */ class RouteMapCoreAirlineWithCodesharesTest extends WebTestCase { public function test() { global $webroot, $route; // First figure out the correct results $dbh = db_connect(); - $sth = $dbh->prepare("SELECT DISTINCT src_apid,dst_apid,alid FROM routes WHERE airline = ?"); + $sth = $dbh->prepare("SELECT DISTINCT src_apid, dst_apid, alid FROM routes WHERE airline = ?"); $sth->execute([$route["core_al_iata"]]); $rows = $sth->rowCount(); $this->assertTrue($rows >= 1, "No routes found"); @@ -184,12 +198,14 @@ public function test() { } } -// Airline with no routes +/** + * Airline with no routes + */ class RouteMapNoRouteAirlineTest extends WebTestCase { public function test() { global $webroot, $route; - // First figure out the correct apid + // First figure out the correct airport id $dbh = db_connect(); $sth = $dbh->prepare("SELECT * FROM airlines WHERE iata = ?"); $sth->execute([$route["noroute_al_iata"]]); @@ -213,7 +229,9 @@ public function test() { } } -// Invalid airline ID +/** + * Invalid airline ID + */ class RouteMapInvalidAirlineTest extends WebTestCase { public function test() { global $webroot, $route; diff --git a/test/server/settings.php b/test/server/settings.php index 90b6d5d0..baff55b0 100644 --- a/test/server/settings.php +++ b/test/server/settings.php @@ -2,12 +2,12 @@ include_once dirname(__FILE__) . '/config.php'; -// // Test cases for php/settings.php // NB: Assumes there is no existing test user (run cleanup.php first!) -// -// Create new user +/** + * Create new user + */ class SuccessfulNewUserTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -20,7 +20,9 @@ public function test() { } } -// Duplicate name +/** + * Duplicate username + */ class DuplicateUserTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -33,7 +35,9 @@ public function test() { } } -// Try to manipulate without session +/** + * Try to manipulate without a session + */ class LoadEditResetWithoutSessionTest extends WebTestCase { public function test() { global $webroot; @@ -48,7 +52,9 @@ public function test() { } } -// Try to change pw, but give wrong password +/** + * Try to change pw, but give the wrong password + */ class ChangePasswordWithWrongOldPasswordTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -68,7 +74,9 @@ public function test() { } } -// Change password +/** + * Change password + */ class ChangePasswordTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -99,7 +107,9 @@ public function test() { } } -// Change all other settings +/** + * Change all other settings + */ class ChangeSettingsTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -129,7 +139,9 @@ public function test() { } } -// Restore original settings +/** + * Restore original settings + */ class RestoreSettingsTest extends WebTestCase { public function test() { global $webroot, $settings; @@ -141,7 +153,9 @@ public function test() { } } -// Reset (delete) all flights +/** + * Reset (delete) all flights + */ class ResetFlightsTest extends WebTestCase { public function test() { global $webroot; diff --git a/test/server/stats.php b/test/server/stats.php index 560b2059..2273620f 100644 --- a/test/server/stats.php +++ b/test/server/stats.php @@ -1,14 +1,15 @@ assertTrue($cols[0] == "1", "One flight recorded"); - // Get the ID of the newly-added flight + // Get the ID of the newly added flight $dbh = db_connect(); $sth = $dbh->prepare("SELECT fid FROM flights WHERE note = ?"); $sth->execute([$flight["note"]]); @@ -89,7 +98,9 @@ public function test() { } } -// Fetch and validate newly-added flight +/** + * Fetch and validate newly added flight + */ class FetchAddSingleFlightTest extends WebTestCase { public function test() { global $webroot, $flight, $fid; @@ -116,7 +127,9 @@ public function test() { } } -// Edit new flight, altering all fields into flight2 +/** + * Edit new flight, altering all fields into flight2 + */ class EditFlightTest extends WebTestCase { public function test() { global $webroot, $flight2, $fid; @@ -130,7 +143,9 @@ public function test() { } } -// Fetch and validate newly-added flight +/** + * Fetch and validate newly added flight + */ class FetchEditedFlightTest extends WebTestCase { public function test() { global $webroot, $flight2, $fid; @@ -157,7 +172,9 @@ public function test() { } } -// CSV export and validate edited flight +/** + * CSV export and validate edited flight + */ class CSVExportFlightTest extends WebTestCase { public function test() { global $webroot, $flight2; diff --git a/test/server/top10.php b/test/server/top10.php index 95abbdd2..932700d6 100644 --- a/test/server/top10.php +++ b/test/server/top10.php @@ -2,14 +2,19 @@ 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 +$fid = null; // global for newly added flight -// Return first value matching $pred or null if no matches +/** + * Return first value matching $pred or null if no matches + * + * @param $array + * @param $pred + * + * @return mixed|null + */ function array_find($array, $pred) { foreach ($array as $value) { if ($pred($value)) { @@ -19,7 +24,9 @@ function array_find($array, $pred) { return null; } -// Check default (flight count) Top 10 stats +/** + * Check default (flight count) Top 10 stats + */ class CheckTop10FlightCountStats extends WebTestCase { public function test() { global $webroot, $settings, $flight2; @@ -35,38 +42,38 @@ public function test() { $this->assertTrue(array_key_exists("planes", $json)); // Top 10 routes - $route_src = array_find($json["routes"], function($val) use ($flight2) { + $route_src = array_find($json["routes"], function ($val) use ($flight2) { return $val["src_apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($route_src, null); $this->assertEqual($route_src["count"], 1); - $route_dst = array_find($json["routes"], function($val) use ($flight2) { + $route_dst = array_find($json["routes"], function ($val) use ($flight2) { return $val["dst_apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($route_dst, null); $this->assertEqual($route_dst["count"], 1); // Top 10 airports - $airport_src = array_find($json["airports"], function($val) use ($flight2) { + $airport_src = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($airport_src, null); $this->assertEqual($airport_src["count"], 1); - $airport_dst = array_find($json["airports"], function($val) use ($flight2) { + $airport_dst = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($airport_dst, null); $this->assertEqual($airport_dst["count"], 1); // Top 10 airlines - $airline = array_find($json["airlines"], function($val) use ($flight2) { + $airline = array_find($json["airlines"], function ($val) use ($flight2) { return $val["alid"] == $flight2["alid"]; }); $this->assertNotEqual($airline, null); $this->assertEqual($airline["count"], 1); // Top 10 planes - $plane = array_find($json["planes"], function($val) use ($flight2) { + $plane = array_find($json["planes"], function ($val) use ($flight2) { return $val["name"] == $flight2["plane"]; }); $this->assertNotEqual($plane, null); @@ -74,7 +81,9 @@ public function test() { } } -// Check flight count Top 10 stats with airline filtering +/** + * Check flight count Top 10 stats with airline filtering + */ class CheckTop10AirlineFilteredFlightCountStats extends WebTestCase { public function test() { global $webroot, $settings, $flight2; @@ -92,38 +101,38 @@ public function test() { $this->assertTrue(array_key_exists("planes", $json)); // Top 10 routes - $route_src = array_find($json["routes"], function($val) use ($flight2) { + $route_src = array_find($json["routes"], function ($val) use ($flight2) { return $val["src_apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($route_src, null); $this->assertEqual($route_src["count"], 1); - $route_dst = array_find($json["routes"], function($val) use ($flight2) { + $route_dst = array_find($json["routes"], function ($val) use ($flight2) { return $val["dst_apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($route_dst, null); $this->assertEqual($route_dst["count"], 1); // Top 10 airports - $airport_src = array_find($json["airports"], function($val) use ($flight2) { + $airport_src = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($airport_src, null); $this->assertEqual($airport_src["count"], 1); - $airport_dst = array_find($json["airports"], function($val) use ($flight2) { + $airport_dst = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($airport_dst, null); $this->assertEqual($airport_dst["count"], 1); // Top 10 airlines - $airline = array_find($json["airlines"], function($val) use ($flight2) { + $airline = array_find($json["airlines"], function ($val) use ($flight2) { return $val["alid"] == $flight2["alid"]; }); $this->assertNotEqual($airline, null); $this->assertEqual($airline["count"], 1); // Top 10 planes - $plane = array_find($json["planes"], function($val) use ($flight2) { + $plane = array_find($json["planes"], function ($val) use ($flight2) { return $val["name"] == $flight2["plane"]; }); $this->assertNotEqual($plane, null); @@ -131,7 +140,9 @@ public function test() { } } -// Check by-distance Top 10 stats +/** + * Check by-distance Top 10 stats + */ class CheckTop10DistanceStats extends WebTestCase { public function test() { global $webroot, $settings, $flight2; @@ -151,38 +162,38 @@ public function test() { $this->assertTrue(array_key_exists("planes", $json)); // Top 10 routes - $route_src = array_find($json["routes"], function($val) use ($flight2) { + $route_src = array_find($json["routes"], function ($val) use ($flight2) { return $val["src_apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($route_src, null); $this->assertEqual($route_src["count"], $distance); - $route_dst = array_find($json["routes"], function($val) use ($flight2) { + $route_dst = array_find($json["routes"], function ($val) use ($flight2) { return $val["dst_apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($route_dst, null); $this->assertEqual($route_dst["count"], $distance); // Top 10 airports - $airport_src = array_find($json["airports"], function($val) use ($flight2) { + $airport_src = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["src_apid"]; }); $this->assertNotEqual($airport_src, null); $this->assertEqual($airport_src["count"], $distance); - $airport_dst = array_find($json["airports"], function($val) use ($flight2) { + $airport_dst = array_find($json["airports"], function ($val) use ($flight2) { return $val["apid"] == $flight2["dst_apid"]; }); $this->assertNotEqual($airport_dst, null); $this->assertEqual($airport_dst["count"], $distance); // Top 10 airlines - $airline = array_find($json["airlines"], function($val) use ($flight2) { + $airline = array_find($json["airlines"], function ($val) use ($flight2) { return $val["alid"] == $flight2["alid"]; }); $this->assertNotEqual($airline, null); $this->assertEqual($airline["count"], $distance); // Top 10 planes - $plane = array_find($json["planes"], function($val) use ($flight2) { + $plane = array_find($json["planes"], function ($val) use ($flight2) { return $val["name"] == $flight2["plane"]; }); $this->assertNotEqual($plane, null); diff --git a/test/server/trip.php b/test/server/trip.php index 501bb2b8..a6869847 100644 --- a/test/server/trip.php +++ b/test/server/trip.php @@ -2,13 +2,13 @@ include_once dirname(__FILE__) . '/config.php'; -// // Test cases for php/trip.php -// $trid = null; -// Create new trip without logging in +/** + * Create a new trip without logging in + */ class NewTripNotLoggedInTest extends WebTestCase { public function test() { global $webroot, $trip; @@ -19,7 +19,9 @@ public function test() { } } -// Create new trip +/** + * Create a new trip + */ class SuccessfulNewTripTest extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -34,7 +36,9 @@ public function test() { } } -// Try to edit when not logged in +/** + * Try to edit when not logged in + */ class EditTripWithoutLoggingInTest extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -46,7 +50,9 @@ public function test() { } } -// Try to manipulate wrong trip id +/** + * Try to manipulate the wrong trip id + */ class EditWrongTridTripTest extends WebTestCase { public function test() { global $webroot, $trip; @@ -59,7 +65,9 @@ public function test() { } } -// Check public trip +/** + * Check a public trip + */ class CheckPublicFullTripMap extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -79,7 +87,9 @@ public function test() { } } -// Change trip settings +/** + * Change trip settings + */ class SuccessfulEditTripTest extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -106,7 +116,7 @@ public function test() { } } -// Check private trip (should fail) +/** Check loading a private trip; it should fail */ class CheckPrivateFullTripMap extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -119,7 +129,9 @@ public function test() { } } -// Check invalid trid trip map (should fail) +/** + * Check an invalid Trip ID trip map; it should fail + */ class CheckNonExistentFullTripMap extends WebTestCase { public function test() { global $webroot, $trip, $trid; @@ -132,7 +144,9 @@ public function test() { } } -// Delete trip +/** + * Delete trip + */ class DeleteTripTest extends WebTestCase { public function test() { global $webroot, $trip, $trid;