145 : void {
146 $ouService = $this->getMockBuilder(OrgUnitUserService::class)
147 ->disableOriginalConstructor()
148 ->onlyMethods(['getUsers',])
149 ->getMock();
150
151 $lng = $this->getMockBuilder(ilLanguage::class)
152 ->disableOriginalConstructor()
153 ->onlyMethods(['txt', 'loadLanguageModule',])
154 ->getMock();
155
156 $envHelper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
157 ->disableOriginalConstructor()
158 ->onlyMethods(['getClientId', 'getHttpPath',])
159 ->getMock();
160
161 $lngHelper = $this->getMockBuilder(ilMailLanguageHelper::class)
162 ->disableOriginalConstructor()
163 ->onlyMethods(['getLanguageByIsoCode', 'getCurrentLanguage',])
164 ->getMock();
165
166 $userHelper = $this->getMockBuilder(ilMailUserHelper::class)
167 ->disableOriginalConstructor()
168 ->onlyMethods(['getUsernameMapForIds',])
169 ->getMock();
170
171 $ouService->expects($this->atLeastOnce())->method('getUsers')->willReturn([$ouUser,]);
172 $lng->expects($this->atLeastOnce())->method(
'txt')->will($this->returnArgument(0));
173 $envHelper->expects($this->atLeastOnce())->method('getClientId')->willReturn('###phpunit_client###');
174 $envHelper->expects($this->atLeastOnce())->method('getHttpPath')->willReturn('###http_ilias###');
175 $lngHelper->expects($this->atLeastOnce())->method(
'getLanguageByIsoCode')->willReturn(
$lng);
176 $lngHelper->expects($this->atLeastOnce())->method(
'getCurrentLanguage')->willReturn(
$lng);
177
178 $expectedIdsConstraint = self::logicalAnd(...array_map(
function (
ilOrgUnitUser $user) {
179 if (version_compare(\PHPUnit\Runner\
Version::id(),
'9.0',
'>=')) {
180 return self::containsEqual($user->
getUserId());
181 } else {
182 return self::contains($user->
getUserId());
183 }
184 }, $superiors));
185
186 $firstAndLastnames = array_map(
function (
ilOrgUnitUser $user,
int $key) {
187 return "PhpSup{$key} UnitSup{$key}";
188 }, $superiors, array_keys($superiors));
189
190 $userHelper->expects($this->atLeastOnce())->method('getUsernameMapForIds')
191 ->with($expectedIdsConstraint)
192 ->willReturn($firstAndLastnames);
193
195 $ouService,
196 $envHelper,
197 $userHelper,
198 $lngHelper
199 );
200
202 '[MAIL_SALUTATION]',
203 '[FIRST_NAME]',
204 '[LAST_NAME]',
205 '[LOGIN]',
206 '[TITLE]',
207 '[FIRSTNAME_LASTNAME_SUPERIOR]',
208 '[ILIAS_URL]',
209 '[CLIENT_NAME]',
210 ]));
211
212 $replaceMessage = $placeholderResolver->resolve($user);
213
214 $this->assertStringContainsString('###Dr. Ing###', $replaceMessage);
215 $this->assertStringContainsString('###phpunit###', $replaceMessage);
216 $this->assertStringContainsString('###Unit###', $replaceMessage);
217 $this->assertStringContainsString('###PHP###', $replaceMessage);
218 $this->assertStringContainsString('###phpunit_client###', $replaceMessage);
219 $this->assertStringContainsString('###http_ilias###', $replaceMessage);
220 $this->assertStringContainsString('mail_salutation_' . $user->getGender(), $replaceMessage);
221
222 foreach ($firstAndLastnames as $firstAndLastname) {
223 $this->assertStringContainsString($firstAndLastname, $replaceMessage);
224 }
225 }
getAnonymousTemplateContext(OrgUnitUserService $orgUnitUserService, ilMailEnvironmentHelper $envHelper, ilMailUserHelper $usernameHelper, ilMailLanguageHelper $languageHelper)
Class ilMailTemplatePlaceholderResolver.