165 : void {
166 $mock_builder_user_callable = fn(): MockBuilder => $this->getMockBuilder(
ilObjUser::class);
167 $mock_builder_ou_user_callable = fn(): MockBuilder => $this->getMockBuilder(
ilOrgUnitUser::class);
168
169 $user_callable = Closure::bind($user_callable, $this, self::class);
170 $ou_user_callable = Closure::bind($ou_user_callable, $this, self::class);
171
172 $user = $user_callable($mock_builder_user_callable);
173 [$ou_user, $ou_superiors] = $ou_user_callable($mock_builder_ou_user_callable);
174
175 $ou_service = $this->getMockBuilder(OrgUnitUserService::class)
176 ->disableOriginalConstructor()
177 ->onlyMethods(['getUsers',])
178 ->getMock();
179
180 $lng = $this->getMockBuilder(ilLanguage::class)
181 ->disableOriginalConstructor()
182 ->onlyMethods(['txt', 'loadLanguageModule',])
183 ->getMock();
184
185 $env_helper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
186 ->disableOriginalConstructor()
187 ->onlyMethods(['getClientId', 'getHttpPath',])
188 ->getMock();
189
190 $lng_helper = $this->getMockBuilder(ilMailLanguageHelper::class)
191 ->disableOriginalConstructor()
192 ->onlyMethods(['getLanguageByIsoCode', 'getCurrentLanguage',])
193 ->getMock();
194
195 $user_helper = $this->getMockBuilder(ilMailUserHelper::class)
196 ->disableOriginalConstructor()
197 ->onlyMethods(['getUsernameMapForIds',])
198 ->getMock();
199
200 $ou_service->expects($this->atLeastOnce())->method('getUsers')->willReturn([$ou_user,]);
201 $lng->expects($this->atLeastOnce())->method(
'txt')->willReturnArgument(0);
202 $env_helper->expects($this->atLeastOnce())->method('getClientId')->willReturn('###phpunit_client###');
203 $env_helper->expects($this->atLeastOnce())->method('getHttpPath')->willReturn('###http_ilias###');
204 $lng_helper->expects($this->atLeastOnce())->method(
'getLanguageByIsoCode')->willReturn(
$lng);
205 $lng_helper->expects($this->atLeastOnce())->method(
'getCurrentLanguage')->willReturn(
$lng);
206
207 $expected_ids_constraint = [];
208 if ($ou_superiors !== []) {
209 $expected_ids_constraint = self::logicalAnd(
210 ...array_map(
211 static function (
ilOrgUnitUser $user): \PHPUnit\Framework\Constraint\TraversableContainsEqual {
212 return self::containsEqual($user->
getUserId());
213 },
214 $ou_superiors
215 )
216 );
217 }
218
219 $first_and_last_names = array_map(
static function (
ilOrgUnitUser $user,
int $key):
string {
220 return "PhpSup$key UnitSup$key";
221 }, $ou_superiors, array_keys($ou_superiors));
222
223 $user_helper->expects($this->atLeastOnce())->method('getUsernameMapForIds')
224 ->with($expected_ids_constraint)
225 ->willReturn($first_and_last_names);
226
228 $ou_service,
229 $env_helper,
230 $user_helper,
231 $lng_helper
232 );
233
234 $mustache = new Mustache_Engine();
236
238 '{{MAIL_SALUTATION}}',
239 '{{FIRST_NAME}}',
240 '{{LAST_NAME}}',
241 '{{LOGIN}}',
242 '{{TITLE}}',
243 '{{FIRSTNAME_LASTNAME_SUPERIOR}}',
244 '{{ILIAS_URL}}',
245 '{{INSTALLATION_NAME}}',
246 ]);
247 $replace_message = $placeholder_resolver->resolve(
$context,
$message, $user);
248
249 $this->assertStringContainsString('###Dr. Ing###', $replace_message);
250 $this->assertStringContainsString('###phpunit###', $replace_message);
251 $this->assertStringContainsString('###Unit###', $replace_message);
252 $this->assertStringContainsString('###PHP###', $replace_message);
253 $this->assertStringContainsString('###phpunit_client###', $replace_message);
254 $this->assertStringContainsString('###http_ilias###', $replace_message);
255 $this->assertStringContainsString('mail_salutation_' . $user->getGender(), $replace_message);
256
257 foreach ($first_and_last_names as $first_and_lastname) {
258 $this->assertStringContainsString($first_and_lastname, $replace_message);
259 }
260 }
getAnonymousTemplateContext(OrgUnitUserService $org_unit_user_service, ilMailEnvironmentHelper $il_mail_environment_helper, ilMailUserHelper $mail_user_helper, ilMailLanguageHelper $language_helper)