ILIAS  release_7 Revision v7.30-3-g800a261c036
ilScormPlaceholderValuesTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
9 public function testGetPlaceholderValues()
10 {
11 $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $language = $this->getMockBuilder(ilLanguage::class)
16 ->disableOriginalConstructor()
17 ->getMock();
18
19 $language->method('txt')
20 ->willReturnCallback(function ($variableValue) {
21 if ($variableValue === 'lang_sep_decimal') {
22 return ',';
23 } elseif ($variableValue === 'lang_sep_thousand') {
24 return '.';
25 }
26
27 return 'Some Translation: ' . $variableValue;
28 });
29
30 $language->expects($this->once())
31 ->method('loadLanguageModule');
32
33 $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
34 ->getMock();
35
36 $objectMock = $this->getMockBuilder(ilObjSAHSLearningModule::class)
37 ->disableOriginalConstructor()
38 ->onlyMethods(['getPointsInPercent', 'getMaxPoints', 'getTitle', 'getId'])
39 ->getMock();
40
41 $objectMock->method('getPointsInPercent')
42 ->willReturn(100);
43
44 $objectMock->method('getMaxPoints')
45 ->willReturn(100);
46
47 $objectMock->method('getTitle')
48 ->willReturn('SomeTitle');
49
50 $objectMock->method('getId')
51 ->willReturn(500);
52
53 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
54 ->getMock();
55
56 $objectHelper->method('getInstanceByObjId')
57 ->willReturn($objectMock);
58
59 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
60 ->getMock();
61
62 $utilHelper->method('prepareFormOutput')
63 ->willReturn('Formatted String');
64
65 $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
66 ->getMock();
67
68 $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
69 ->disableOriginalConstructor()
70 ->onlyMethods(['getPossibleItems', 'getScoresForUserAndCP_Node_Id', 'isAssignedEntry'])
71 ->getMock();
72
73 $lpCollection->method('getPossibleItems')
74 ->willReturn(array(100 => array('title' => 'Some Title')));
75
76 $lpCollection->method('getScoresForUserAndCP_Node_Id')
77 ->willReturn(
78 array(
79 'raw' => 100,
80 'max' => 300,
81 'scaled' => 2
82 )
83 );
84
85 $lpCollection->method('isAssignedEntry')
86 ->willReturn(true);
87
88 $olp = $this->getMockBuilder(ilObjectLP::class)
89 ->disableOriginalConstructor()
90 ->onlyMethods(['getCollectionInstance'])
91 ->getMock();
92
93 $olp->method('getCollectionInstance')
94 ->willReturn($lpCollection);
95
96 $objectLPHelper->method('getInstance')
97 ->willReturn($olp);
98
99 $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
100 ->getMock();
101
102 $lpStatusHelper->method('lookupStatusChanged')
103 ->willReturn('2018-12-01 13:00:11');
104
105 $scormPlaceholderValues = new ilScormPlaceholderValues(
106 $defaultPlaceholderValues,
107 $language,
108 $dateHelper,
109 $objectHelper,
110 $utilHelper,
111 $objectLPHelper,
112 $lpStatusHelper
113 );
114
115 $result = $scormPlaceholderValues->getPlaceholderValues(10, 200);
116
117 $this->assertEquals(
118 array(
119 'SCORM_TITLE' => 'Formatted String',
120 'SCORM_POINTS' => '100,0 %',
121 'SCORM_POINTS_MAX' => 100,
122 'SCO_T_0' => 'Some Title',
123 'SCO_P_0' => '100,0',
124 'SCO_PM_0' => '300,0',
125 'SCO_PP_0' => '200,0 %',
126 'DATE_COMPLETED' => '',
127 'DATETIME_COMPLETED' => ''
128 ),
129 $result
130 );
131 }
132
134 {
135 $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
136 ->disableOriginalConstructor()
137 ->getMock();
138
139 $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
140 ->willReturn(
141 array(
142 'SOME_PLACEHOLDER' => 'aaa',
143 'SOME_OTHER_PLACEHOLDER' => 'bbb'
144 )
145 );
146
147 $language = $this->getMockBuilder(ilLanguage::class)
148 ->disableOriginalConstructor()
149 ->getMock();
150
151 $language->method('txt')
152 ->willReturnCallback(function ($variableValue) {
153 if ($variableValue === 'lang_sep_decimal') {
154 return ',';
155 } elseif ($variableValue === 'lang_sep_thousand') {
156 return '.';
157 }
158
159 return 'Some Translation: ' . $variableValue;
160 });
161
162 $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
163 ->getMock();
164
165 $objectMock = $this->getMockBuilder(ilObject::class)
166 ->disableOriginalConstructor()
167 ->getMock();
168
169 $objectMock->method('getTitle')
170 ->willReturn('Some Title');
171
172 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
173 ->getMock();
174
175 $objectHelper->method('getInstanceByObjId')
176 ->willReturn($objectMock);
177
178 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
179 ->getMock();
180
181 $utilHelper->method('prepareFormOutput')
182 ->willReturnCallback(function ($input) {
183 return $input;
184 });
185
186 $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
187 ->getMock();
188
189 $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
190 ->disableOriginalConstructor()
191 ->onlyMethods(['getPossibleItems', 'isAssignedEntry'])
192 ->getMock();
193
194 $lpCollection->method('getPossibleItems')
195 ->willReturn(array(
196 array(
197 'title' => 'Some Title'
198 ),
199 array(
200 'title' => 'Some Other Title'
201 )
202 ));
203
204 $lpCollection->method('isAssignedEntry')
205 ->willReturn(true);
206
207 $objectLPMock = $this->getMockBuilder(ilObjectLP::class)
208 ->disableOriginalConstructor()
209 ->getMock();
210
211 $objectLPMock->method('getCollectionInstance')
212 ->willReturn($lpCollection);
213
214 $objectLPHelper->method('getInstance')
215 ->willReturn($objectLPMock);
216
217 $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
218 ->getMock();
219
220 $scormPlaceholderValues = new ilScormPlaceholderValues(
221 $defaultPlaceholderValues,
222 $language,
223 $dateHelper,
224 $objectHelper,
225 $utilHelper,
226 $objectLPHelper,
227 $lpStatusHelper
228 );
229
230 $result = $scormPlaceholderValues->getPlaceholderValuesForPreview(100, 10);
231
232 $this->assertEquals(
233 array(
234 'SCORM_TITLE' => 'Some Title',
235 'SCORM_POINTS' => '80,7 %',
236 'SCORM_POINTS_MAX' => '90',
237 'SCO_T_0' => 'Some Title',
238 'SCO_P_0' => '30,3',
239 'SCO_PM_0' => '90,9',
240 'SCO_PP_0' => '33,3 %',
241 'SCO_T_1' => 'Some Other Title',
242 'SCO_P_1' => '30,3',
243 'SCO_PM_1' => '90,9',
244 'SCO_PP_1' => '33,3 %',
245 'SOME_PLACEHOLDER' => 'aaa',
246 'SOME_OTHER_PLACEHOLDER' => 'bbb'
247 ),
248 $result
249 );
250 }
251}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilCertificateBaseTestCase.