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