forked from aces/Loris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/2020-07-22_conflictresolver_reac…
…tification' into 2020-07-22_conflictresolver_reactification
- Loading branch information
Showing
1 changed file
with
130 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
<?php | ||
/** | ||
* PHP Version 7 | ||
* | ||
* @category Test | ||
* @package Loris | ||
* @author Wang Shen <[email protected]> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://github.com/aces/Loris | ||
*/ | ||
namespace LORIS\conflict_resolver; | ||
/** | ||
* Automated integration tests for conflict resolver module | ||
* | ||
* PHP Version 7 | ||
* | ||
* @category Test | ||
* @package Loris | ||
* @author Wang Shen <[email protected]> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://github.com/aces/Loris | ||
*/ | ||
use Facebook\WebDriver\WebDriverSelect; | ||
use Facebook\WebDriver\WebDriverBy; | ||
use Facebook\WebDriver\WebDriverExpectedCondition; | ||
|
||
/** | ||
* Automated integration tests for conflict resolver module | ||
* | ||
* @category Test | ||
* @package Loris | ||
* @author Wang Shen <[email protected]> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://github.com/aces/Loris | ||
*/ | ||
class ConflictResolverTestIntegrationTest extends \LorisIntegrationTest | ||
require_once __DIR__ | ||
. "/../../../test/integrationtests/LorisIntegrationTest.class.inc"; | ||
/** | ||
* Implements tests for conflict resolver | ||
* | ||
* @category Test | ||
* @package Loris | ||
* @author Wang Shen <[email protected]> | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
* @link https://github.com/aces/Loris | ||
*/ | ||
class ConflictResolverTestIntegrationTest extends LorisIntegrationTest | ||
{ | ||
//filter location on conflict_resolver page | ||
static $ForSite = 'select[name="Site"]'; | ||
|
@@ -31,13 +33,14 @@ class ConflictResolverTestIntegrationTest extends \LorisIntegrationTest | |
static $PSCID = 'input[name="PSCID"]'; | ||
static $Question = 'input[name="Question"]'; | ||
static $Project = 'select[name="Project"]'; | ||
|
||
//filter location on resolved_conflicts page | ||
static $Timestamp = 'input[name="ResolutionTimestamp"]'; | ||
|
||
//public location for both pages | ||
static $clearFilter = 'button[type="reset"]'; | ||
static $display = '.table-header'; | ||
static $clearFilter = 'a[name="reset"]'; | ||
static $display = ".table-header"; | ||
static $saveBtn = ".btn-sm:nth-child(1)"; | ||
static $resetBtn = ".btn-sm:nth-child(2)"; | ||
/** | ||
* Insert testing data into the database | ||
* author: Wang Shen | ||
|
@@ -91,30 +94,13 @@ function tearDown() | |
*/ | ||
function testConflictResolverPermission() | ||
{ | ||
$this->setupPermissions(["conflict_resolver"]); | ||
$this->safeGet($this->url . "/conflict_resolver"); | ||
$this->webDriver->wait()->until( | ||
WebDriverExpectedCondition::presenceOfElementLocated( | ||
WebDriverBy::id('tab-unresolved') | ||
) | ||
$this->checkPagePermissions( | ||
'/conflict_resolver/', | ||
[ | ||
'conflict_resolver' | ||
], | ||
"Conflict Resolver" | ||
); | ||
|
||
$this->resetPermissions(); | ||
} | ||
/** | ||
* Tests that conflict resolver does not load with the permission | ||
* | ||
* @return void | ||
*/ | ||
function testConflictResolverWithoutPermission() | ||
{ | ||
$this->setupPermissions([]); | ||
$this->safeGet($this->url . "/conflict_resolver"); | ||
$bodyText = $this->webDriver->findElement( | ||
WebDriverBy::id('lorisworkspace') | ||
)->getText(); | ||
$this->assertContains("You do not have access to this page.", $bodyText); | ||
$this->resetPermissions(); | ||
} | ||
/** | ||
* Tests clear button in the form | ||
|
@@ -125,66 +111,49 @@ function testConflictResolverWithoutPermission() | |
function testFiltersForUnresolvedConflicts() | ||
{ | ||
$this->safeGet($this->url . "/conflict_resolver/"); | ||
|
||
$this->webDriver->wait()->until( | ||
WebDriverExpectedCondition::presenceOfElementLocated( | ||
WebDriverBy::id('tab-unresolved') | ||
) | ||
//testing data | ||
$this->_filterTest( | ||
self::$ForSite, | ||
self::$display, | ||
self::$clearFilter, | ||
'Montreal', | ||
"20 rows displayed of 311" | ||
); | ||
|
||
$this->_testFilter(self::$ForSite, "20 rows displayed of 311", '2'); | ||
$this->_testFilter(self::$VisitLabel, "displayed of 573", '1'); | ||
$this->_testFilter(self::$CandID, "2 rows displayed of 2", '300004'); | ||
$this->_testFilter(self::$PSCID, "2 rows displayed of 2", 'MTL004'); | ||
$this->_testFilter(self::$Question, "displayed of 180", 'height_inches'); | ||
$this->_testFilter(self::$Project, "0 rows displayed of 0", '1'); | ||
} | ||
/** | ||
* Testing filter funtion and clear button | ||
* | ||
* @param string $element The input element location | ||
* @param string $records The records number in the table | ||
* @param string $value The test value | ||
* | ||
* @return void | ||
*/ | ||
function _testFilter($element,$records,$value) | ||
{ | ||
// get element from the page | ||
if (strpos($element, "select") === false) { | ||
$this->webDriver->executescript( | ||
"input = document.querySelector('$element'); | ||
lastValue = input.value; | ||
input.value = '$value'; | ||
event = new Event('input', { bubbles: true }); | ||
input._valueTracker.setValue(lastValue); | ||
input.dispatchEvent(event); | ||
" | ||
); | ||
} else { | ||
$this->webDriver->executescript( | ||
"input = document.querySelector('$element'); | ||
input.selectedIndex = '$value'; | ||
event = new Event('change', { bubbles: true }); | ||
input.dispatchEvent(event); | ||
" | ||
); | ||
} | ||
|
||
$row = self::$display; | ||
$bodyText = $this->webDriver->executescript( | ||
"return document.querySelector('$row').textContent" | ||
$this->_filterTest( | ||
self::$VisitLabel, | ||
self::$display, | ||
self::$clearFilter, | ||
'V1', | ||
"displayed of 573" | ||
); | ||
$this->assertContains($records, $bodyText); | ||
//test clear filter | ||
$btn = self::$clearFilter; | ||
$this->webDriver->executescript( | ||
"document.querySelector('$btn').click();" | ||
$this->_filterTest( | ||
self::$CandID, | ||
self::$display, | ||
self::$clearFilter, | ||
'300004', | ||
"2 rows displayed of 2" | ||
); | ||
$inputText = $this->webDriver->executescript( | ||
"return document.querySelector('$element').value" | ||
$this->_filterTest( | ||
self::$PSCID, | ||
self::$display, | ||
self::$clearFilter, | ||
'MTL004', | ||
"2 rows displayed of 2" | ||
); | ||
$this->_filterTest( | ||
self::$Question, | ||
self::$display, | ||
self::$clearFilter, | ||
'height_inches', | ||
"displayed of 180" | ||
); | ||
$this->_filterTest( | ||
self::$Project, | ||
self::$display, | ||
self::$clearFilter, | ||
'Pumpernickel', | ||
"573" | ||
); | ||
$this->assertEquals("", $inputText); | ||
} | ||
/** | ||
* Tests filter in resolved conflicts | ||
|
@@ -194,31 +163,50 @@ function _testFilter($element,$records,$value) | |
*/ | ||
function testFiltersForResolvedConflicts() | ||
{ | ||
$this->safeGet($this->url . "/conflict_resolver"); | ||
|
||
$this->webDriver->wait()->until( | ||
WebDriverExpectedCondition::presenceOfElementLocated( | ||
WebDriverBy::id('tab-resolved') | ||
) | ||
$this->safeGet($this->url."/conflict_resolver/"); | ||
$this->safeClick(WebDriverBy::cssSelector("#tab-resolved")); | ||
$this->_filterTest( | ||
self::$ForSite, | ||
self::$display, | ||
self::$clearFilter, | ||
"Montreal", | ||
"displayed of 14" | ||
); | ||
|
||
$this->webDriver->executescript( | ||
"document.querySelector('#tab-resolved').click();" | ||
$this->_filterTest( | ||
self::$VisitLabel, | ||
self::$display, | ||
self::$clearFilter, | ||
"V1", | ||
"displayed of 32" | ||
); | ||
|
||
// Clicking on the tab renders a new tab content. | ||
$this->webDriver->wait()->until( | ||
WebDriverExpectedCondition::presenceOfElementLocated( | ||
WebDriverBy::id('resolved') | ||
) | ||
$this->_filterTest( | ||
self::$CandID, | ||
self::$display, | ||
self::$clearFilter, | ||
'400167', | ||
"1 row" | ||
); | ||
$this->_filterTest( | ||
self::$PSCID, | ||
self::$display, | ||
self::$clearFilter, | ||
'ROM167', | ||
"1 row" | ||
); | ||
$this->_filterTest( | ||
self::$Question, | ||
self::$display, | ||
self::$clearFilter, | ||
'date_taken', | ||
"8 rows" | ||
); | ||
$this->_filterTest( | ||
self::$Timestamp, | ||
self::$display, | ||
self::$clearFilter, | ||
'2016-08-16 18:35:51', | ||
"1 row" | ||
); | ||
|
||
$this->_testFilter(self::$ForSite, "displayed of 14", '2'); | ||
$this->_testFilter(self::$VisitLabel, "displayed of 32", '1'); | ||
$this->_testFilter(self::$CandID, "1 row", '400167'); | ||
$this->_testFilter(self::$PSCID, "1 row", 'ROM167'); | ||
$this->_testFilter(self::$Question, "8 rows", 'date_taken'); | ||
$this->_testFilter(self::$Timestamp, "1 row", '2016-08-16 18:35:51'); | ||
|
||
} | ||
/** | ||
|
@@ -229,10 +217,25 @@ function testFiltersForResolvedConflicts() | |
*/ | ||
function testSaveUnresolvedToResolved() | ||
{ | ||
$this->markTestSkipped( | ||
'rewrite later' | ||
); | ||
//set canID 475906 to resolved | ||
$this->safeGet( | ||
$this->url . | ||
"/conflict_resolver/?candidateID=475906&instrument=radiology_review" | ||
"/conflict_resolver/?CandID=475906&instrument=radiology_review" | ||
); | ||
$element = "tr:nth-child(1) .form-control"; | ||
$row = self::$display; | ||
$el_dropdown = new WebDriverSelect( | ||
$this->safeFindElement(WebDriverBy::cssSelector("$element")) | ||
); | ||
$el_dropdown->selectByVisibleText("no"); | ||
$this->safeGet($this->url."/conflict_resolver/"); | ||
$bodyText = $this->safeFindElement( | ||
WebDriverBy::cssSelector($row) | ||
)->getText(); | ||
// 4 means there are 4 records under this site. | ||
$this->assertContains("of 572", $bodyText); | ||
} | ||
} |