ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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')
12  ->disableOriginalConstructor()
13  ->getMock();
14 
15  $language = $this->getMockBuilder('ilLanguage')
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')
34  ->getMock();
35 
36  $objectMock = $this->getMockBuilder('ilObject')
37  ->disableOriginalConstructor()
38  ->setMethods(array('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')
54  ->getMock();
55 
56  $objectHelper->method('getInstanceByObjId')
57  ->willReturn($objectMock);
58 
59  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
60  ->getMock();
61 
62  $utilHelper->method('prepareFormOutput')
63  ->willReturn('Formatted String');
64 
65  $objectLPHelper = $this->getMockBuilder('ilCertificateObjectLPHelper')
66  ->getMock();
67 
68  $lpCollection = $this->getMockBuilder('ilLPCollection')
69  ->disableOriginalConstructor()
70  ->setMethods(array('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')
89  ->disableOriginalConstructor()
90  ->setMethods(array('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')
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')
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')
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')
163  ->getMock();
164 
165  $objectMock = $this->getMockBuilder('ilObject')
166  ->disableOriginalConstructor()
167  ->getMock();
168 
169  $objectMock->method('getTitle')
170  ->willReturn('Some Title');
171 
172  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
173  ->getMock();
174 
175  $objectHelper->method('getInstanceByObjId')
176  ->willReturn($objectMock);
177 
178  $utilHelper = $this->getMockBuilder('ilCertificateUtilHelper')
179  ->getMock();
180 
181  $utilHelper->method('prepareFormOutput')
182  ->willReturnCallback(function ($input) {
183  return $input;
184  });
185 
186  $objectLPHelper = $this->getMockBuilder('ilCertificateObjectLPHelper')
187  ->getMock();
188 
189  $lpCollection = $this->getMockBuilder('ilLPCollection')
190  ->disableOriginalConstructor()
191  ->setMethods(array('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')
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')
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
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.