ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilTestSessionTest Class Reference

Class ilTestSessionTest. More...

+ Inheritance diagram for ilTestSessionTest:
+ Collaboration diagram for ilTestSessionTest:

Public Member Functions

 test_instantiateObject_shouldReturnInstance ()
 
 testRefId ()
 
 testActiveId ()
 
 testUserId ()
 
 testTestId ()
 
 testAnonymousId ()
 
 testLastSequence ()
 
 testPass ()
 
 testIncreasePass ()
 
 testSubmitted ()
 
 testSubmittedTimestamp ()
 
 testLastFinishedPass ()
 
 testObjectiveOrientedContainerId ()
 
 testLastStartedPass ()
 
 testIsObjectiveOriented ()
 
 testSetAccessCodeToSession ()
 
 testUnsetAccessCodeInSession ()
 
 testIsAnonymousUser ()
 
 testPasswordChecked ()
 
 testCheckAccessRejectsAnonymousActiveIdWithoutAccessCode ()
 
 testCheckAccessRejectsAnonymousActiveIdWithForeignAccessCode ()
 
 testCheckAccessAcceptsAnonymousActiveIdWithMatchingAccessCode ()
 
 testCheckAccessRejectsActiveIdFromDifferentTest ()
 
 testCheckAccessAllowsAuthenticatedUsers ()
 
 testCheckAccessRejectsAuthenticatedUsersWithInconsistentUserId ()
 
 testCheckAccessAllowsAnonymousWithoutActiveId ()
 
- Public Member Functions inherited from ilTestBaseTestCase
 createInstanceOf (string $class_name, array $explicit_parameters=[])
 
 createTraitInstanceOf (string $class_name, array $explicit_parameters=[])
 

Protected Member Functions

 setUp ()
 
- Protected Member Functions inherited from ilTestBaseTestCase
 setUp ()
 
 tearDown ()
 

Private Member Functions

 getTestObject (int $test_id)
 
 createTestSession (int $user_id, int $active_id, int $test_id, ?string $access_code=null)
 

Private Attributes

ilTestSession $testObj
 

Additional Inherited Members

- Static Public Member Functions inherited from ilTestBaseTestCase
static callMethod ($obj, $name, array $args=[])
 
static getNonPublicPropertyValue (object $obj, string $name)
 
- Data Fields inherited from ilTestBaseTestCase
const string MOCKED_METHOD_WITHOUT_OUTPUT = 'MOCKED_METHOD_WITHOUT_OUTPUT'
 
const string DYNAMIC_CLASS = 'DynamicClass'
 
- Protected Attributes inherited from ilTestBaseTestCase
Container $dic = null
 
Container $backup_dic = null
 
- Static Protected Attributes inherited from ilTestBaseTestCase
static int $DYNAMIC_CLASS_COUNT = 0
 

Detailed Description

Class ilTestSessionTest.

Author
Marvin Beym mbeym.nosp@m.@dat.nosp@m.abay..nosp@m.de

Definition at line 25 of file ilTestSessionTest.php.

Member Function Documentation

◆ createTestSession()

ilTestSessionTest::createTestSession ( int  $user_id,
int  $active_id,
int  $test_id,
?string  $access_code = null 
)
private

Definition at line 281 of file ilTestSessionTest.php.

286 : ilTestSession {
287 $user = $this->createMock(ilObjUser::class);
288 $user->method('getId')->willReturn($user_id);
289 $this->setGlobalVariable('ilUser', $user);
290
291 $session = new ilTestSession(
292 $this->createMock(ilDBInterface::class),
293 $user
294 );
295 $session->setUserId($user_id);
296 $session->setTestId($test_id);
297 $session->active_id = $active_id;
298
299 if ($access_code !== null) {
300 $session->setAnonymousId($access_code);
301 }
302
303 return $session;
304 }
Test session handler.
setGlobalVariable(string $name, mixed $value)

Referenced by testCheckAccessAcceptsAnonymousActiveIdWithMatchingAccessCode(), testCheckAccessAllowsAnonymousWithoutActiveId(), testCheckAccessAllowsAuthenticatedUsers(), testCheckAccessRejectsActiveIdFromDifferentTest(), testCheckAccessRejectsAnonymousActiveIdWithForeignAccessCode(), testCheckAccessRejectsAnonymousActiveIdWithoutAccessCode(), and testCheckAccessRejectsAuthenticatedUsersWithInconsistentUserId().

+ Here is the caller graph for this function:

◆ getTestObject()

ilTestSessionTest::getTestObject ( int  $test_id)
private

◆ setUp()

ilTestSessionTest::setUp ( )
protected

Reimplemented from ilTestBaseTestCase.

Definition at line 29 of file ilTestSessionTest.php.

29 : void
30 {
32
33 $this->addGlobal_ilTabs();
35 $this->addGlobal_rbacsystem();
36 $this->addGlobal_ilHelp();
37 $this->addGlobal_ilToolbar();
40
41 $this->testObj = new ilTestSession(
42 $this->createMock(ilDBInterface::class),
43 $this->createMock(ilObjUser::class)
44 );
45 }
addGlobal_ilNavigationHistory()
addGlobal_GlobalScreenService()
addGlobal_ilObjDataCache()
addGlobal_rbacsystem()

References addGlobal_GlobalScreenService(), addGlobal_ilHelp(), addGlobal_ilNavigationHistory(), addGlobal_ilObjDataCache(), addGlobal_ilTabs(), addGlobal_ilToolbar(), addGlobal_rbacsystem(), and setUp().

+ Here is the call graph for this function:

◆ test_instantiateObject_shouldReturnInstance()

ilTestSessionTest::test_instantiateObject_shouldReturnInstance ( )

Definition at line 47 of file ilTestSessionTest.php.

47 : void
48 {
49 $this->assertInstanceOf(ilTestSession::class, $this->testObj);
50 }

◆ testActiveId()

ilTestSessionTest::testActiveId ( )

Definition at line 59 of file ilTestSessionTest.php.

59 : void
60 {
61 $active_id = 20;
62 $this->testObj->active_id = $active_id;
63 $this->assertEquals($active_id, $this->testObj->getActiveId());
64 }

◆ testAnonymousId()

ilTestSessionTest::testAnonymousId ( )

Definition at line 80 of file ilTestSessionTest.php.

80 : void
81 {
82 $anonymous_id = '20';
83 $this->testObj->setAnonymousId($anonymous_id);
84 $this->assertEquals($anonymous_id, $this->testObj->getAnonymousId());
85 }

◆ testCheckAccessAcceptsAnonymousActiveIdWithMatchingAccessCode()

ilTestSessionTest::testCheckAccessAcceptsAnonymousActiveIdWithMatchingAccessCode ( )

Definition at line 217 of file ilTestSessionTest.php.

217 : void
218 {
219 $session = $this->createTestSession(ANONYMOUS_USER_ID, 99, 42, 'matching-code');
220 $session->setAccessCodeToSession('matching-code');
221
222 $session->checkAccess(
223 $this->getTestObject(42)
224 );
225
226 $this->addToAssertionCount(1);
227 }
getTestObject(int $test_id)
createTestSession(int $user_id, int $active_id, int $test_id, ?string $access_code=null)
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testCheckAccessAllowsAnonymousWithoutActiveId()

ilTestSessionTest::testCheckAccessAllowsAnonymousWithoutActiveId ( )

Definition at line 265 of file ilTestSessionTest.php.

265 : void
266 {
267 $this->createTestSession(ANONYMOUS_USER_ID, 0, 42)->checkAccess(
268 $this->getTestObject(42)
269 );
270
271 $this->addToAssertionCount(1);
272 }

References ANONYMOUS_USER_ID, createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testCheckAccessAllowsAuthenticatedUsers()

ilTestSessionTest::testCheckAccessAllowsAuthenticatedUsers ( )

Definition at line 241 of file ilTestSessionTest.php.

241 : void
242 {
243 $this->createTestSession(6, 99, 42)->checkAccess(
244 $this->getTestObject(42)
245 );
246
247 $this->addToAssertionCount(1);
248 }

References createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testCheckAccessRejectsActiveIdFromDifferentTest()

ilTestSessionTest::testCheckAccessRejectsActiveIdFromDifferentTest ( )

Definition at line 229 of file ilTestSessionTest.php.

229 : void
230 {
231 $session = $this->createTestSession(ANONYMOUS_USER_ID, 99, 99, 'matching-code');
232 $session->setAccessCodeToSession('matching-code');
233
234 $this->expectException(ilTestException::class);
235 $this->expectExceptionMessage('active id given does not relate to current test!');
236 $session->checkAccess(
237 $this->getTestObject(42)
238 );
239 }

References ANONYMOUS_USER_ID, createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testCheckAccessRejectsAnonymousActiveIdWithForeignAccessCode()

