ILIAS  release_8 Revision v8.24
ilCoursePlaceholderValuesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public function testGetPlaceholderValues(): void
27 {
28 $customUserFieldsPlaceholderValues = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderValues::class)
29 ->disableOriginalConstructor()
30 ->getMock();
31
32 $customUserFieldsPlaceholderValues->method('getPlaceholderValues')
33 ->willReturn([]);
34
35 $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
36 ->disableOriginalConstructor()
37 ->getMock();
38
39 $defaultPlaceholderValues->method('getPlaceholderValues')
40 ->willReturn([]);
41
42 $language = $this->getMockBuilder(ilLanguage::class)
43 ->disableOriginalConstructor()
44 ->getMock();
45
46 $language->method('txt')
47 ->willReturn('Something');
48
49 $objectMock = $this->getMockBuilder(ilObject::class)
50 ->disableOriginalConstructor()
51 ->getMock();
52
53 $objectMock->method('getTitle')
54 ->willReturn('Some Title');
55
56 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
57 ->getMock();
58
59 $objectHelper->method('getInstanceByObjId')
60 ->willReturn($objectMock);
61
62 $participantsHelper = $this->getMockBuilder(ilCertificateParticipantsHelper::class)
63 ->getMock();
64
65 $participantsHelper->method('getDateTimeOfPassed')
66 ->willReturn('2018-09-10');
67
68 $ilUtilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
69 ->getMock();
70
71 $ilUtilHelper->method('prepareFormOutput')
72 ->willReturn('Some Title');
73
74 $ilDateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
75 ->getMock();
76
77 $ilDateHelper->method('formatDate')
78 ->willReturn('2018-09-10');
79
80 $ilDateHelper->method('formatDateTime')
81 ->willReturn('2018-09-10 10:32:00');
82
83 $valuesObject = new ilCoursePlaceholderValues(
84 $customUserFieldsPlaceholderValues,
85 $defaultPlaceholderValues,
86 $language,
87 $objectHelper,
88 $participantsHelper,
89 $ilUtilHelper,
90 $ilDateHelper
91 );
92
93 $placeholderValues = $valuesObject->getPlaceholderValues(100, 200);
94
95 $this->assertEquals(
96 [
97 'COURSE_TITLE' => 'Some Title',
98 'DATE_COMPLETED' => '2018-09-10',
99 'DATETIME_COMPLETED' => '2018-09-10 10:32:00'
100 ],
101 $placeholderValues
102 );
103 }
104
105 public function testGetPreviewPlaceholderValues(): void
106 {
107 $customUserFieldsPlaceholderValues = $this->getMockBuilder(ilObjectCustomUserFieldsPlaceholderValues::class)
108 ->disableOriginalConstructor()
109 ->getMock();
110
111 $customUserFieldsPlaceholderValues->method('getPlaceholderValuesForPreview')
112 ->willReturn(
113 [
114 'SOME_PLACEHOLDER' => 'ANYTHING',
115 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
116 ]
117 );
118
119 $defaultPlaceholderValues = $this->getMockBuilder(ilDefaultPlaceholderValues::class)
120 ->disableOriginalConstructor()
121 ->getMock();
122
123 $defaultPlaceholderValues->method('getPlaceholderValuesForPreview')
124 ->willReturn(
125 [
126 'SOME_PLACEHOLDER' => 'ANYTHING',
127 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
128 ]
129 );
130
131 $language = $this->getMockBuilder(ilLanguage::class)
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $language->method('txt')
136 ->willReturn('Something');
137
138 $objectMock = $this->getMockBuilder(ilObject::class)
139 ->disableOriginalConstructor()
140 ->getMock();
141
142 $objectMock->method('getTitle')
143 ->willReturn('SomeTitle');
144
145 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
146 ->getMock();
147
148 $objectHelper->method('getInstanceByObjId')
149 ->willReturn($objectMock);
150
151 $participantsHelper = $this->getMockBuilder(ilCertificateParticipantsHelper::class)
152 ->getMock();
153
154 $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
155 ->getMock();
156
157 $utilHelper->method('prepareFormOutput')
158 ->willReturnCallback(function ($input) {
159 return $input;
160 });
161
162 $valuesObject = new ilCoursePlaceholderValues(
163 $customUserFieldsPlaceholderValues,
164 $defaultPlaceholderValues,
165 $language,
166 $objectHelper,
167 $participantsHelper,
168 $utilHelper
169 );
170
171 $placeholderValues = $valuesObject->getPlaceholderValuesForPreview(100, 10);
172
173 $this->assertSame(
174 [
175 'SOME_PLACEHOLDER' => 'ANYTHING',
176 'SOME_OTHER_PLACEHOLDER' => '2018-09-10',
177 'COURSE_TITLE' => 'SomeTitle'
178 ],
179 $placeholderValues
180 );
181 }
182}
Class ilCertificateBaseTestCase.