1 <?php declare(strict_types=1);
27 return new class($orgUnitUserService, $envHelper, $usernameHelper, $languageHelper) extends
ilMailTemplateContext {
28 public function getId() :
string 33 public function getTitle() :
string 38 public function getDescription() :
string 43 public function getSpecificPlaceholders() : array
48 public function resolveSpecificPlaceholder(
49 string $placeholder_id,
50 array $context_parameters,
52 bool $html_markup =
false 68 for (
$i = 1;
$i <= $amount;
$i++) {
69 $user = $this->getMockBuilder(ilOrgUnitUser::class)
70 ->disableOriginalConstructor()
71 ->setMethods([
'getUserId',])
73 $user->expects($this->atLeastOnce())->method(
'getUserId')->willReturn(
$i);
90 [
'gender' =>
'm',
'num_superiors' => 2,],
91 [
'gender' =>
'n',
'num_superiors' => 1,],
92 [
'gender' =>
'f',
'num_superiors' => 0,],
93 [
'gender' =>
'',
'num_superiors' => 3,]
95 $user = $this->getMockBuilder(ilObjUser::class)
96 ->disableOriginalConstructor()
108 $user->expects($this->atLeastOnce())->method(
'getLanguage')->willReturn(
'de');
109 $user->expects($this->atLeastOnce())->method(
'getUTitle')->willReturn(
'###Dr. Ing###');
110 $user->expects($this->atLeastOnce())->method(
'getLogin')->willReturn(
'###phpunit###');
111 $user->expects($this->atLeastOnce())->method(
'getLastname')->willReturn(
'###Unit###');
112 $user->expects($this->atLeastOnce())->method(
'getFirstname')->willReturn(
'###PHP###');
113 $user->expects($this->atLeastOnce())->method(
'getGender')->willReturn($definition[
'gender']);
114 $user->expects($this->atLeastOnce())->method(
'getId')->willReturn(4711);
116 $ouUser = $this->getMockBuilder(ilOrgUnitUser::class)
117 ->disableOriginalConstructor()
118 ->setMethods([
'getSuperiors',])
122 $ouUser->expects($this->atLeastOnce())->method(
'getSuperiors')->willReturn($superiors);
125 'User with gender "%s" and %s superiors',
126 $definition[
'gender'],
127 $definition[
'num_superiors']
128 )] = [$user, $ouUser, $superiors,];
146 $ouService = $this->getMockBuilder(OrgUnitUserService::class)
147 ->disableOriginalConstructor()
148 ->setMethods([
'getUsers',])
151 $lng = $this->getMockBuilder(ilLanguage::class)
152 ->disableOriginalConstructor()
153 ->setMethods([
'txt',
'loadLanguageModule',])
156 $envHelper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
157 ->disableOriginalConstructor()
158 ->setMethods([
'getClientId',
'getHttpPath',])
161 $lngHelper = $this->getMockBuilder(ilMailLanguageHelper::class)
162 ->disableOriginalConstructor()
163 ->setMethods([
'getLanguageByIsoCode',
'getCurrentLanguage',])
166 $userHelper = $this->getMockBuilder(ilMailUserHelper::class)
167 ->disableOriginalConstructor()
168 ->setMethods([
'getUsernameMapForIds',])
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);
178 $expectedIdsConstraint = $this->logicalAnd(...array_map(
function (
ilOrgUnitUser $user) {
179 return $this->contains($user->
getUserId());
182 $firstAndLastnames = array_map(
function (
ilOrgUnitUser $user,
int $key) {
183 return "PhpSup{$key} UnitSup{$key}";
184 }, $superiors, array_keys($superiors));
186 $userHelper->expects($this->atLeastOnce())->method(
'getUsernameMapForIds')
187 ->with($expectedIdsConstraint)
188 ->willReturn($firstAndLastnames);
203 '[FIRSTNAME_LASTNAME_SUPERIOR]',
208 $replaceMessage = $placeholderResolver->resolve($user);
210 $this->assertStringContainsString(
'###Dr. Ing###', $replaceMessage);
211 $this->assertStringContainsString(
'###phpunit###', $replaceMessage);
212 $this->assertStringContainsString(
'###Unit###', $replaceMessage);
213 $this->assertStringContainsString(
'###PHP###', $replaceMessage);
214 $this->assertStringContainsString(
'###phpunit_client###', $replaceMessage);
215 $this->assertStringContainsString(
'###http_ilias###', $replaceMessage);
216 $this->assertStringContainsString(
'mail_salutation_' . $user->getGender(), $replaceMessage);
218 foreach ($firstAndLastnames as $firstAndLastname) {
219 $this->assertStringContainsString($firstAndLastname, $replaceMessage);
testGlobalPlaceholdersCanBeResolvedWithCorrespondingValues(ilObjUser $user, ilOrgUnitUser $ouUser, array $superiors)
userProvider
Class ilMailEnvironmentHelper.
Class ilMailLanguageHelper.
Class ilMailTemplateContext.
Class ilMailTemplatePlaceholderResolver.
generateOrgUnitUsers(int $amount)
Class ilMailTemplateContextTest.
getAnonymousTemplateContext(OrgUnitUserService $orgUnitUserService, ilMailEnvironmentHelper $envHelper, ilMailUserHelper $usernameHelper, ilMailLanguageHelper $languageHelper)