19declare(strict_types=1);
33use PHPUnit\Framework\MockObject\MockObject;
40 $this->assertInstanceOf(Repository::class, $repository);
51 $actual = $repository->getPassedParticipants($test_obj_id);
52 foreach ($actual as $index => $participant) {
53 $this->assertEquals($participant[
'active_id'], $query_result[$index][
'active_id']);
54 $this->assertEquals($participant[
'user_id'], $query_result[$index][
'user_id']);
66 $actual = $repository->getTestResult($query_result[
'active_fi']);
68 $this->assertNotNull($actual);
69 $this->assertInstanceOf(ParticipantResult::class, $actual);
70 foreach ($expected as $method => $value) {
71 $this->assertEquals($value, $actual->$method());
80 $actual = $repository->getTestResult(1000);
82 $this->assertNull($actual);
92 $repository->updateTestResultCache($query_result[
'active_fi']);
95 $test_obj_id = $query_result[
'test_obj_id'];
97 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
98 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
99 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
106 $this->assertFalse($repository->isPassed(100, 200));
107 $this->assertFalse($repository->isFailed(100, 200));
108 $this->assertFalse($repository->hasFinished(100, 200));
118 $test_obj_id = $query[
'test_obj_id'];
123 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
124 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
125 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
129 \ilDBInterface::class,
131 $mock->expects($this->exactly(0))->method(
'queryF');
132 $mock->expects($this->exactly(0))->method(
'fetchAssoc');
136 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
137 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
138 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
148 $active_id = $query[
'active_id'];
149 $test_obj_id = $query[
'test_obj_id'];
154 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
155 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
156 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
159 $repository->removeTestResults([$active_id], $test_obj_id);
164 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
165 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
166 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
177 $actual = $repository->getTestAttemptResult($query_result[
'active_fi']);
179 $this->assertNotNull($actual);
180 $this->assertInstanceOf(AttemptResult::class, $actual);
181 foreach ($expected as $method => $value) {
182 $this->assertEquals($value, $actual->$method());
191 $actual = $repository->getTestAttemptResult(1000);
193 $this->assertNull($actual);
202 array $test_config_result,
203 array $working_time_result,
209 $actual = $repository->updateTestAttemptResult(
210 $parameters[
'active_id'],
213 $parameters[
'test_obj_id'],
217 $this->assertNotNull($actual);
218 $this->assertInstanceOf(AttemptResult::class, $actual);
219 $this->assertEqualsWithDelta(time(), $actual->getTimestamp(), 5);
220 foreach ($expected as $method => $value) {
221 $this->assertEquals($value, $actual->$method());
233 $global_cache = $this->createConfiguredMock(
235 [
'get' => $this->createCacheMock()]
238 $partial_mock = $this->getMockBuilder(Repository::class)
239 ->disableOriginalClone()
240 ->disableArgumentCloning()
241 ->disallowMockingUnknownTypes()
242 ->setConstructorArgs([
244 $this->createMock(Refinery::class),
245 $this->createMarksRepositoryMock($mock_data),
248 ->onlyMethods([
'lookupAttempt'])
250 $partial_mock->method(
'lookupAttempt')->willReturn(0);
252 return $partial_mock;
259 $mock_data[
'mark_short'],
260 $mock_data[
'mark_official'],
262 (
bool) $mock_data[
'passed']
264 $mark_schema = $this->createConfiguredMock(
266 [
'getMatchingMark' => $mock]
277 public function getMarkSchemaFor(
int $test_id):
MarkSchema
279 return $this->mark_schema;
282 public function storeMarkSchema(
MarkSchema $mark_schema): array
287 public function getMarkSchemaBySteps(array $step_ids):
MarkSchema
292 public function deleteSteps(array $step_ids):
void
301 return new class () implements
Container {
302 private array $cache = [];
304 public function lock(
float $seconds):
void
309 public function isLocked():
bool
314 public function has(
string $key):
bool
316 return isset($this->cache[$key]);
319 public function get(
string $key,
Transformation $transformation):
string|
int|array|
bool|
null
321 return $this->cache[$key] ??
null;
324 public function set(
string $key,
string|
int|array|
bool|
null $value, ?
int $ttl =
null):
void
326 $this->cache[$key] = $value;
329 public function delete(
string $key):
void
331 unset($this->cache[$key]);
334 public function flush():
void
339 public function getAdaptorName():
string
344 public function getContainerName():
string
361 \ilDBInterface::class,
362 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
364 ->expects($this->once())
366 ->with($this->stringContains(
"WHERE tst_tests.obj_fi = %s AND tst_result_cache.passed_once = 1"));
369 ->expects($this->once())
371 ->willReturn($fetch_all_return);
381 if ($fetch_assoc_return) {
382 $fetch_assoc_return[
'test_id'] = 0;
384 $this->mockGetResultQuery(
'tst_result_cache', $fetch_assoc_return);
392 $this->mockGetResultQuery(
'tst_pass_result', $fetch_assoc_return);
398 \ilDBInterface::class,
399 function (\
ilDBInterface|MockObject $mock) use ($table, $fetch_assoc_return) {
401 ->expects($this->once())
405 ->expects($this->once())
406 ->method(
'fetchAssoc')
407 ->willReturn($fetch_assoc_return);
418 \ilDBInterface::class,
419 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_return) {
420 $mock->expects($this->atLeastOnce())->method(
'queryF');
421 $mock->expects($this->atLeastOnce())->method(
'fetchAssoc')->willReturn($fetch_assoc_return);
432 \ilDBInterface::class,
433 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
434 $mock->expects($this->once())
436 ->with($this->equalTo(
"SELECT user_fi FROM tst_active WHERE\n"));
437 $mock->expects($this->once())->method(
'fetchAll')->willReturn($fetch_all_return);
448 \ilDBInterface::class,
449 function (\
ilDBInterface|MockObject $mock) use ($test_attempt_result) {
451 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
454 $mock->method(
'queryF')->willReturn($mocked_stmt);
457 $mock->expects($this->exactly(1))
458 ->method(
'fetchAssoc')
459 ->willReturn($test_attempt_result);
461 $mock->expects($this->exactly(1))->method(
'replace');
471 $fetch_assoc_mocks = [
480 \ilDBInterface::class,
481 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_mocks) {
483 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
486 $mock->method(
'queryF')->willReturn($mocked_stmt);
488 $mock->expects($this->exactly(count($fetch_assoc_mocks)))
489 ->method(
'fetchAssoc')
490 ->willReturnOnConsecutiveCalls(...$fetch_assoc_mocks);
492 $mock->expects($this->exactly(1))->method(
'replace');
508 [
'user_id' => 1,
'test_obj_id' => 100,
'active_id' => 1000],
509 [
'passed' =>
true,
'failed' =>
false,
'finished' =>
false],
510 [
'isPassed' =>
true,
'isFailed' =>
false,
'hasFinished' =>
false],
513 [
'user_id' => 10,
'test_obj_id' => 100,
'active_id' => 1000],
514 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
false],
515 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
false],
518 [
'user_id' => 1,
'test_obj_id' => 250,
'active_id' => 1400],
519 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
true],
520 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
true],
540 [
'user_id' => 1,
'active_id' => 100],
541 [
'user_id' => 2,
'active_id' => 200],
542 [
'user_id' => 3,
'active_id' => 101],
543 [
'user_id' => 4,
'active_id' => 201],
544 [
'user_id' => 5,
'active_id' => 0],
566 'reached_points' => 0,
567 'mark_short' =>
'failed',
568 'mark_official' =>
'failed',
571 'tstamp' => 1740557748,
577 'isPassedOnce' =>
false,
580 'getMaxPoints' => 25,
581 'getReachedPoints' => 0,
582 'getMarkShort' =>
'failed',
583 'getMarkOfficial' =>
'failed',
584 'getTimestamp' => 1740557748,
609 'questioncount' => 2,
610 'answeredquestions' => 2,
612 'tstamp' => 1740557748,
613 'exam_id' =>
'I0_T334_A41_P0',
614 'finalized_by' =>
null,
615 'last_finished_pass' => 0,
618 'test_obj_id' => 100,
620 'reached_points' => 0,
625 'isPassedOnce' =>
false,
627 'hasFinished' =>
true,
629 'getMaxPoints' => 25,
630 'getReachedPoints' => 0,
631 'getMarkShort' =>
'failed',
632 'getMarkOfficial' =>
'failed',
633 'getTimestamp' => 1740557748,
642 'questioncount' => 2,
643 'answeredquestions' => 2,
645 'tstamp' => 1740557748,
646 'exam_id' =>
'I0_T334_A41_P0',
647 'finalized_by' =>
null,
648 'last_finished_pass' => 1,
651 'test_obj_id' => 100,
653 'reached_points' => 25,
658 'isPassedOnce' =>
true,
660 'hasFinished' =>
true,
662 'getMaxPoints' => 25,
663 'getReachedPoints' => 25,
664 'getMarkShort' =>
'passed',
665 'getMarkOfficial' =>
'passed',
666 'getTimestamp' => 1740557748,
688 'questioncount' => 3,
689 'answeredquestions' => 2,
691 'tstamp' => 1740557748,
692 'exam_id' =>
'I0_T334_A41_P0',
693 'finalized_by' =>
null,
698 'getMaxPoints' => 25,
699 'getReachedPoints' => 0,
700 'getQuestionCount' => 3,
701 'getAnsweredQuestions' => 2,
702 'getWorkingTime' => 12,
703 'getTimestamp' => 1740557748,
704 'getExamId' =>
'I0_T334_A41_P0',
705 'getFinalizedBy' => null
729 'test_obj_id' => 100,
735 'answeredquestions' => 2,
744 'started' =>
'2024-01-01 04:05:05',
745 'finished' =>
'2024-01-01 04:05:17'
751 'getMaxPoints' => 25,
752 'getReachedPoints' => 10,
753 'getQuestionCount' => 3,
754 'getAnsweredQuestions' => 2,
755 'getWorkingTime' => 12,
756 'getExamId' =>
'I_T100_A10_P0',
757 'getFinalizedBy' => null
Class ParticipantResult is a model representation of an entry in the test_result_cache table.
A class defining mark schemas for assessment test objects.
A class defining marks for assessment test objects.
mockGetUserIds(?array $fetch_all_return)
testGetTestAttemptResult(array $query_result, array $expected)
@dataProvider provideTestAttemptResult
testGetTestResult(array $query_result, array $expected)
@dataProvider provideTestResultCache
testRemoveTestResults(array $query, array $cached_status, array $expected)
@dataProvider provideCachedStatus
mockUpdateTestResultCache(?array $test_attempt_result, bool $passed_once=false)
mockUpdateTestAttemptResult(?array $test_result, ?array $test_config, ?array $working_time)
testReadStatus(array $query_result, array $expected)
@dataProvider provideFetchedTestAttemptResult
testReadFromCache(array $query, array $cached_status, array $expected)
@dataProvider provideCachedStatus
mockReadResultStatusQuery(?array $fetch_assoc_return)
mockGetResultQuery(string $table, ?array $fetch_assoc_return)
testGetTestAttemptResultNotFound()
createMarksRepositoryMock(?array $mock_data)
testGetTestResultNotFound()
testGetPassedParticipants(int $test_obj_id, array $query_result)
@dataProvider providePassedParticipants
static provideFetchedTestResult()
This method returns sample data for these queries:
static provideTestAttemptResult()
This method returns sample data for this query:
static provideFetchedTestAttemptResult()
This method returns sample data for this query:
testUpdateTestAttemptResult(array $parameters, array $test_result, array $test_config_result, array $working_time_result, array $expected)
@dataProvider provideFetchedTestResult
static provideCachedStatus()
This method returns test parameter, sample data and expected results for testing status cache.
mockGetPassedParticipants(array $fetch_all_return)
mockGetTestPassResultQuery(?array $fetch_assoc_return)
mockGetTestResultQuery(?array $fetch_assoc_return)
static providePassedParticipants()
This method returns sample data for this query:
testFailedPassedNotFound()
createInstance(?array $mock_data=null)
static provideTestResultCache()
This method returns sample data for this query:
__construct()
Constructor setup ILIAS global object @access public.
const QUESTION_SET_TYPE_FIXED
adaptDICServiceMock(string $service_name, callable $adapt)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.