ilTestSessionTest::testCheckAccessRejectsAnonymousActiveIdWithForeignAccessCode ( )

Definition at line 204 of file ilTestSessionTest.php.

204 : void
205 {
206 $session = $this->createTestSession(ANONYMOUS_USER_ID, 99, 42, 'victim-code');
207 $session->setAccessCodeToSession('attacker-code');
208
209 $this->expectException(ilTestException::class);
210 $this->expectExceptionMessage('active id given does not relate to current anonymous session!');
211
212 $session->checkAccess(
213 $this->getTestObject(42)
214 );
215 }

References ANONYMOUS_USER_ID, createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testCheckAccessRejectsAnonymousActiveIdWithoutAccessCode()

ilTestSessionTest::testCheckAccessRejectsAnonymousActiveIdWithoutAccessCode ( )

Definition at line 192 of file ilTestSessionTest.php.

192 : void
193 {
195
196 $this->expectException(ilTestException::class);
197 $this->expectExceptionMessage('active id given does not relate to current anonymous session!');
198
199 $this->createTestSession(ANONYMOUS_USER_ID, 99, 42, 'victim-code')->checkAccess(
200 $this->getTestObject(42)
201 );
202 }
static set(string $a_var, $a_val)
Set a value.

References ilTestSession\ACCESS_CODE_SESSION_INDEX, ANONYMOUS_USER_ID, createTestSession(), getTestObject(), and ilSession\set().

+ Here is the call graph for this function:

◆ testCheckAccessRejectsAuthenticatedUsersWithInconsistentUserId()

ilTestSessionTest::testCheckAccessRejectsAuthenticatedUsersWithInconsistentUserId ( )

Definition at line 250 of file ilTestSessionTest.php.

250 : void
251 {
252 $session = $this->createTestSession(6, 99, 42);
253 $session->setUserId(2);
254
255 $this->expectException(ilTestException::class);
256 $this->expectExceptionMessage('active id given does not relate to current user!');
257
258 $session->checkAccess(
259 $this->getTestObject(42)
260 );
261
262 $this->addToAssertionCount(1);
263 }

References createTestSession(), and getTestObject().

+ Here is the call graph for this function:

◆ testIncreasePass()

ilTestSessionTest::testIncreasePass ( )

Definition at line 101 of file ilTestSessionTest.php.

101 : void
102 {
103 $pass = 20;
104 $this->testObj->setPass($pass);
105 $this->assertEquals($pass, $this->testObj->getPass());
106
107 $this->testObj->increasePass();
108 $this->assertEquals(++$pass, $this->testObj->getPass());
109 }

◆ testIsAnonymousUser()

ilTestSessionTest::testIsAnonymousUser ( )

Definition at line 175 of file ilTestSessionTest.php.

175 : void
176 {
177 $this->assertFalse($this->testObj->isAnonymousUser());
178
179 $this->testObj->setUserId(ANONYMOUS_USER_ID);
180 $this->assertTrue($this->testObj->isAnonymousUser());
181 }

References ANONYMOUS_USER_ID.

◆ testIsObjectiveOriented()

ilTestSessionTest::testIsObjectiveOriented ( )

Definition at line 148 of file ilTestSessionTest.php.

148 : void
149 {
150 $this->assertFalse($this->testObj->isObjectiveOriented());
151
152 $this->testObj->setObjectiveOrientedContainerId(20);
153 $this->assertTrue($this->testObj->isObjectiveOriented());
154 }

◆ testLastFinishedPass()

ilTestSessionTest::testLastFinishedPass ( )

Definition at line 127 of file ilTestSessionTest.php.

127 : void
128 {
129 $lastFinishedPass = 20;
130 $this->testObj->setLastFinishedPass($lastFinishedPass);
131 $this->assertEquals($lastFinishedPass, $this->testObj->getLastFinishedPass());
132 }

◆ testLastSequence()

ilTestSessionTest::testLastSequence ( )

Definition at line 87 of file ilTestSessionTest.php.

87 : void
88 {
89 $lastsequence = 20;
90 $this->testObj->setLastSequence($lastsequence);
91 $this->assertEquals($lastsequence, $this->testObj->getLastSequence());
92 }

◆ testLastStartedPass()

ilTestSessionTest::testLastStartedPass ( )

Definition at line 141 of file ilTestSessionTest.php.

141 : void
142 {
143 $lastStartedPass = 20;
144 $this->testObj->setLastStartedPass($lastStartedPass);
145 $this->assertEquals($lastStartedPass, $this->testObj->getLastStartedPass());
146 }

