ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilScormPlaceholderValuesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected function setUp(): void
24  {
25  parent::setUp();
26  global $DIC;
27  $DIC['file_delivery'] = $this->createMock(\ILIAS\FileDelivery\Services::class);
28  }
29 
30  public function testGetPlaceholderValues(): void
31  {
32  $defaultPlaceholderValues = $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  ->willReturnCallback(function ($variableValue) {
42  if ($variableValue === 'lang_sep_decimal') {
43  return ',';
44  } elseif ($variableValue === 'lang_sep_thousand') {
45  return '.';
46  }
47 
48  return 'Some Translation: ' . $variableValue;
49  });
50 
51  $language->expects($this->once())
52  ->method('loadLanguageModule');
53 
54  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
55  ->getMock();
56 
57  $objectMock = $this->getMockBuilder(ilObjSAHSLearningModule::class)
58  ->disableOriginalConstructor()
59  ->onlyMethods(['getPointsInPercent', 'getMaxPoints', 'getTitle', 'getId'])
60  ->getMock();
61 
62  $objectMock->method('getPointsInPercent')
63  ->willReturn(100.0);
64 
65  $objectMock->method('getMaxPoints')
66  ->willReturn(100.0);
67 
68  $objectMock->method('getTitle')
69  ->willReturn('SomeTitle');
70 
71  $objectMock->method('getId')
72  ->willReturn(500);
73 
74  $user_object = $this->getMockBuilder(ilObjUser::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77 
78  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
79  ->getMock();
80  $objectHelper->method('getInstanceByObjId')
81  ->willReturnMap(
82  [
83  [200, $objectMock],
84  [10, $user_object]
85  ]
86  );
87 
88  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
89  ->getMock();
90 
91  $utilHelper->method('prepareFormOutput')
92  ->willReturn('Formatted String');
93 
94  $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
95  ->getMock();
96 
97  $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
98  ->disableOriginalConstructor()
99  ->onlyMethods(['getPossibleItems', 'getScoresForUserAndCP_Node_Id', 'isAssignedEntry'])
100  ->getMock();
101 
102  $lpCollection->method('getPossibleItems')
103  ->willReturn([100 => ['title' => 'Some Title']]);
104 
105  $lpCollection->method('getScoresForUserAndCP_Node_Id')
106  ->willReturn(
107  [
108  'raw' => 100,
109  'max' => 300,
110  'scaled' => 2
111  ]
112  );
113 
114  $lpCollection->method('isAssignedEntry')
115  ->willReturn(true);
116 
117  $olp = $this->getMockBuilder(ilObjectLP::class)
118  ->disableOriginalConstructor()
119  ->onlyMethods(['getCollectionInstance'])
120  ->getMock();
121 
122  $olp->method('getCollectionInstance')
123  ->willReturn($lpCollection);
124 
125  $objectLPHelper->method('getInstance')
126  ->willReturn($olp);
127 
128  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
129  ->getMock();
130 
131  $lpStatusHelper->method('lookupStatusChanged')
132  ->willReturn('2018-12-01 13:00:11');
133 
134  $scormPlaceholderValues = new ilScormPlaceholderValues(
135  $defaultPlaceholderValues,
136  $language,
137  $dateHelper,
138  $objectHelper,
139  $utilHelper,
140  $objectLPHelper,
141  $lpStatusHelper
142  );
143 
144  $result = $scormPlaceholderValues->getPlaceholderValues(10, 200);
145 
146  $this->assertEquals(
147  [
148  'SCORM_TITLE' => 'Formatted String',
149  'SCORM_POINTS' => '100,0 %',
150  'SCORM_POINTS_MAX' => 100,
151  'SCO_T_0' => 'Some Title',
152  'SCO_P_0' => '100,0',
153  'SCO_PM_0' => '300,0',
154  'SCO_PP_0' => '200,0 %',
155  'DATE_COMPLETED' => '',
156  'DATETIME_COMPLETED' => ''
157  ],
158  $result
159  );
160  }
161 
162  public function testGetPlaceholderValuesForPreview(): void
163  {
164  $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
165  ->disableOriginalConstructor()
166  ->getMock();
167 
168  $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
169  ->willReturn(
170  [
171  'SOME_PLACEHOLDER' => 'aaa',
172  'SOME_OTHER_PLACEHOLDER' => 'bbb'
173  ]
174  );
175 
176  $language = $this->getMockBuilder(ilLanguage::class)
177  ->disableOriginalConstructor()
178  ->getMock();
179 
180  $language->method('txt')
181  ->willReturnCallback(function ($variableValue) {
182  if ($variableValue === 'lang_sep_decimal') {
183  return ',';
184  } elseif ($variableValue === 'lang_sep_thousand') {
185  return '.';
186  }
187 
188  return 'Some Translation: ' . $variableValue;
189  });
190 
191  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
192  ->getMock();
193 
194  $objectMock = $this->getMockBuilder(ilObject::class)
195  ->disableOriginalConstructor()
196  ->getMock();
197 
198  $objectMock->method('getTitle')
199  ->willReturn('Some Title');
200 
201  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
202  ->getMock();
203 
204  $objectHelper->method('getInstanceByObjId')
205  ->willReturn($objectMock);
206 
207  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
208  ->getMock();
209 
210  $utilHelper->method('prepareFormOutput')
211  ->willReturnCallback(function ($input) {
212  return $input;
213  });
214 
215  $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
216  ->getMock();
217 
218  $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
219  ->disableOriginalConstructor()
220  ->onlyMethods(['getPossibleItems', 'isAssignedEntry'])
221  ->getMock();
222 
223  $lpCollection->method('getPossibleItems')
224  ->willReturn([
225  [
226  'title' => 'Some Title'
227  ],
228  [
229  'title' => 'Some Other Title'
230  ]
231  ]);
232 
233  $lpCollection->method('isAssignedEntry')
234  ->willReturn(true);
235 
236  $objectLPMock = $this->getMockBuilder(ilObjectLP::class)
237  ->disableOriginalConstructor()
238  ->getMock();
239 
240  $objectLPMock->method('getCollectionInstance')
241  ->willReturn($lpCollection);
242 
243  $objectLPHelper->method('getInstance')
244  ->willReturn($objectLPMock);
245 
246  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
247  ->getMock();
248 
249  $scormPlaceholderValues = new ilScormPlaceholderValues(
250  $defaultPlaceholderValues,
251  $language,
252  $dateHelper,
253  $objectHelper,
254  $utilHelper,
255  $objectLPHelper,
256  $lpStatusHelper
257  );
258 
259  $result = $scormPlaceholderValues->getPlaceholderValuesForPreview(100, 10);
260 
261  $this->assertEquals(
262  [
263  'SCORM_TITLE' => 'Some Title',
264  'SCORM_POINTS' => '80,7 %',
265  'SCORM_POINTS_MAX' => '90',
266  'SCO_T_0' => 'Some Title',
267  'SCO_P_0' => '30,3',
268  'SCO_PM_0' => '90,9',
269  'SCO_PP_0' => '33,3 %',
270  'SCO_T_1' => 'Some Other Title',
271  'SCO_P_1' => '30,3',
272  'SCO_PM_1' => '90,9',
273  'SCO_PP_1' => '33,3 %',
274  'SOME_PLACEHOLDER' => 'aaa',
275  'SOME_OTHER_PLACEHOLDER' => 'bbb'
276  ],
277  $result
278  );
279  }
280 }
Interface Observer Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26