Skip to content

Commit

Permalink
Type SETUP/tests/unittests/
Browse files Browse the repository at this point in the history
The PR is mostly typing the test functions
that should be returning `void`.
  • Loading branch information
jchaffraix authored and cpeel committed Dec 11, 2024
1 parent 9fba0b2 commit 84546f7
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 309 deletions.
85 changes: 43 additions & 42 deletions SETUP/tests/unittests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function wordcheck_report(string $projectid, string $page_name, array
//---------------------------------------------------------------------------
// tests

public function test_get_invalid_project_info()
public function test_get_invalid_project_info(): void
{
$this->expectExceptionCode(101);

Expand All @@ -107,7 +107,7 @@ public function test_get_invalid_project_info()
$router->route($path, $query_params);
}

public function test_get_invalid_round_stats()
public function test_get_invalid_round_stats(): void
{
$this->expectExceptionCode(103);

Expand All @@ -118,7 +118,7 @@ public function test_get_invalid_round_stats()
$router->route($path, $query_params);
}

public function test_get_invalid_page_data()
public function test_get_invalid_page_data(): void
{
$this->expectExceptionCode(104);

Expand All @@ -130,7 +130,7 @@ public function test_get_invalid_page_data()
$router->route($path, $query_params);
}

public function test_get_invalid_pageround_data()
public function test_get_invalid_pageround_data(): void
{
$this->expectExceptionCode(105);

Expand All @@ -144,7 +144,7 @@ public function test_get_invalid_pageround_data()
$router->route($path, $query_params);
}

public function test_get_valid_pageround_data()
public function test_get_valid_pageround_data(): void
{
$project = $this->_create_project();
$this->add_page($project, "001");
Expand All @@ -159,7 +159,7 @@ public function test_get_valid_pageround_data()
$this->assertEquals("P1.page_avail", $result["state"]);
}

public function test_create_project_unauthorised()
public function test_create_project_unauthorised(): void
{
$this->expectExceptionCode(3);

Expand All @@ -170,7 +170,7 @@ public function test_create_project_unauthorised()
$router->route($path, $query_params);
}

public function test_create_project_no_data()
public function test_create_project_no_data(): void
{
global $pguser;
$this->expectExceptionCode(100);
Expand All @@ -183,7 +183,7 @@ public function test_create_project_no_data()
$router->route($path, $query_params);
}

public function test_get_page_data()
public function test_get_page_data(): void
{
global $pguser;
$pguser = $this->TEST_USERNAME;
Expand All @@ -201,7 +201,7 @@ public function test_get_page_data()
//---------------------------------------------------------------------------
// tests for proofreading

public function test_checkout_bad_projectid()
public function test_checkout_bad_projectid(): void
{
global $pguser;
$pguser = $this->TEST_USERNAME;
Expand All @@ -211,7 +211,7 @@ public function test_checkout_bad_projectid()
$this->checkout("projectId", "P1.proj_avail");
}

public function test_checkout_invalid_proj_state()
public function test_checkout_invalid_proj_state(): void
{
global $pguser;
$pguser = $this->TEST_USERNAME;
Expand All @@ -222,7 +222,7 @@ public function test_checkout_invalid_proj_state()
$this->checkout($project->projectid, "project_ne");
}

public function test_project_no_state_given()
public function test_project_no_state_given(): void
{
global $pguser;

Expand All @@ -237,7 +237,7 @@ public function test_project_no_state_given()
$router->route($path, []);
}

public function test_checkout_wrong_proj_state()
public function test_checkout_wrong_proj_state(): void
{
global $pguser;
$pguser = $this->TEST_USERNAME;
Expand All @@ -248,7 +248,7 @@ public function test_checkout_wrong_proj_state()
$this->checkout($project->projectid, "P1.proj_bad");
}

public function test_project_not_in_round()
public function test_project_not_in_round(): void
{
global $pguser;

Expand All @@ -260,7 +260,7 @@ public function test_project_not_in_round()
$this->checkout($project->projectid, "project_new");
}

public function test_project_unavailable()
public function test_project_unavailable(): void
{
global $pguser;

Expand All @@ -273,7 +273,7 @@ public function test_project_unavailable()
$this->checkout($project->projectid, "P1.proj_unavail");
}

public function test_user_not_qualified_for_round()
public function test_user_not_qualified_for_round(): void
{
global $pguser;
$pguser = $this->TEST_USERNAME;
Expand All @@ -289,7 +289,7 @@ public function test_user_not_qualified_for_round()
$this->checkout($project->projectid, "P2.proj_avail");
}

public function test_project_checkout_available()
public function test_project_checkout_available(): void
{
global $pguser;

Expand All @@ -310,7 +310,7 @@ public function test_project_checkout_available()
$this->assertEquals($expected, $response);
}

public function test_many_pages_few_days()
public function test_many_pages_few_days(): void
{
// user done many pages but few days on site
// $page_tally_threshold 500 for new projects in reserve time
Expand All @@ -323,7 +323,7 @@ public function test_many_pages_few_days()
$this->assertEquals('001.png', $response['pagename']);
}

public function test_few_pages_many_days()
public function test_few_pages_many_days(): void
{
global $pguser;
$project = $this->_create_available_project();
Expand All @@ -332,7 +332,7 @@ public function test_few_pages_many_days()
$this->assertEquals('001.png', $response['pagename']);
}

public function test_many_pages_many_days()
public function test_many_pages_many_days(): void
{
global $pguser;
$project = $this->_create_available_project();
Expand All @@ -344,7 +344,7 @@ public function test_many_pages_many_days()
$this->checkout($project->projectid, "P1.proj_avail");
}

public function test_beginner_project_checkout()
public function test_beginner_project_checkout(): void
{
global $pguser;

Expand All @@ -358,7 +358,7 @@ public function test_beginner_project_checkout()
$this->checkout($project->projectid, "P1.proj_avail");
}

public function test_beginner_mentor_project_checkout()
public function test_beginner_mentor_project_checkout(): void
{
global $pguser;

Expand All @@ -374,7 +374,7 @@ public function test_beginner_mentor_project_checkout()
$this->checkout($project->projectid, "P2.proj_avail");
}

public function test_resume_page()
public function test_resume_page(): void
{
global $pguser;

Expand All @@ -398,7 +398,7 @@ public function test_resume_page()
$this->assertEquals($expected, $response);
}

public function test_resume_page_not_owned()
public function test_resume_page_not_owned(): void
{
global $pguser;

Expand All @@ -415,7 +415,7 @@ public function test_resume_page_not_owned()
$this->resume($project->projectid, 'P1.proj_avail', '001.png', 'P1.page_out');
}

public function test_project_return_to_round()
public function test_project_return_to_round(): void
{
global $pguser;

Expand All @@ -430,7 +430,7 @@ public function test_project_return_to_round()
$this->assertEquals(null, $response);
}

public function test_return_page_no_state()
public function test_return_page_no_state(): void
{
global $pguser;

Expand All @@ -445,7 +445,7 @@ public function test_return_page_no_state()
$router->route($path, ['state' => "P1.proj_avail", 'pageaction' => "abandon"]);
}

public function test_no_page_action()
public function test_no_page_action(): void
{
global $pguser;

Expand All @@ -462,7 +462,7 @@ public function test_no_page_action()
$router->route($path, ['state' => "P1.proj_avail", 'pagestate' => "P1.page_out"]);
}

public function test_invalid_page_action()
public function test_invalid_page_action(): void
{
global $pguser;

Expand All @@ -479,7 +479,7 @@ public function test_invalid_page_action()
$router->route($path, ['state' => "P1.proj_avail", 'pagestate' => "P1.page_out", 'pageaction' => "revoke"]);
}

public function test_return_non_existent_page()
public function test_return_non_existent_page(): void
{
global $pguser;

Expand All @@ -490,7 +490,7 @@ public function test_return_non_existent_page()
$this->return_to_round($project->projectid, "P1.proj_avail", "002.png", "P1.page_out");
}

public function test_return_invalid_page_state()
public function test_return_invalid_page_state(): void
{
global $pguser;

Expand All @@ -502,7 +502,7 @@ public function test_return_invalid_page_state()
$this->return_to_round($project->projectid, "P1.proj_avail", "001.png", "P1.page_in");
}

public function test_return_page_state_not_as_in_project()
public function test_return_page_state_not_as_in_project(): void
{
global $pguser;

Expand All @@ -514,7 +514,7 @@ public function test_return_page_state_not_as_in_project()
$this->return_to_round($project->projectid, "P1.proj_avail", "001.png", "P1.page_out");
}

public function test_return_page_state_not_allowed()
public function test_return_page_state_not_allowed(): void
{
global $pguser;

Expand All @@ -529,7 +529,7 @@ public function test_return_page_state_not_allowed()
$this->return_to_round($project->projectid, "P1.proj_avail", "001.png", "P1.page_avail");
}

public function test_return_page_not_owned()
public function test_return_page_not_owned(): void
{
global $pguser;

Expand All @@ -546,7 +546,7 @@ public function test_return_page_not_owned()
$this->return_to_round($project->projectid, "P1.proj_avail", "001.png", "P1.page_out");
}

public function test_save_as_in_progress()
public function test_save_as_in_progress(): void
{
global $pguser;

Expand Down Expand Up @@ -580,7 +580,7 @@ public function test_save_as_in_progress()
$this->save_as_in_progress($project->projectid, "P1.proj_avail", "001.png", "P1.page_temp", "This is a bĀd test file");
}

public function test_save_no_text()
public function test_save_no_text(): void
{
global $pguser;

Expand All @@ -595,7 +595,7 @@ public function test_save_no_text()
$this->api_project_page($project->projectid, "P1.proj_avail", "001.png", "P1.page_out", [], "save");
}

public function test_save_as_done()
public function test_save_as_done(): void
{
global $pguser;

Expand Down Expand Up @@ -636,7 +636,7 @@ public function test_save_as_done()
$this->assertEquals($user_tallyboard->get_current_tally($user->u_id), $tally);
}

public function test_daily_limit()
public function test_daily_limit(): void
{
global $pguser;

Expand All @@ -662,7 +662,7 @@ public function test_daily_limit()
$round->daily_page_limit = $old_limit;
}

public function test_info_for_previous_proofreaders()
public function test_info_for_previous_proofreaders(): void
{
global $pguser;

Expand Down Expand Up @@ -696,23 +696,23 @@ public function test_info_for_previous_proofreaders()
$this->assertEquals($this->TEST_OLDUSERNAME, $info[1]->username);
}

public function test_validate_bad_text()
public function test_validate_bad_text(): void
{
$project = $this->_create_available_project();
$response = $this->validate_text($project->projectid, "This is an invĀlid test file");
$expected = ["invalid_chars" => ["Ā" => "LATIN CAPITAL LETTER A WITH MACRON"]];
$this->assertEquals($expected, $response);
}

public function test_validate_good_text()
public function test_validate_good_text(): void
{
$project = $this->_create_available_project();
$response = $this->validate_text($project->projectid, "This is a valid test file");
$expected = ["invalid_chars" => []];
$this->assertEquals($expected, $response);
}

public function test_wordcheck_bad_words()
public function test_wordcheck_bad_words(): void
{
$project = $this->_create_available_project();
$response = $this->wordcheck($project->projectid, "Fort Snelling b[oe]uf a1l file");
Expand All @@ -723,7 +723,7 @@ public function test_wordcheck_bad_words()
$this->assertEquals($expected, $response);
}

public function test_wordcheck_accept()
public function test_wordcheck_accept(): void
{
$project = $this->_create_available_project();
$response = $this->wordcheck($project->projectid, "Fort Snelling test\nfile", [], ["Snelling"]);
Expand All @@ -734,7 +734,7 @@ public function test_wordcheck_accept()
$this->assertEquals($expected, $response);
}

public function test_wordcheck_report()
public function test_wordcheck_report(): void
{
global $pguser;

Expand All @@ -756,6 +756,7 @@ public function test_wordcheck_report()
}

// this mocks the function in index.php
/** @return string|array */
function api_get_request_body()
{
global $request_body;
Expand Down
Loading

0 comments on commit 84546f7

Please sign in to comment.