17
17
require_once __DIR__ . '/../../php/libraries/NDB_BVL_Instrument.class.inc ' ;
18
18
require_once 'Smarty_hook.class.inc ' ;
19
19
require_once 'NDB_Config.class.inc ' ;
20
+ require_once 'SessionID.php ' ;
20
21
/**
21
22
* Unit test for NDB_BVL_Instrument class
22
23
*
@@ -983,14 +984,21 @@ function testGetCommentID()
983
984
*/
984
985
function testGetSessionID ()
985
986
{
986
- $ this ->_setUpMockDB ();
987
- $ this ->_setTableData ();
988
987
$ 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
+ );
990
998
}
991
999
992
1000
/**
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
994
1002
* database for the given commentID
995
1003
*
996
1004
* @covers NDB_BVL_Instrument::getSessionID
@@ -1001,7 +1009,8 @@ function testGetSessionIDReturnsNegative()
1001
1009
$ this ->_setUpMockDB ();
1002
1010
$ this ->_setTableData ();
1003
1011
$ this ->_instrument ->commentID = 'commentID3 ' ;
1004
- $ this ->assertEquals (-1 , $ this ->_instrument ->getSessionID ());
1012
+ $ this ->expectException ('NotFound ' );
1013
+ $ this ->_instrument ->getSessionID ();
1005
1014
}
1006
1015
1007
1016
/**
@@ -1013,28 +1022,20 @@ function testGetSessionIDReturnsNegative()
1013
1022
*/
1014
1023
function testGetVisitLabel ()
1015
1024
{
1016
- $ this ->_setUpMockDB ();
1017
- $ this ->_setTableData ();
1018
1025
$ 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
+ );
1020
1036
$ this ->assertEquals ("V1 " , $ this ->_instrument ->getVisitLabel ());
1021
1037
}
1022
1038
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
-
1038
1039
/**
1039
1040
* Test that getSubprojectID returns the correct value
1040
1041
* for the given session ID
@@ -1044,26 +1045,18 @@ function testGetVisitLabelReturnsEmpty()
1044
1045
*/
1045
1046
function testGetSubprojectID ()
1046
1047
{
1047
- $ this ->_setUpMockDB ();
1048
- $ this ->_setTableData ();
1049
1048
$ 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 ]);
1050
1057
$ this ->assertEquals (2 , $ this ->_instrument ->getSubprojectID ());
1051
1058
}
1052
1059
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
-
1067
1060
/**
1068
1061
* Test that getDoB returns the correct date of birth from the database
1069
1062
*
@@ -1769,44 +1762,6 @@ function toJsonParseSmartySelectType()
1769
1762
$ this ->assertEquals ($ el , $ this ->_instrument ->_toJSONParseSmarty ($ select ));
1770
1763
}
1771
1764
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
-
1810
1765
/**
1811
1766
* Test that usesJSONData returns false
1812
1767
*
0 commit comments