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,
74 for ($i = 1; $i <= $amount; $i++) {
75 $user = $this->getMockBuilder(ilOrgUnitUser::class)
76 ->disableOriginalConstructor()
77 ->onlyMethods([
'getUserId',])
79 $user->expects($this->atLeastOnce())->method(
'getUserId')->willReturn($i);
95 [
'gender' =>
'm',
'num_superiors' => 2,],
96 [
'gender' =>
'n',
'num_superiors' => 1,],
97 [
'gender' =>
'f',
'num_superiors' => 0,],
98 [
'gender' =>
'',
'num_superiors' => 3,],
100 $user = $this->getMockBuilder(ilObjUser::class)
101 ->disableOriginalConstructor()
113 $user->expects($this->atLeastOnce())->method(
'getLanguage')->willReturn(
'de');
114 $user->expects($this->atLeastOnce())->method(
'getUTitle')->willReturn(
'###Dr. Ing###');
115 $user->expects($this->atLeastOnce())->method(
'getLogin')->willReturn(
'###phpunit###');
116 $user->expects($this->atLeastOnce())->method(
'getLastname')->willReturn(
'###Unit###');
117 $user->expects($this->atLeastOnce())->method(
'getFirstname')->willReturn(
'###PHP###');
118 $user->expects($this->atLeastOnce())->method(
'getGender')->willReturn($definition[
'gender']);
119 $user->expects($this->atLeastOnce())->method(
'getId')->willReturn(4711);
121 $ouUser = $this->getMockBuilder(ilOrgUnitUser::class)
122 ->disableOriginalConstructor()
123 ->onlyMethods([
'getSuperiors',])
127 $ouUser->expects($this->atLeastOnce())->method(
'getSuperiors')->willReturn($superiors);
130 'User with gender "%s" and %s superiors',
131 $definition[
'gender'],
132 $definition[
'num_superiors']
133 )] = [$user, $ouUser, $superiors,];
149 $ouService = $this->getMockBuilder(OrgUnitUserService::class)
150 ->disableOriginalConstructor()
151 ->onlyMethods([
'getUsers',])
154 $lng = $this->getMockBuilder(ilLanguage::class)
155 ->disableOriginalConstructor()
156 ->onlyMethods([
'txt',
'loadLanguageModule',])
159 $envHelper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
160 ->disableOriginalConstructor()
161 ->onlyMethods([
'getClientId',
'getHttpPath',])
164 $lngHelper = $this->getMockBuilder(ilMailLanguageHelper::class)
165 ->disableOriginalConstructor()
166 ->onlyMethods([
'getLanguageByIsoCode',
'getCurrentLanguage',])
169 $userHelper = $this->getMockBuilder(ilMailUserHelper::class)
170 ->disableOriginalConstructor()
171 ->onlyMethods([
'getUsernameMapForIds',])
174 $ouService->expects($this->atLeastOnce())->method(
'getUsers')->willReturn([$ouUser,]);
175 $lng->expects($this->atLeastOnce())->method(
'txt')->will($this->returnArgument(0));
176 $envHelper->expects($this->atLeastOnce())->method(
'getClientId')->willReturn(
'###phpunit_client###');
177 $envHelper->expects($this->atLeastOnce())->method(
'getHttpPath')->willReturn(
'###http_ilias###');
178 $lngHelper->expects($this->atLeastOnce())->method(
'getLanguageByIsoCode')->willReturn(
$lng);
179 $lngHelper->expects($this->atLeastOnce())->method(
'getCurrentLanguage')->willReturn(
$lng);
181 if ($superiors === []) {
182 $expectedIdsConstraint = [];
184 $expectedIdsConstraint = self::logicalAnd(...array_map(
static function (
ilOrgUnitUser $user): \PHPUnit\Framework\Constraint\TraversableContainsEqual {
185 return self::containsEqual($user->
getUserId());
189 $firstAndLastnames = array_map(
static function (
ilOrgUnitUser $user,
int $key):
string {
190 return "PhpSup$key UnitSup$key";
191 }, $superiors, array_keys($superiors));
193 $userHelper->expects($this->atLeastOnce())->method(
'getUsernameMapForIds')
194 ->with($expectedIdsConstraint)
195 ->willReturn($firstAndLastnames);
204 $mustache =
new Mustache_Engine();
208 '{{MAIL_SALUTATION}}',
213 '{{FIRSTNAME_LASTNAME_SUPERIOR}}',
215 '{{INSTALLATION_NAME}}',
219 $this->assertStringContainsString(
'###Dr. Ing###', $replaceMessage);
220 $this->assertStringContainsString(
'###phpunit###', $replaceMessage);
221 $this->assertStringContainsString(
'###Unit###', $replaceMessage);
222 $this->assertStringContainsString(
'###PHP###', $replaceMessage);
223 $this->assertStringContainsString(
'###phpunit_client###', $replaceMessage);
224 $this->assertStringContainsString(
'###http_ilias###', $replaceMessage);
225 $this->assertStringContainsString(
'mail_salutation_' . $user->getGender(), $replaceMessage);
227 foreach ($firstAndLastnames as $firstAndLastname) {
228 $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)