ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilTestEvaluationDataTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  "hint_count" => 0,
98  "hint_points" => 0,
99  "obligations_answered" => true,
100  "exam_id" => "I0_T355_A7_P1",
101  "usr_id" => 6,
102  "firstname" => "root",
103  "lastname" => "user",
104  "title" => "",
105  "login" => "root",
106  "finalized_by" => null
107  ];
108  $records[] = ['first_access' => '2024-12-11 17:54:26'];
109  $records[] = null;
110 
111  $test_obj = $this->createMock(ilObjTest::class);
112  $test_obj
113  ->expects($this->once())
114  ->method('getPassScoring');
115  $test_obj
116  ->expects($this->once())
117  ->method('getAccessFilteredParticipantList')
118  ->willReturn(null);
119  $test_obj
120  ->expects($this->once())
121  ->method('getTestParticipants')
122  ->willReturn([7]);
123  $test_obj
124  ->expects($this->once())
125  ->method('getVisitingTimeOfParticipant')
126  ->willReturn(
127  [
128  'first_access' => new \DateTimeImmutable(),
129  'last_access' => new \DateTimeImmutable()
130  ]
131  );
132 
133  $db = $this->createMock(ilDBInterface::class);
134  $db
135  ->expects($this->exactly(3))
136  ->method('fetchAssoc')
137  ->willReturnCallback(
138  function ($res) use (&$records) {
139  return array_shift($records);
140  }
141  );
142 
143  $factory = new ilTestEvaluationFactory($db, $test_obj);
144  $data = $factory->getEvaluationData();
145  $this->assertInstanceOf(ilTestEvaluationData::class, $data);
146 
147  $this->assertEquals(
148  [7],
149  $data->getParticipantIds()
150  );
151  $this->assertInstanceOf(
152  ilTestEvaluationUserData::class,
153  $data->getParticipant(7)
154  );
155  }
156 }
$res
Definition: ltiservices.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null