19 declare(strict_types=1);
36 return new class ($orgUnitUserService, $envHelper, $usernameHelper, $languageHelper) extends
ilMailTemplateContext {
37 public function getId():
string 42 public function getTitle():
string 47 public function getDescription():
string 52 public function getSpecificPlaceholders(): array
57 public function resolveSpecificPlaceholder(
58 string $placeholder_id,
59 array $context_parameters,
61 bool $html_markup =
false 75 for (
$i = 1;
$i <= $amount;
$i++) {
76 $user = $this->getMockBuilder(ilOrgUnitUser::class)
77 ->disableOriginalConstructor()
78 ->onlyMethods([
'getUserId',])
80 $user->expects($this->atLeastOnce())->method(
'getUserId')->willReturn(
$i);
96 [
'gender' =>
'm',
'num_superiors' => 2,],
97 [
'gender' =>
'n',
'num_superiors' => 1,],
98 [
'gender' =>
'f',
'num_superiors' => 0,],
99 [
'gender' =>
'',
'num_superiors' => 3,],
101 $user = $this->getMockBuilder(ilObjUser::class)
102 ->disableOriginalConstructor()
114 $user->expects($this->atLeastOnce())->method(
'getLanguage')->willReturn(
'de');
115 $user->expects($this->atLeastOnce())->method(
'getUTitle')->willReturn(
'###Dr. Ing###');
116 $user->expects($this->atLeastOnce())->method(
'getLogin')->willReturn(
'###phpunit###');
117 $user->expects($this->atLeastOnce())->method(
'getLastname')->willReturn(
'###Unit###');
118 $user->expects($this->atLeastOnce())->method(
'getFirstname')->willReturn(
'###PHP###');
119 $user->expects($this->atLeastOnce())->method(
'getGender')->willReturn($definition[
'gender']);
120 $user->expects($this->atLeastOnce())->method(
'getId')->willReturn(4711);
122 $ouUser = $this->getMockBuilder(ilOrgUnitUser::class)
123 ->disableOriginalConstructor()
124 ->onlyMethods([
'getSuperiors',])
128 $ouUser->expects($this->atLeastOnce())->method(
'getSuperiors')->willReturn($superiors);
131 'User with gender "%s" and %s superiors',
132 $definition[
'gender'],
133 $definition[
'num_superiors']
134 )] = [$user, $ouUser, $superiors,];
150 $ouService = $this->getMockBuilder(OrgUnitUserService::class)
151 ->disableOriginalConstructor()
152 ->onlyMethods([
'getUsers',])
155 $lng = $this->getMockBuilder(ilLanguage::class)
156 ->disableOriginalConstructor()
157 ->onlyMethods([
'txt',
'loadLanguageModule',])
160 $envHelper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
161 ->disableOriginalConstructor()
162 ->onlyMethods([
'getClientId',
'getHttpPath',])
165 $lngHelper = $this->getMockBuilder(ilMailLanguageHelper::class)
166 ->disableOriginalConstructor()
167 ->onlyMethods([
'getLanguageByIsoCode',
'getCurrentLanguage',])
170 $userHelper = $this->getMockBuilder(ilMailUserHelper::class)
171 ->disableOriginalConstructor()
172 ->onlyMethods([
'getUsernameMapForIds',])
175 $ouService->expects($this->atLeastOnce())->method(
'getUsers')->willReturn([$ouUser,]);
176 $lng->expects($this->atLeastOnce())->method(
'txt')->will($this->returnArgument(0));
177 $envHelper->expects($this->atLeastOnce())->method(
'getClientId')->willReturn(
'###phpunit_client###');
178 $envHelper->expects($this->atLeastOnce())->method(
'getHttpPath')->willReturn(
'###http_ilias###');
179 $lngHelper->expects($this->atLeastOnce())->method(
'getLanguageByIsoCode')->willReturn(
$lng);
180 $lngHelper->expects($this->atLeastOnce())->method(
'getCurrentLanguage')->willReturn(
$lng);
182 if ($superiors === []) {
183 $expectedIdsConstraint = [];
185 $expectedIdsConstraint = self::logicalAnd(...array_map(
static function (
ilOrgUnitUser $user) {
186 return self::containsEqual($user->
getUserId());
190 $firstAndLastnames = array_map(
static function (
ilOrgUnitUser $user,
int $key):
string {
191 return "PhpSup$key UnitSup$key";
192 }, $superiors, array_keys($superiors));
194 $userHelper->expects($this->atLeastOnce())->method(
'getUsernameMapForIds')
195 ->with($expectedIdsConstraint)
196 ->willReturn($firstAndLastnames);
211 '[FIRSTNAME_LASTNAME_SUPERIOR]',
213 '[INSTALLATION_NAME]',
216 $replaceMessage = $placeholderResolver->resolve($user);
218 $this->assertStringContainsString(
'###Dr. Ing###', $replaceMessage);
219 $this->assertStringContainsString(
'###phpunit###', $replaceMessage);
220 $this->assertStringContainsString(
'###Unit###', $replaceMessage);
221 $this->assertStringContainsString(
'###PHP###', $replaceMessage);
222 $this->assertStringContainsString(
'###phpunit_client###', $replaceMessage);
223 $this->assertStringContainsString(
'###http_ilias###', $replaceMessage);
224 $this->assertStringContainsString(
'mail_salutation_' . $user->getGender(), $replaceMessage);
226 foreach ($firstAndLastnames as $firstAndLastname) {
227 $this->assertStringContainsString($firstAndLastname, $replaceMessage);
testGlobalPlaceholdersCanBeResolvedWithCorrespondingValues(ilObjUser $user, ilOrgUnitUser $ouUser, array $superiors)
userProvider
Class ilMailEnvironmentHelper.
Class ilMailLanguageHelper.
Class ilMailTemplateContext.
Class ilMailTemplatePlaceholderResolver.
generateOrgUnitUsers(int $amount)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMailTemplateContextTest.
getAnonymousTemplateContext(OrgUnitUserService $orgUnitUserService, ilMailEnvironmentHelper $envHelper, ilMailUserHelper $usernameHelper, ilMailLanguageHelper $languageHelper)