Skip to content

Commit

Permalink
Various test related cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
reedy committed Oct 19, 2023
1 parent aa1725c commit f53e452
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 197 deletions.
13 changes: 5 additions & 8 deletions test/client/AirportSearchTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

include_once dirname(__FILE__) . '/OpenFlightsSeleniumTestCase.php';

class AirportSearchTest extends OpenFlightsSeleniumTestCase
{
public function testAnonAirportSearch()
{
class AirportSearchTest extends OpenFlightsSeleniumTestCase {
public function testAnonAirportSearch() {
global $airport;

$this->open("/html/apsearch");
Expand All @@ -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());
Expand All @@ -42,8 +40,7 @@ public function testAnonAirportSearchPreload()
$this->assertValue("iata", "");
}

public function testLoggedInAirportEdit()
{
public function testLoggedInAirportEdit() {
global $settings, $airport;

$this->open('/');
Expand Down
6 changes: 2 additions & 4 deletions test/client/OpenFlightsSeleniumTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions test/client/WebLoginTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

include_once dirname(__FILE__) . '/OpenFlightsSeleniumTestCase.php';

class WebLoginTest extends OpenFlightsSeleniumTestCase
{
public function testFailedLogin()
{
class WebLoginTest extends OpenFlightsSeleniumTestCase {
public function testFailedLogin() {
global $settings;

$this->open('/');
Expand All @@ -28,8 +27,7 @@ public function testFailedLogin()
$this->click('close');
}

public function testSuccessfulLogin()
{
public function testSuccessfulLogin() {
global $settings;

$this->open('/');
Expand All @@ -45,8 +43,7 @@ public function testSuccessfulLogin()
$this->verifyTextPresent("Add new flights");
}

public function testReload()
{
public function testReload() {
global $settings;

$this->open('/');
Expand Down
9 changes: 4 additions & 5 deletions test/client/WebMapPublicTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

include_once dirname(__FILE__) . '/OpenFlightsSeleniumTestCase.php';

class WebMapPublicTest extends OpenFlightsSeleniumTestCase
{
public function testPublicUserMapAsAnonymous()
{
class WebMapPublicTest extends OpenFlightsSeleniumTestCase {
public function testPublicUserMapAsAnonymous() {
global $settings;

$this->open("/user/" . $settings['name']);
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion test/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
50 changes: 37 additions & 13 deletions test/server/alsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -91,22 +103,26 @@ 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);
$this->assertText('0;');
}
}

// 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
44 changes: 33 additions & 11 deletions test/server/apsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -171,7 +189,9 @@ public function test() {
}
}

// Load a single airport
/**
* Load a single airport
*/
class LoadAirportByInvalidApidTest extends WebTestCase {
public function test() {
global $webroot;
Expand All @@ -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;
Expand Down
Loading

0 comments on commit f53e452

Please sign in to comment.