19 declare(strict_types=1);
38 $this->assertInstanceOf(Repository::class, $repository);
49 $actual = $repository->getPassedParticipants($test_obj_id);
50 foreach ($actual as $index => $participant) {
51 $this->assertEquals($participant[
'active_id'], $query_result[$index][
'active_id']);
52 $this->assertEquals($participant[
'user_id'], $query_result[$index][
'user_id']);
64 $actual = $repository->getTestResult($query_result[
'active_fi']);
66 $this->assertNotNull($actual);
67 $this->assertInstanceOf(ParticipantResult::class, $actual);
68 foreach ($expected as $method => $value) {
69 $this->assertEquals($value, $actual->$method());
78 $actual = $repository->getTestResult(1000);
80 $this->assertNull($actual);
90 $repository->updateTestResultCache($query_result[
'active_fi']);
93 $test_obj_id = $query_result[
'test_obj_id'];
95 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
96 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
97 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
104 $this->assertFalse($repository->isPassed(100, 200));
105 $this->assertFalse($repository->isFailed(100, 200));
106 $this->assertFalse($repository->hasFinished(100, 200));
116 $test_obj_id = $query[
'test_obj_id'];
121 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
122 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
123 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
127 \ilDBInterface::class,
129 $mock->expects($this->exactly(0))->method(
'queryF');
130 $mock->expects($this->exactly(0))->method(
'fetchAssoc');
134 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
135 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
136 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
146 $active_id = $query[
'active_id'];
147 $test_obj_id = $query[
'test_obj_id'];
152 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
153 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
154 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
157 $repository->removeTestResults([$active_id], $test_obj_id);
162 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
163 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
164 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
175 $actual = $repository->getTestAttemptResult($query_result[
'active_fi']);
177 $this->assertNotNull($actual);
178 $this->assertInstanceOf(AttemptResult::class, $actual);
179 foreach ($expected as $method => $value) {
180 $this->assertEquals($value, $actual->$method());
189 $actual = $repository->getTestAttemptResult(1000);
191 $this->assertNull($actual);
200 array $test_config_result,
201 array $working_time_result,
207 $actual = $repository->updateTestAttemptResult(
208 $parameters[
'active_id'],
211 $parameters[
'test_obj_id'],
215 $this->assertNotNull($actual);
216 $this->assertInstanceOf(AttemptResult::class, $actual);
217 $this->assertEqualsWithDelta(time(), $actual->getTimestamp(), 5);
218 foreach ($expected as $method => $value) {
219 $this->assertEquals($value, $actual->$method());
229 $global_cache = $this->createConfiguredMock(
244 $mock_data[
'mark_short'],
245 $mock_data[
'mark_official'],
247 (
bool) $mock_data[
'passed']
249 $mark_schema = $this->createConfiguredMock(
251 [
'getMatchingMark' => $mock]
254 $mark_schema = (
new MarkSchema(0))->createSimpleSchema();
262 public function getMarkSchemaFor(
int $test_id):
MarkSchema 264 return $this->mark_schema;
267 public function storeMarkSchema(
MarkSchema $mark_schema):
void 276 return new class () implements
Container {
277 private array $cache = [];
279 public function lock(
float $seconds):
void 284 public function isLocked():
bool 289 public function has(
string $key):
bool 291 return isset($this->cache[$key]);
294 public function get(
string $key,
Transformation $transformation):
string|
int|array|
bool|
null 296 return $this->cache[$key] ??
null;
299 public function set(
string $key,
string|
int|array|
bool|
null $value, ?
int $ttl =
null):
void 301 $this->cache[$key] = $value;
304 public function delete(
string $key):
void 306 unset($this->cache[$key]);
309 public function flush():
void 314 public function getAdaptorName():
string 319 public function getContainerName():
string 336 \ilDBInterface::class,
337 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
339 ->expects($this->once())
341 ->with($this->stringContains(
"WHERE tst_tests.obj_fi = %s AND tst_result_cache.passed_once = 1"));
344 ->expects($this->once())
346 ->willReturn($fetch_all_return);
356 if ($fetch_assoc_return) {
357 $fetch_assoc_return[
'test_id'] = 0;
373 \ilDBInterface::class,
374 function (\
ilDBInterface|MockObject $mock) use ($table, $fetch_assoc_return) {
376 ->expects($this->once())
380 ->expects($this->once())
381 ->method(
'fetchAssoc')
382 ->willReturn($fetch_assoc_return);
393 \ilDBInterface::class,
394 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_return) {
395 $mock->expects($this->atLeastOnce())->method(
'queryF');
396 $mock->expects($this->atLeastOnce())->method(
'fetchAssoc')->willReturn($fetch_assoc_return);
407 \ilDBInterface::class,
408 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
409 $mock->expects($this->once())
411 ->with($this->equalTo(
"SELECT user_fi FROM tst_active WHERE\n"));
412 $mock->expects($this->once())->method(
'fetchAll')->willReturn($fetch_all_return);
422 $fetch_assoc_mocks = [
425 $test_attempt_result,
429 \ilDBInterface::class,
430 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_mocks) {
432 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
435 $mock->method(
'queryF')->willReturn($mocked_stmt);
437 $mock->expects($this->exactly(count($fetch_assoc_mocks)))
438 ->method(
'fetchAssoc')
439 ->willReturnOnConsecutiveCalls(...$fetch_assoc_mocks);
441 $mock->expects($this->exactly(1))->method(
'replace');
451 $fetch_assoc_mocks = [
460 \ilDBInterface::class,
461 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_mocks) {
463 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
466 $mock->method(
'queryF')->willReturn($mocked_stmt);
468 $mock->expects($this->exactly(count($fetch_assoc_mocks)))
469 ->method(
'fetchAssoc')
470 ->willReturnOnConsecutiveCalls(...$fetch_assoc_mocks);
472 $mock->expects($this->exactly(1))->method(
'replace');
488 [
'user_id' => 1,
'test_obj_id' => 100,
'active_id' => 1000],
489 [
'passed' =>
true,
'failed' =>
false,
'finished' =>
false],
490 [
'isPassed' =>
true,
'isFailed' =>
false,
'hasFinished' =>
false],
493 [
'user_id' => 10,
'test_obj_id' => 100,
'active_id' => 1000],
494 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
false],
495 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
false],
498 [
'user_id' => 1,
'test_obj_id' => 250,
'active_id' => 1400],
499 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
true],
500 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
true],
520 [
'user_id' => 1,
'active_id' => 100],
521 [
'user_id' => 2,
'active_id' => 200],
522 [
'user_id' => 3,
'active_id' => 101],
523 [
'user_id' => 4,
'active_id' => 201],
524 [
'user_id' => 5,
'active_id' => 0],
546 'reached_points' => 0,
547 'mark_short' =>
'failed',
548 'mark_official' =>
'failed',
551 'tstamp' => 1740557748,
557 'isPassedOnce' =>
false,
560 'getMaxPoints' => 25,
561 'getReachedPoints' => 0,
562 'getMarkShort' =>
'failed',
563 'getMarkOfficial' =>
'failed',
564 'getTimestamp' => 1740557748,
589 'questioncount' => 2,
590 'answeredquestions' => 2,
592 'tstamp' => 1740557748,
593 'exam_id' =>
'I0_T334_A41_P0',
594 'finalized_by' =>
null,
595 'last_finished_pass' => 0,
598 'test_obj_id' => 100,
600 'reached_points' => 0,
605 'isPassedOnce' =>
false,
607 'hasFinished' =>
true,
609 'getMaxPoints' => 25,
610 'getReachedPoints' => 0,
611 'getMarkShort' =>
'failed',
612 'getMarkOfficial' =>
'failed',
613 'getTimestamp' => 1740557748,
622 'questioncount' => 2,
623 'answeredquestions' => 2,
625 'tstamp' => 1740557748,
626 'exam_id' =>
'I0_T334_A41_P0',
627 'finalized_by' =>
null,
628 'last_finished_pass' => 1,
631 'test_obj_id' => 100,
633 'reached_points' => 25,
638 'isPassedOnce' =>
true,
640 'hasFinished' =>
true,
642 'getMaxPoints' => 25,
643 'getReachedPoints' => 25,
644 'getMarkShort' =>
'passed',
645 'getMarkOfficial' =>
'passed',
646 'getTimestamp' => 1740557748,
668 'questioncount' => 3,
669 'answeredquestions' => 2,
671 'tstamp' => 1740557748,
672 'exam_id' =>
'I0_T334_A41_P0',
673 'finalized_by' =>
null,
678 'getMaxPoints' => 25,
679 'getReachedPoints' => 0,
680 'getQuestionCount' => 3,
681 'getAnsweredQuestions' => 2,
682 'getWorkingTime' => 12,
683 'getTimestamp' => 1740557748,
684 'getExamId' =>
'I0_T334_A41_P0',
685 'getFinalizedBy' =>
null 709 'test_obj_id' => 100,
715 'answeredquestions' => 2,
724 'started' =>
'2024-01-01 04:05:05',
725 'finished' =>
'2024-01-01 04:05:17' 731 'getMaxPoints' => 25,
732 'getReachedPoints' => 10,
733 'getQuestionCount' => 3,
734 'getAnsweredQuestions' => 2,
735 'getWorkingTime' => 12,
736 'getExamId' =>
'I_T100_A10_P0',
737 'getFinalizedBy' =>
null
static provideFetchedTestAttemptResult()
This method returns sample data for this query:
mockGetUserIds(?array $fetch_all_return)
A class defining mark schemas for assessment test objects.
createInstanceOf(string $class_name, array $explicit_parameters=[])
mockUpdateTestAttemptResult(?array $test_result, ?array $test_config, ?array $working_time)
A class defining marks for assessment test objects.
Interface Observer Contains several chained tasks and infos about them.
mockUpdateTestResultCache(?array $test_attempt_result, bool $passed_once=false)
createInstance(?array $mock_data=null)
createMarksRepositoryMock(?array $mock_data)
mockReadResultStatusQuery(?array $fetch_assoc_return)
static provideCachedStatus()
This method returns test parameter, sample data and expected results for testing status cache...
mockGetResultQuery(string $table, ?array $fetch_assoc_return)
testGetTestResult(array $query_result, array $expected)
provideTestResultCache
testFailedPassedNotFound()
testGetTestAttemptResultNotFound()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
adaptDICServiceMock(string $service_name, callable $adapt)
mockGetTestPassResultQuery(?array $fetch_assoc_return)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
mockGetTestResultQuery(?array $fetch_assoc_return)
__construct()
Constructor setup ILIAS global object public.
mockGetPassedParticipants(array $fetch_all_return)
testUpdateTestAttemptResult(array $parameters, array $test_result, array $test_config_result, array $working_time_result, array $expected)
provideFetchedTestResult
static provideTestAttemptResult()
This method returns sample data for this query:
static provideTestResultCache()
This method returns sample data for this query:
testReadStatus(array $query_result, array $expected)
provideFetchedTestAttemptResult
testGetTestResultNotFound()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testReadFromCache(array $query, array $cached_status, array $expected)
provideCachedStatus
testGetPassedParticipants(int $test_obj_id, array $query_result)
providePassedParticipants
const QUESTION_SET_TYPE_FIXED
testRemoveTestResults(array $query, array $cached_status, array $expected)
provideCachedStatus
static providePassedParticipants()
This method returns sample data for this query:
testGetTestAttemptResult(array $query_result, array $expected)
provideTestAttemptResult
static provideFetchedTestResult()
This method returns sample data for these queries: