Skip to content

Commit

Permalink
[Integration] changeUserProject helper function, candidate_profile te…
Browse files Browse the repository at this point in the history
…sts (aces#6912)

Add 2 helper functions, changeProject and resetProject, to the LorisIntegrationTest.class.inc class. These will allow us to test project permissions on modules.

Also added initial integration tests for the candidate_profile module, including a project permission test.

    Resolves aces#6911
  • Loading branch information
AlexandraLivadas committed Jun 29, 2021
1 parent ca29c6f commit 458873d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
82 changes: 82 additions & 0 deletions modules/candidate_profile/test/candidate_profileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Candidate_profile automated integration tests
*
* PHP Version 7
*
* @category Test
* @package Loris
* @author Alexandra Livadas <alexandra.livadas@mail.mcgill.ca>
* @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 <alexandra.livadas@mail.mcgill.ca>
* @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();
}
}
32 changes: 32 additions & 0 deletions test/integrationtests/LorisIntegrationTest.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
1 change: 1 addition & 0 deletions test/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<directory>../modules/bvl_feedback/test/</directory>
<directory>../modules/candidate_list/test/</directory>
<directory>../modules/candidate_parameters/test/</directory>
<directory>../modules/candidate_profile/test/</directory>
<directory>../modules/configuration/test/</directory>
<directory>../modules/conflict_resolver/test/</directory>
<directory>../modules/create_timepoint/test/</directory>
Expand Down

0 comments on commit 458873d

Please # to comment.