ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
75  ->getMock();
76 
77  $objectHelper->method('getInstanceByObjId')
78  ->willReturn($objectMock);
79 
80  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
81  ->getMock();
82 
83  $utilHelper->method('prepareFormOutput')
84  ->willReturn('Formatted String');
85 
86  $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
87  ->getMock();
88 
89  $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
90  ->disableOriginalConstructor()
91  ->onlyMethods(['getPossibleItems', 'getScoresForUserAndCP_Node_Id', 'isAssignedEntry'])
92  ->getMock();
93 
94  $lpCollection->method('getPossibleItems')
95  ->willReturn([100 => ['title' => 'Some Title']]);
96 
97  $lpCollection->method('getScoresForUserAndCP_Node_Id')
98  ->willReturn(
99  [
100  'raw' => 100,
101  'max' => 300,
102  'scaled' => 2
103  ]
104  );
105 
106  $lpCollection->method('isAssignedEntry')
107  ->willReturn(true);
108 
109  $olp = $this->getMockBuilder(ilObjectLP::class)
110  ->disableOriginalConstructor()
111  ->onlyMethods(['getCollectionInstance'])
112  ->getMock();
113 
114  $olp->method('getCollectionInstance')
115  ->willReturn($lpCollection);
116 
117  $objectLPHelper->method('getInstance')
118  ->willReturn($olp);
119 
120  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
121  ->getMock();
122 
123  $lpStatusHelper->method('lookupStatusChanged')
124  ->willReturn('2018-12-01 13:00:11');
125 
126  $scormPlaceholderValues = new ilScormPlaceholderValues(
127  $defaultPlaceholderValues,
128  $language,
129  $dateHelper,
130  $objectHelper,
131  $utilHelper,
132  $objectLPHelper,
133  $lpStatusHelper
134  );
135 
136  $result = $scormPlaceholderValues->getPlaceholderValues(10, 200);
137 
138  $this->assertEquals(
139  [
140  'SCORM_TITLE' => 'Formatted String',
141  'SCORM_POINTS' => '100,0 %',
142  'SCORM_POINTS_MAX' => 100,
143  'SCO_T_0' => 'Some Title',
144  'SCO_P_0' => '100,0',
145  'SCO_PM_0' => '300,0',
146  'SCO_PP_0' => '200,0 %',
147  'DATE_COMPLETED' => '',
148  'DATETIME_COMPLETED' => ''
149  ],
150  $result
151  );
152  }
153 
154  public function testGetPlaceholderValuesForPreview(): void
155  {
156  $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
157  ->disableOriginalConstructor()
158  ->getMock();
159 
160  $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
161  ->willReturn(
162  [
163  'SOME_PLACEHOLDER' => 'aaa',
164  'SOME_OTHER_PLACEHOLDER' => 'bbb'
165  ]
166  );
167 
168  $language = $this->getMockBuilder(ilLanguage::class)
169  ->disableOriginalConstructor()
170  ->getMock();
171 
172  $language->method('txt')
173  ->willReturnCallback(function ($variableValue) {
174  if ($variableValue === 'lang_sep_decimal') {
175  return ',';
176  } elseif ($variableValue === 'lang_sep_thousand') {
177  return '.';
178  }
179 
180  return 'Some Translation: ' . $variableValue;
181  });
182 
183  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
184  ->getMock();
185 
186  $objectMock = $this->getMockBuilder(ilObject::class)
187  ->disableOriginalConstructor()
188  ->getMock();
189 
190  $objectMock->method('getTitle')
191  ->willReturn('Some Title');
192 
193  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
194  ->getMock();
195 
196  $objectHelper->method('getInstanceByObjId')
197  ->willReturn($objectMock);
198 
199  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
200  ->getMock();
201 
202  $utilHelper->method('prepareFormOutput')
203  ->willReturnCallback(function ($input) {
204  return $input;
205  });
206 
207  $objectLPHelper = $this->getMockBuilder(ilCertificateObjectLPHelper::class)
208  ->getMock();
209 
210  $lpCollection = $this->getMockBuilder(ilLPCollectionOfSCOs::class)
211  ->disableOriginalConstructor()
212  ->onlyMethods(['getPossibleItems', 'isAssignedEntry'])
213  ->getMock();
214 
215  $lpCollection->method('getPossibleItems')
216  ->willReturn([
217  [
218  'title' => 'Some Title'
219  ],
220  [
221  'title' => 'Some Other Title'
222  ]
223  ]);
224 
225  $lpCollection->method('isAssignedEntry')
226  ->willReturn(true);
227 
228  $objectLPMock = $this->getMockBuilder(ilObjectLP::class)
229  ->disableOriginalConstructor()
230  ->getMock();
231 
232  $objectLPMock->method('getCollectionInstance')
233  ->willReturn($lpCollection);
234 
235  $objectLPHelper->method('getInstance')
236  ->willReturn($objectLPMock);
237 
238  $lpStatusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
239  ->getMock();
240 
241  $scormPlaceholderValues = new ilScormPlaceholderValues(
242  $defaultPlaceholderValues,
243  $language,
244  $dateHelper,
245  $objectHelper,
246  $utilHelper,
247  $objectLPHelper,
248  $lpStatusHelper
249  );
250 
251  $result = $scormPlaceholderValues->getPlaceholderValuesForPreview(100, 10);
252 
253  $this->assertEquals(
254  [
255  'SCORM_TITLE' => 'Some Title',
256  'SCORM_POINTS' => '80,7 %',
257  'SCORM_POINTS_MAX' => '90',
258  'SCO_T_0' => 'Some Title',
259  'SCO_P_0' => '30,3',
260  'SCO_PM_0' => '90,9',
261  'SCO_PP_0' => '33,3 %',
262  'SCO_T_1' => 'Some Other Title',
263  'SCO_P_1' => '30,3',
264  'SCO_PM_1' => '90,9',
265  'SCO_PP_1' => '33,3 %',
266  'SOME_PLACEHOLDER' => 'aaa',
267  'SOME_OTHER_PLACEHOLDER' => 'bbb'
268  ],
269  $result
270  );
271  }
272 }
Interface Observer Contains several chained tasks and infos about them.
Class ilCertificateBaseTestCase.
global $DIC
Definition: shib_login.php:22