ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCoursePlaceholderValuesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Course\Certificate;
22 
23 use ilObjUser;
24 use ilLanguage;
25 use ilObjCourse;
26 use ilDBInterface;
36 
40 class ilCoursePlaceholderValuesTest extends TestCase
41 {
42  protected ?Container $dic;
43 
44  protected function setUp(): void
45  {
46  if (!defined('ANONYMOUS_USER_ID')) {
47  define('ANONYMOUS_USER_ID', 13);
48  }
49 
50  global $DIC;
51  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
52  $DIC = new Container();
53  parent::setUp();
54  }
55 
56  protected function setGlobalVariable(string $name, $value): void
57  {
58  global $DIC;
59 
60  $GLOBALS[$name] = $value;
61 
62  unset($DIC[$name]);
63  $DIC[$name] = static function (Container $c) use ($name) {
64  return $GLOBALS[$name];
65  };
66  }
67 
68  public function testGetPlaceholderValues(): void
69  {
70  $customUserFieldsPlaceholderValues = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderValues::class)
71  ->disableOriginalConstructor()
72  ->getMock();
73 
74  $customUserFieldsPlaceholderValues->method('getPlaceholderValues')
75  ->willReturn([]);
76 
77  $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
78  ->disableOriginalConstructor()
79  ->getMock();
80 
81  $defaultPlaceholderValues->method('getPlaceholderValues')
82  ->willReturn([]);
83 
84  $language = $this->getMockBuilder(ilLanguage::class)
85  ->disableOriginalConstructor()
86  ->getMock();
87 
88  $language->method('txt')
89  ->willReturn('Something');
90 
91  $objectMock = $this->getMockBuilder(ilObjCourse::class)
92  ->disableOriginalConstructor()
93  ->getMock();
94 
95  $objectMock->method('getTitle')
96  ->willReturn('Some Title');
97 
98  $obj_translation = $this->getMockBuilder(ilObjectTranslation::class)
99  ->disableOriginalConstructor()
100  ->getMock();
101 
102  $german = $this->createMock(ilObjectTranslationLanguage::class);
103  $german->method('getLanguageCode')
104  ->willReturn('de');
105 
106  $english = $this->createMock(ilObjectTranslationLanguage::class);
107  $english->method('getLanguageCode')
108  ->willReturn('en');
109 
110  $obj_translation->method('getLanguages')
111  ->willReturn([
112  $german,
113  $english
114  ]);
115 
116  $objectMock->method('getObjectTranslation')
117  ->willReturn($obj_translation);
118 
119  $user_object = $this->getMockBuilder(ilObjUser::class)
120  ->disableOriginalConstructor()
121  ->getMock();
122 
123  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
124  ->getMock();
125  $objectHelper->method('getInstanceByObjId')
126  ->willReturnMap(
127  [
128  [200, $objectMock],
129  [100, $user_object]
130  ]
131  );
132 
133  $participantsHelper = $this->getMockBuilder(CertificateParticipantsHelper::class)
134  ->getMock();
135 
136  $participantsHelper->method('getDateTimeOfPassed')
137  ->willReturn('2018-09-10');
138 
139  $ilUtilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
140  ->disableOriginalConstructor()
141  ->getMock();
142 
143  $ilUtilHelper->method('prepareFormOutput')
144  ->willReturn('Some Title');
145 
146  $ilDateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
147  ->getMock();
148 
149  $ilDateHelper->method('formatDate')
150  ->willReturn('2018-09-10');
151 
152  $ilDateHelper->method('formatDateTime')
153  ->willReturn('2018-09-10 10:32:00');
154 
155  $database = $this->getMockBuilder(ilDBInterface::class)
156  ->getMock();
157 
158  $this->setGlobalVariable('ilDB', $database);
159  $this->setGlobalVariable('lng', $language);
160 
161  $valuesObject = new CoursePlaceholderValues(
162  $customUserFieldsPlaceholderValues,
163  $defaultPlaceholderValues,
164  $language,
165  $objectHelper,
166  $participantsHelper,
167  $ilDateHelper,
168  );
169 
170  $placeholderValues = $valuesObject->getPlaceholderValues(100, 200);
171 
172  $this->assertEquals(
173  [
174  'COURSE_TITLE' => 'Some Title',
175  'DATE_COMPLETED' => '2018-09-10',
176  'DATETIME_COMPLETED' => '2018-09-10 10:32:00'
177  ],
178  $placeholderValues
179  );
180  }
181 
182  public function testGetPreviewPlaceholderValues(): void
183  {
184  $customUserFieldsPlaceholderValues = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderValues::class)
185  ->disableOriginalConstructor()
186  ->getMock();
187 
188  $customUserFieldsPlaceholderValues->method('getPlaceholderValuesForPreview')
189  ->willReturn(
190  [
191  'SOME_PLACEHOLDER' => 'ANYTHING',
192  'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
193  ]
194  );
195 
196  $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
197  ->disableOriginalConstructor()
198  ->getMock();
199 
200  $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
201  ->willReturn(
202  [
203  'SOME_PLACEHOLDER' => 'ANYTHING',
204  'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
205  ]
206  );
207 
208  $language = $this->getMockBuilder(ilLanguage::class)
209  ->disableOriginalConstructor()
210  ->getMock();
211 
212  $language->method('txt')
213  ->willReturn('Something');
214 
215  $objectMock = $this->getMockBuilder(ilObjCourse::class)
216  ->disableOriginalConstructor()
217  ->getMock();
218 
219  $objectMock->method('getTitle')
220  ->willReturn('SomeTitle');
221 
222  $obj_translation = $this->getMockBuilder(ilObjectTranslation::class)
223  ->disableOriginalConstructor()
224  ->getMock();
225 
226  $german = $this->createMock(ilObjectTranslationLanguage::class);
227  $german->method('getLanguageCode')
228  ->willReturn('de');
229 
230  $english = $this->createMock(ilObjectTranslationLanguage::class);
231  $english->method('getLanguageCode')
232  ->willReturn('en');
233 
234  $obj_translation->method('getLanguages')
235  ->willReturn([
236  $german,
237  $english
238  ]);
239 
240  $objectMock->method('getObjectTranslation')
241  ->willReturn($obj_translation);
242 
243  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
244  ->getMock();
245 
246  $objectHelper->method('getInstanceByObjId')
247  ->willReturn($objectMock);
248 
249  $participantsHelper = $this->getMockBuilder(CertificateParticipantsHelper::class)
250  ->getMock();
251 
252  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
253  ->disableOriginalConstructor()
254  ->getMock();
255 
256  $utilHelper->method('prepareFormOutput')
257  ->willReturnCallback(function ($input) {
258  return $input;
259  });
260 
261  $database = $this->getMockBuilder(ilDBInterface::class)
262  ->getMock();
263 
264  $this->setGlobalVariable('ilDB', $database);
265  $this->setGlobalVariable('lng', $language);
266 
267  $valuesObject = new CoursePlaceholderValues(
268  $customUserFieldsPlaceholderValues,
269  $defaultPlaceholderValues,
270  $language,
271  $objectHelper,
272  $participantsHelper,
273  );
274 
275  $placeholderValues = $valuesObject->getPlaceholderValuesForPreview(100, 10);
276 
277  $this->assertSame(
278  [
279  'SOME_PLACEHOLDER' => 'ANYTHING',
280  'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
281  'COURSE_TITLE' => 'SomeTitle'
282  ],
283  $placeholderValues
284  );
285  }
286 }
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
$GLOBALS["DIC"]
Definition: wac.php:53
global $DIC
Definition: shib_login.php:22