ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTestEvaluationDataTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
27
28 protected function setUp(): void
29 {
30 parent::setUp();
31 $user_data = [
34 ];
35 $this->testObj = new ilTestEvaluationData($user_data);
36 }
37
39 {
40 $this->assertInstanceOf(ilTestEvaluationData::class, $this->testObj);
41 }
42
43 public function test__sleep(): void
44 {
45 $expected = ['question_titles', 'participants', 'statistics', 'arr_filter', 'datasets', 'test'];
46
47 $this->assertEquals($expected, $this->testObj->__sleep());
48 }
49
50 public function testDatasets(): void
51 {
52 $this->testObj->setDatasets(20);
53
54 $this->assertEquals(20, $this->testObj->getDatasets());
55 }
56
57 public function testQuestionTitle(): void
58 {
59 $expected = [
60 120 => 'abcd',
61 121 => 'Hello',
62 2150 => 'World',
63 ];
64
65 foreach ($expected as $questionId => $questionTitle) {
66 $this->testObj->addQuestionTitle($questionId, $questionTitle);
67
68 $this->assertEquals($questionTitle, $this->testObj->getQuestionTitle($questionId));
69 }
70
71 $this->assertEquals($expected, $this->testObj->getQuestionTitles());
72
73 $this->assertEquals($expected[2150], $this->testObj->getQuestionTitle(2150));
74 }
75
76 public function testEvaluationFactory(): void
77 {
78 $records = [];
79 $records[] = [
80 "active_id" => 7 ,
81 "question_fi" => 9,
82 "result_points" => 1.2,
83 "answered" => true,
84 "manual" => 1,
85 "original_id" => null,
86 "questiontitle" => "some title",
87 "qpl_maxpoints" => 2.4,
88 "submitted" => true,
89 "last_finished_pass" => 1,
90 "pass" => 1,
91 "points" => 10.3,
92 "maxpoints" => 32,
93 "questioncount" => 32,
94 "answeredquestions" => 1,
95 "workingtime" => 28,
96 "tstamp" => 1731941437,
97 "obligations_answered" => true,
98 "exam_id" => "I0_T355_A7_P1",
99 "usr_id" => 6,
100 "firstname" => "root",
101 "lastname" => "user",
102 "title" => "",
103 "login" => "root",
104 "finalized_by" => null
105 ];
106 $records[] = ['first_access' => '2024-12-11 17:54:26'];
107 $records[] = null;
108
109 $test_obj = $this->createMock(ilObjTest::class);
110 $test_obj
111 ->expects($this->once())
112 ->method('getPassScoring');
113 $test_obj
114 ->expects($this->once())
115 ->method('getAccessFilteredParticipantList')
116 ->willReturn(null);
117 $test_obj
118 ->expects($this->once())
119 ->method('getTestParticipants')
120 ->willReturn([7]);
121 $test_obj
122 ->expects($this->once())
123 ->method('getVisitingTimeOfParticipant')
124 ->willReturn(
125 [
126 'first_access' => new \DateTimeImmutable(),
127 'last_access' => new \DateTimeImmutable()
128 ]
129 );
130
131 $db = $this->createMock(ilDBInterface::class);
132 $db
133 ->expects($this->exactly(3))
134 ->method('fetchAssoc')
135 ->willReturnCallback(
136 function ($res) use (&$records) {
137 return array_shift($records);
138 }
139 );
140
141 $factory = new ilTestEvaluationFactory($db, $test_obj);
142 $data = $factory->getEvaluationData();
143 $this->assertInstanceOf(ilTestEvaluationData::class, $data);
144
145 $this->assertEquals(
146 [7],
147 $data->getParticipantIds()
148 );
149 $this->assertInstanceOf(
150 ilTestEvaluationUserData::class,
151 $data->getParticipant(7)
152 );
153 }
154}
Class ilTestBaseClass.
$res
Definition: ltiservices.php:69