Skip to content

Commit 4475452

Browse files
authoredAug 12, 2020
[Test] Fixing unittests causing Travis failure (#6903)
The unit tests for NDB_BVL_Instrument that were merged with main in PR #6819 were causing Travis to fail. This fixes those errors. The reason it failed Travis was because the changes made in merged PR #5352 were not added to the testing PR. These changes caused it to fail Travis but were not flagged before.
1 parent 53979f0 commit 4475452

File tree

1 file changed

+32
-77
lines changed

1 file changed

+32
-77
lines changed
 

‎test/unittests/NDB_BVL_Instrument_Test.php

+32-77
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require_once __DIR__ . '/../../php/libraries/NDB_BVL_Instrument.class.inc';
1818
require_once 'Smarty_hook.class.inc';
1919
require_once 'NDB_Config.class.inc';
20+
require_once 'SessionID.php';
2021
/**
2122
* Unit test for NDB_BVL_Instrument class
2223
*
@@ -983,14 +984,21 @@ function testGetCommentID()
983984
*/
984985
function testGetSessionID()
985986
{
986-
$this->_setUpMockDB();
987-
$this->_setTableData();
988987
$this->_instrument->commentID = 'commentID1';
989-
$this->assertEquals("123", $this->_instrument->getSessionID());
988+
$this->_mockDB->expects($this->once())->method('pselectOne')
989+
->with(
990+
"SELECT SessionID FROM flag WHERE CommentID = :CID",
991+
['CID' => 'commentID1']
992+
)
993+
->willReturn('123');
994+
$this->assertEquals(
995+
new \SessionID('123'),
996+
$this->_instrument->getSessionID()
997+
);
990998
}
991999

9921000
/**
993-
* Test that getSessionID returns -1 if nothing was found in the
1001+
* Test that getSessionID throws a NotFound exception if nothing was found in the
9941002
* database for the given commentID
9951003
*
9961004
* @covers NDB_BVL_Instrument::getSessionID
@@ -1001,7 +1009,8 @@ function testGetSessionIDReturnsNegative()
10011009
$this->_setUpMockDB();
10021010
$this->_setTableData();
10031011
$this->_instrument->commentID = 'commentID3';
1004-
$this->assertEquals(-1, $this->_instrument->getSessionID());
1012+
$this->expectException('NotFound');
1013+
$this->_instrument->getSessionID();
10051014
}
10061015

10071016
/**
@@ -1013,28 +1022,20 @@ function testGetSessionIDReturnsNegative()
10131022
*/
10141023
function testGetVisitLabel()
10151024
{
1016-
$this->_setUpMockDB();
1017-
$this->_setTableData();
10181025
$this->_instrument->commentID = 'commentID1';
1019-
$this->assertEquals("123", $this->_instrument->getSessionID());
1026+
$this->_mockDB->expects($this->any(0))->method('pselectOne')
1027+
->with(
1028+
"SELECT SessionID FROM flag WHERE CommentID = :CID",
1029+
['CID' => 'commentID1']
1030+
)
1031+
->willReturn('123');
1032+
$this->_mockDB->expects($this->any())->method('pselectRow')
1033+
->willReturn(
1034+
['SubprojectID' => 2, 'Visit_label' => 'V1', 'CandID' => '300123']
1035+
);
10201036
$this->assertEquals("V1", $this->_instrument->getVisitLabel());
10211037
}
10221038

1023-
/**
1024-
* Test that getVistiLabel returns an empty string
1025-
* if nothing was found in the database
1026-
*
1027-
* @covers NDB_BVL_Instrument::getVisitLabel
1028-
* @return void
1029-
*/
1030-
function testGetVisitLabelReturnsEmpty()
1031-
{
1032-
$this->_setUpMockDB();
1033-
$this->_setTableData();
1034-
$this->_instrument->commentID = 'commentID3';
1035-
$this->assertEquals("", $this->_instrument->getVisitLabel());
1036-
}
1037-
10381039
/**
10391040
* Test that getSubprojectID returns the correct value
10401041
* for the given session ID
@@ -1044,26 +1045,18 @@ function testGetVisitLabelReturnsEmpty()
10441045
*/
10451046
function testGetSubprojectID()
10461047
{
1047-
$this->_setUpMockDB();
1048-
$this->_setTableData();
10491048
$this->_instrument->commentID = 'commentID1';
1049+
$this->_mockDB->expects($this->any(0))->method('pselectOne')
1050+
->with(
1051+
"SELECT SessionID FROM flag WHERE CommentID = :CID",
1052+
['CID' => 'commentID1']
1053+
)
1054+
->willReturn('123');
1055+
$this->_mockDB->expects($this->any())->method('pselectRow')
1056+
->willReturn(['SubprojectID' => 2]);
10501057
$this->assertEquals(2, $this->_instrument->getSubprojectID());
10511058
}
10521059

1053-
/**
1054-
* Test that getSubprojectID returns null if nothing was found
1055-
*
1056-
* @covers NDB_BVL_Instrument::getSubprojectID
1057-
* @return void
1058-
*/
1059-
function testGetSubprojectIDReturnsNull()
1060-
{
1061-
$this->_setUpMockDB();
1062-
$this->_setTableData();
1063-
$this->_instrument->commentID = 'commentID3';
1064-
$this->assertEquals(null, $this->_instrument->getSubprojectID());
1065-
}
1066-
10671060
/**
10681061
* Test that getDoB returns the correct date of birth from the database
10691062
*
@@ -1769,44 +1762,6 @@ function toJsonParseSmartySelectType()
17691762
$this->assertEquals($el, $this->_instrument->_toJSONParseSmarty($select));
17701763
}
17711764

1772-
/**
1773-
* Test that getBreadcrumbs returns a BreadcrumbTrail object with the correct
1774-
* Breadcrumb data
1775-
*
1776-
* @covers NDB_BVL_Instrument::getBreadcrumbs
1777-
* @return void
1778-
*/
1779-
function testGetBreadcrumbs()
1780-
{
1781-
$this->_setUpMockDB();
1782-
$this->_setTableData();
1783-
$this->_instrument->commentID = 'commentID1';
1784-
$this->_instrument->testName = 'testname';
1785-
$breadcrumb = new \LORIS\BreadcrumbTrail(
1786-
new \LORIS\Breadcrumb(
1787-
'Access Profile',
1788-
'/candidate_list'
1789-
),
1790-
new \LORIS\Breadcrumb(
1791-
"Candidate Profile 300123 / 345",
1792-
"/300123"
1793-
),
1794-
new \LORIS\Breadcrumb(
1795-
"TimePoint V1 Details",
1796-
"/instrument_list/?candID=300123&sessionID=123"
1797-
),
1798-
new \LORIS\Breadcrumb(
1799-
"Test Instrument",
1800-
"/instruments/testname/".
1801-
"?commentID=commentID1&sessionID=123&candID=300123"
1802-
)
1803-
);
1804-
$this->assertEquals(
1805-
$breadcrumb,
1806-
$this->_instrument->getBreadcrumbs()
1807-
);
1808-
}
1809-
18101765
/**
18111766
* Test that usesJSONData returns false
18121767
*

0 commit comments

Comments
 (0)