diff --git a/modules/candidate_profile/test/candidate_profileTest.php b/modules/candidate_profile/test/candidate_profileTest.php new file mode 100644 index 00000000000..4f5825d4737 --- /dev/null +++ b/modules/candidate_profile/test/candidate_profileTest.php @@ -0,0 +1,82 @@ + + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://github.com/aces/Loris + */ +use Facebook\WebDriver\WebDriverBy; +require_once __DIR__ + . "/../../../test/integrationtests/LorisIntegrationTestWithCandidate.class.inc"; +/** + * CandidateProfileIntegrationTest + * + * @category Test + * @package Loris + * @author Alexandra Livadas + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://github.com/aces/Loris + */ +class CandidateProfileIntegrationTest extends LorisIntegrationTestWithCandidate +{ + /** + * Tests that the page loads + * + * @return void + */ + function testCandidateProfileDoespageLoad() + { + $this->safeGet($this->url . "/900000/"); + $bodyText + = $this->safeFindElement(WebDriverBy::cssSelector("body")) + ->getText(); + $this->assertContains("Candidate Profile 900000", $bodyText); + } + + /** + * Test that the page does not load if the user's study site does not + * match the candidate's + * + * @return void + */ + function testCandidateProfileWithoutSitePermissions() + { + $this->resetStudySite(); + $this->changeStudySite(); + $this->setupPermissions(["data_entry"]); + $this->safeGet($this->url . "/900000/"); + $bodyText + = $this->safeFindElement(WebDriverBy::cssSelector("body")) + ->getText(); + $this->assertContains("Permission Denied", $bodyText); + $this->resetPermissions(); + + $this->resetStudySite(); + } + + /** + * Test that the page does not load if the user's project does not + * match the candidate's + * + * @return void + */ + function testCandidateProfileWithoutProjectPermissions() + { + $this->resetUserProject(); + $this->changeUserProject(); + $this->setupPermissions(["data_entry"]); + $this->safeGet($this->url . "/900000/"); + $bodyText + = $this->safeFindElement(WebDriverBy::cssSelector("body")) + ->getText(); + $this->assertContains("Permission Denied", $bodyText); + $this->resetPermissions(); + + $this->resetUserProject(); + } +} diff --git a/test/integrationtests/LorisIntegrationTest.class.inc b/test/integrationtests/LorisIntegrationTest.class.inc index 048851f7522..e9c55f3e974 100644 --- a/test/integrationtests/LorisIntegrationTest.class.inc +++ b/test/integrationtests/LorisIntegrationTest.class.inc @@ -348,6 +348,38 @@ abstract class LorisIntegrationTest extends TestCase $this->DB->run('SET foreign_key_checks =1'); } + /** + * Helper function to change the users Project + * + * @return void + */ + function changeUserProject() + { + $this->DB->insert("Project", ["ProjectID" => 99, "Alias" => "BBQ"]); + $this->DB->update( + "user_project_rel", + ["ProjectID" => 99], + ["UserID" => 999990] + ); + } + + /** + * Helper function to reset the users Project + * + * @return void + */ + function resetUserProject() + { + $this->DB->run('SET foreign_key_checks =0'); + $this->DB->update( + "user_project_rel", + ["ProjectID" => 1], + ["UserID" => 999990] + ); + $this->DB->delete("Project", ["ProjectID" => 99]); + $this->DB->run('SET foreign_key_checks =1'); + } + /** * Helper function to create a subproject * diff --git a/test/phpunit.xml b/test/phpunit.xml index 89e2fab0e1e..ad550ec65cd 100644 --- a/test/phpunit.xml +++ b/test/phpunit.xml @@ -19,6 +19,7 @@ ../modules/bvl_feedback/test/ ../modules/candidate_list/test/ ../modules/candidate_parameters/test/ + ../modules/candidate_profile/test/ ../modules/configuration/test/ ../modules/conflict_resolver/test/ ../modules/create_timepoint/test/