ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
PositionsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
24
25class PositionsTest extends TestCase
26{
28
29 protected function setUp(): void
30 {
31 parent::setUp();
32 $user_questions = [
33 100 => [400, 401, 402, 403],
34 101 => [401, 403],
35 102 => [400, 402, 404],
36 103 => [403]
37 ];
38 $this->positions = new Positions($user_questions, [], []);
39 }
40
41 public function testPositions(): void
42 {
43 $this->assertInstanceOf(Positions::class, $this->positions);
44 $this->assertEquals([], $this->positions->getAllQuestionProperties());
45 $this->assertEquals([], $this->positions->getAllAttempts());
46 }
47
48 public function testPositionsModeAllByUsers(): void
49 {
50 $mode = new ConsecutiveScoringMode(
51 ConsecutiveScoringMode::ORIENTATION_USER,
52 ConsecutiveScoringMode::MODE_ALL_AT_ONCE,
53 );
54 $expected = [
55 [[100],[400, 401, 402, 403]],
56 [[101],[401, 403]],
57 [[102],[400, 402, 404]],
58 [[103],[403]],
59 ];
60 $this->assertEquals($expected, $this->positions->get($mode));
61 }
62
63 public function testPositionsModeAllByQuestion(): void
64 {
65 $mode = new ConsecutiveScoringMode(
66 ConsecutiveScoringMode::ORIENTATION_QUESTION,
67 ConsecutiveScoringMode::MODE_ALL_AT_ONCE,
68 );
69 $expected = [
70 [[100, 102],[400]],
71 [[100, 101],[401]],
72 [[100, 102],[402]],
73 [[100, 101, 103],[403]],
74 [[102], [404]],
75 ];
76 $this->assertEquals($expected, $this->positions->get($mode));
77 }
78
79 public function testPositionsModeSingleByUser(): void
80 {
81 $mode = new ConsecutiveScoringMode(
82 ConsecutiveScoringMode::ORIENTATION_USER,
83 ConsecutiveScoringMode::MODE_ONE_BY_ONE,
84 );
85 $expected = [
86 [[100],[400]],
87 [[100],[401]],
88 [[100],[402]],
89 [[100],[403]],
90 [[101],[401]],
91 [[101],[403]],
92 [[102],[400]],
93 [[102],[402]],
94 [[102],[404]],
95 [[103],[403]]
96 ];
97 $this->assertEquals($expected, $this->positions->get($mode));
98 }
99
100 public function testPositionsModeSingleByQuestion(): void
101 {
102 $mode = new ConsecutiveScoringMode(
103 ConsecutiveScoringMode::ORIENTATION_QUESTION,
104 ConsecutiveScoringMode::MODE_ONE_BY_ONE,
105 );
106 $expected = [
107 [[100],[400]],
108 [[102],[400]],
109 [[100],[401]],
110 [[101],[401]],
111 [[100],[402]],
112 [[102],[402]],
113 [[100],[403]],
114 [[101],[403]],
115 [[103],[403]],
116 [[102],[404]]
117 ];
118 $this->assertEquals($expected, $this->positions->get($mode));
119 }
120
121 public function testPositionsFilter(): void
122 {
123 $mode = new ConsecutiveScoringMode(
124 ConsecutiveScoringMode::ORIENTATION_QUESTION,
125 ConsecutiveScoringMode::MODE_ONE_BY_ONE,
126 );
127
128 $filter_users = static fn(array $uids, array $qids): array => [
129 array_intersect($uids, [100, 102]),
130 $qids
131 ];
132 $filter_questions = static fn(array $uids, array $qids): array => [
133 $uids,
134 array_intersect($qids, [400, 402, 404]),
135 ];
136
137 $positions = $this->positions->applyFilters(
138 $filter_users,
139 $filter_questions
140 );
141
142 $expected = [
143 [[100],[400]],
144 [[102],[400]],
145 [[100],[402]],
146 [[102],[402]],
147 [[102],[404]]
148 ];
149 $this->assertEquals($expected, $positions->get($mode));
150 }
151}
applyFilters(\Closure ... $filters)
Definition: Positions.php:62
get(ConsecutiveScoringMode $mode)
Definition: Positions.php:47
testPositionsModeSingleByQuestion()
testPositionsModeAllByUsers()
Positions $positions
testPositionsModeSingleByUser()
testPositionsModeAllByQuestion()