◆ testObjectiveOrientedContainerId()

ilTestSessionTest::testObjectiveOrientedContainerId ( )

Definition at line 134 of file ilTestSessionTest.php.

134 : void
135 {
136 $objectiveOriented = 20;
137 $this->testObj->setObjectiveOrientedContainerId($objectiveOriented);
138 $this->assertEquals($objectiveOriented, $this->testObj->getObjectiveOrientedContainerId());
139 }

◆ testPass()

ilTestSessionTest::testPass ( )

Definition at line 94 of file ilTestSessionTest.php.

94 : void
95 {
96 $pass = 20;
97 $this->testObj->setPass($pass);
98 $this->assertEquals($pass, $this->testObj->getPass());
99 }

◆ testPasswordChecked()

ilTestSessionTest::testPasswordChecked ( )

Definition at line 183 of file ilTestSessionTest.php.

183 : void
184 {
185 $active_id = 20;
186 $this->testObj->active_id = $active_id;
187 $this->testObj->setPasswordChecked(true);
188 $this->assertTrue(ilSession::get("pw_checked_$active_id"));
189 $this->assertTrue($this->testObj->isPasswordChecked());
190 }
static get(string $a_var)

References ilSession\get().

+ Here is the call graph for this function:

◆ testRefId()

ilTestSessionTest::testRefId ( )

Definition at line 52 of file ilTestSessionTest.php.

52 : void
53 {
54 $ref_id = 20;
55 $this->testObj->setRefId($ref_id);
56 $this->assertEquals($ref_id, $this->testObj->getRefId());
57 }

◆ testSetAccessCodeToSession()

ilTestSessionTest::testSetAccessCodeToSession ( )

Definition at line 156 of file ilTestSessionTest.php.

156 : void
157 {
159 $access_code = '17';
160 $this->testObj->setAccessCodeToSession($access_code);
161 $this->assertEquals([(int) $access_code], ilSession::get(ilTestSession::ACCESS_CODE_SESSION_INDEX));
162 }

References ilTestSession\ACCESS_CODE_SESSION_INDEX, ilSession\get(), and ilSession\set().

+ Here is the call graph for this function:

◆ testSubmitted()

ilTestSessionTest::testSubmitted ( )

Definition at line 111 of file ilTestSessionTest.php.

111 : void
112 {
113 $this->assertFalse($this->testObj->isSubmitted());
114 $this->testObj->setSubmitted();
115
116 $this->assertTrue($this->testObj->isSubmitted());
117 }

◆ testSubmittedTimestamp()

ilTestSessionTest::testSubmittedTimestamp ( )

Definition at line 119 of file ilTestSessionTest.php.

119 : void
120 {
121 $this->assertEmpty($this->testObj->getSubmittedTimestamp());
122 $this->testObj->setSubmittedTimestamp();
123
124 $this->assertIsString($this->testObj->getSubmittedTimestamp());
125 }

◆ testTestId()

ilTestSessionTest::testTestId ( )

Definition at line 73 of file ilTestSessionTest.php.

73 : void
74 {
75 $test_id = 20;
76 $this->testObj->setTestId($test_id);
77 $this->assertEquals($test_id, $this->testObj->getTestId());
78 }

◆ testUnsetAccessCodeInSession()

ilTestSessionTest::testUnsetAccessCodeInSession ( )

Definition at line 164 of file ilTestSessionTest.php.

164 : void
165 {
167 $access_code = '17';
168 $this->testObj->setAccessCodeToSession($access_code);
169 $this->assertEquals([(int) $access_code], ilSession::get(ilTestSession::ACCESS_CODE_SESSION_INDEX));
170
171 $this->testObj->unsetAccessCodeInSession();
173 }

References ilTestSession\ACCESS_CODE_SESSION_INDEX, ilSession\get(), and ilSession\set().

+ Here is the call graph for this function:

◆ testUserId()

ilTestSessionTest::testUserId ( )

Definition at line 66 of file ilTestSessionTest.php.

66 : void
67 {
68 $user_id = 20;
69 $this->testObj->setUserId($user_id);
70 $this->assertEquals($user_id, $this->testObj->getUserId());
71 }

References $user_id.

Field Documentation

◆ $testObj

ilTestSession ilTestSessionTest::$testObj
private

Definition at line 27 of file ilTestSessionTest.php.


The documentation for this class was generated from the following file: