ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TestPlaceholderValuesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
24
28class TestPlaceholderValuesTest extends TestCase
29{
30 public function testA(): void
31 {
32 $default_placeholder_values = $this->getMockBuilder(\ilDefaultPlaceholderValues::class)
33 ->disableOriginalConstructor()
34 ->getMock();
35
36 $language = $this->getMockBuilder(\ilLanguage::class)
37 ->disableOriginalConstructor()
38 ->getMock();
39
40 $language->method('txt')
41 ->willReturn('Some Translation');
42
43 $object_helper = $this->getMockBuilder(\ilCertificateObjectHelper::class)
44 ->getMock();
45
46 $test_object = $this->getMockBuilder(\ilObjTest::class)
47 ->disableOriginalConstructor()
48 ->getMock();
49
50 $test_object->method('getActiveIdOfUser')
51 ->willReturn(999);
52
53 $test_object->method('getTestResult')
54 ->willReturn(
55 [
56 'test' => [
57 'passed' => true,
58 'total_max_points' => 70,
59 'total_reached_points' => 50
60 ]
61 ]
62 );
63
64 $test_object->method('getTestResult')
65 ->willReturn([]);
66
67 $test_object->method('getTitle')
68 ->willReturn(' Some Title');
69
70 $mark_schema = $this->getMockBuilder(\ILIAS\Test\Scoring\Marks\MarkSchema::class)
71 ->disableOriginalConstructor()
72 ->getMock();
73
74 $matching_mark = $this->getMockBuilder(\ILIAS\Test\Scoring\Marks\Mark::class)
75 ->getMock();
76
77 $matching_mark->method('getShortName')
78 ->willReturn('aaa');
79
80 $matching_mark->method('getOfficialName')
81 ->willReturn('bbb');
82
83 $mark_schema->method('getMatchingMark')
84 ->willReturn($matching_mark);
85
86 $test_object->method('getMarkSchema')
87 ->willReturn($mark_schema);
88
89 $user_object = $this->getMockBuilder(\ilObjUser::class)
90 ->disableOriginalConstructor()
91 ->getMock();
92
93 $object_helper->method('getInstanceByObjId')
94 ->willReturnMap(
95 [
96 [200, $test_object],
97 [10, $user_object]
98 ]
99 );
100
101 $test_object_helper = $this->getMockBuilder(CertificateTestObjectHelper::class)
102 ->getMock();
103
104 $user_object_helper = $this->getMockBuilder(\ilCertificateUserObjectHelper::class)
105 ->getMock();
106
107 $user_object_helper->method('lookupFields')
108 ->willReturn(['usr_id' => 10]);
109
110 $lp_status_helper = $this->getMockBuilder(\ilCertificateLPStatusHelper::class)
111 ->getMock();
112
113 $lp_status_helper->method('lookupStatusChanged')
114 ->willReturn('2018-01-12');
115
116 $util_helper = $this->getMockBuilder(\ilCertificateUtilHelper::class)
117 ->disableOriginalConstructor()
118 ->getMock();
119
120 $util_helper->method('prepareFormOutput')
121 ->willReturn('Formatted Output');
122
123 $date_helper = $this->getMockBuilder(\ilCertificateDateHelper::class)
124 ->getMock();
125
126 $date_helper->method('formatDate')
127 ->willReturn('2018-01-12');
128
129 $date_helper->method('formatDateTime')
130 ->willReturn('2018-01-12 10:32:01');
131
132 $placeholder_values = new TestPlaceholderValues(
133 $default_placeholder_values,
134 $language,
135 $object_helper,
136 $test_object_helper,
137 $user_object_helper,
138 $lp_status_helper,
139 $util_helper,
140 $date_helper
141 );
142
143 $result = $placeholder_values->getPlaceholderValues(10, 200);
144
145 $this->assertSame([
146 'RESULT_PASSED' => 'Formatted Output',
147 'RESULT_POINTS' => 'Formatted Output',
148 'RESULT_PERCENT' => '71.43%',
149 'MAX_POINTS' => 'Formatted Output',
150 'RESULT_MARK_SHORT' => 'Formatted Output',
151 'RESULT_MARK_LONG' => 'Formatted Output',
152 'TEST_TITLE' => 'Formatted Output',
153 'DATE_COMPLETED' => '2018-01-12',
154 'DATETIME_COMPLETED' => '2018-01-12 10:32:01'
155 ], $result);
156 }
157
159 {
160 $default_placeholder_values = $this->getMockBuilder(\ilDefaultPlaceholderValues::class)
161 ->disableOriginalConstructor()
162 ->getMock();
163
164 $default_placeholder_values->method('getPlaceholderValuesForPreview')
165 ->willReturn(
166 [
167 'SOME_PLACEHOLDER' => 'something',
168 'SOME_OTHER_PLACEHOLDER' => 'something else',
169 ]
170 );
171
172 $language = $this->getMockBuilder(\ilLanguage::class)
173 ->disableOriginalConstructor()
174 ->getMock();
175
176 $language->method('txt')
177 ->willReturn('Something');
178
179 $object_mock = $this->getMockBuilder(\ilObject::class)
180 ->disableOriginalConstructor()
181 ->getMock();
182
183 $object_mock->method('getTitle')
184 ->willReturn('SomeTitle');
185
186 $object_helper = $this->getMockBuilder(\ilCertificateObjectHelper::class)
187 ->getMock();
188
189 $object_helper->method('getInstanceByObjId')
190 ->willReturn($object_mock);
191
192 $test_object_helper = $this->getMockBuilder(CertificateTestObjectHelper::class)
193 ->getMock();
194
195 $user_object_helper = $this->getMockBuilder(\ilCertificateUserObjectHelper::class)
196 ->getMock();
197
198 $lp_status_helper = $this->getMockBuilder(\ilCertificateLPStatusHelper::class)
199 ->getMock();
200
201 $util_helper = $this->getMockBuilder(\ilCertificateUtilHelper::class)
202 ->disableOriginalConstructor()
203 ->getMock();
204
205 $util_helper->method('prepareFormOutput')
206 ->willReturnCallback(function ($input) {
207 return $input;
208 });
209
210 $date_helper = $this->getMockBuilder(\ilCertificateDateHelper::class)
211 ->getMock();
212
213 $placeholder_values = new TestPlaceholderValues(
214 $default_placeholder_values,
215 $language,
216 $object_helper,
217 $test_object_helper,
218 $user_object_helper,
219 $lp_status_helper,
220 $util_helper,
221 $date_helper
222 );
223
224 $result = $placeholder_values->getPlaceholderValuesForPreview(100, 10);
225
226 $this->assertSame(
227 [
228 'SOME_PLACEHOLDER' => 'something',
229 'SOME_OTHER_PLACEHOLDER' => 'something else',
230 'RESULT_PASSED' => 'Something',
231 'RESULT_POINTS' => 'Something',
232 'RESULT_PERCENT' => 'Something',
233 'MAX_POINTS' => 'Something',
234 'RESULT_MARK_SHORT' => 'Something',
235 'RESULT_MARK_LONG' => 'Something',
236 'TEST_TITLE' => 'SomeTitle'
237 ],
238 $result
239 );
240 }
241}
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.