19 declare(strict_types=1);
35 return new class ($org_unit_user_service, $il_mail_environment_helper, $mail_user_helper, $language_helper) extends
37 public function getId():
string 47 public function getDescription():
string 52 public function getSpecificPlaceholders(): array
57 public function resolveSpecificPlaceholder(
58 string $placeholder_id,
59 array $context_parameters,
75 for ($i = 1; $i <= $amount; $i++) {
76 $user = $mock_builder()
77 ->disableOriginalConstructor()
78 ->onlyMethods([
'getUserId',])
80 $user->expects($this->atLeastOnce())->method(
'getUserId')->willReturn($i);
97 [
'gender' =>
'm',
'num_superiors' => 2,],
98 [
'gender' =>
'n',
'num_superiors' => 1,],
99 [
'gender' =>
'f',
'num_superiors' => 0,],
100 [
'gender' =>
'',
'num_superiors' => 3,],
106 $user_callable =
function (
Closure $mock_builder) use ($definition):
ilObjUser&MockObject {
107 $user = $mock_builder()
108 ->disableOriginalConstructor()
120 $user->expects($this->atLeastOnce())->method(
'getLanguage')->willReturn(
'de');
121 $user->expects($this->atLeastOnce())->method(
'getUTitle')->willReturn(
'###Dr. Ing###');
122 $user->expects($this->atLeastOnce())->method(
'getLogin')->willReturn(
'###phpunit###');
123 $user->expects($this->atLeastOnce())->method(
'getLastname')->willReturn(
'###Unit###');
124 $user->expects($this->atLeastOnce())->method(
'getFirstname')->willReturn(
'###PHP###');
125 $user->expects($this->atLeastOnce())->method(
'getGender')->willReturn($definition[
'gender']);
126 $user->expects($this->atLeastOnce())->method(
'getId')->willReturn(4711);
135 $ou_user_callable =
function (
Closure $mock_builder) use ($definition): array {
136 $ou_user = $mock_builder()
137 ->disableOriginalConstructor()
138 ->onlyMethods([
'getSuperiors',])
142 $ou_user->expects($this->atLeastOnce())->method(
'getSuperiors')->willReturn($superiors);
144 return [$ou_user, $superiors];
148 'User with gender "%s" and %s superiors',
149 $definition[
'gender'],
150 $definition[
'num_superiors']
151 )] = [$user_callable, $ou_user_callable];
161 #[DataProvider('userProvider')] 163 callable $user_callable,
164 callable $ou_user_callable
166 $mock_builder_user_callable = fn(): MockBuilder => $this->getMockBuilder(ilObjUser::class);
167 $mock_builder_ou_user_callable = fn(): MockBuilder => $this->getMockBuilder(ilOrgUnitUser::class);
169 $user_callable = Closure::bind($user_callable, $this, self::class);
170 $ou_user_callable = Closure::bind($ou_user_callable, $this, self::class);
172 $user = $user_callable($mock_builder_user_callable);
173 [$ou_user, $ou_superiors] = $ou_user_callable($mock_builder_ou_user_callable);
175 $ou_service = $this->getMockBuilder(OrgUnitUserService::class)
176 ->disableOriginalConstructor()
177 ->onlyMethods([
'getUsers',])
180 $lng = $this->getMockBuilder(ilLanguage::class)
181 ->disableOriginalConstructor()
182 ->onlyMethods([
'txt',
'loadLanguageModule',])
185 $env_helper = $this->getMockBuilder(ilMailEnvironmentHelper::class)
186 ->disableOriginalConstructor()
187 ->onlyMethods([
'getClientId',
'getHttpPath',])
190 $lng_helper = $this->getMockBuilder(ilMailLanguageHelper::class)
191 ->disableOriginalConstructor()
192 ->onlyMethods([
'getLanguageByIsoCode',
'getCurrentLanguage',])
195 $user_helper = $this->getMockBuilder(ilMailUserHelper::class)
196 ->disableOriginalConstructor()
197 ->onlyMethods([
'getUsernameMapForIds',])
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);
207 $expected_ids_constraint = [];
208 if ($ou_superiors !== []) {
209 $expected_ids_constraint = self::logicalAnd(
212 return self::containsEqual($user->
getUserId());
220 return "PhpSup$key UnitSup$key";
221 }, $ou_superiors, array_keys($ou_superiors));
223 $user_helper->expects($this->atLeastOnce())->method(
'getUsernameMapForIds')
224 ->with($expected_ids_constraint)
225 ->willReturn($first_and_last_names);
234 $mustache =
new Mustache_Engine();
238 '{{MAIL_SALUTATION}}',
243 '{{FIRSTNAME_LASTNAME_SUPERIOR}}',
245 '{{INSTALLATION_NAME}}',
247 $replace_message = $placeholder_resolver->resolve(
$context,
$message, $user);
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);
257 foreach ($first_and_last_names as $first_and_lastname) {
258 $this->assertStringContainsString($first_and_lastname, $replace_message);
generateOrgUnitUsers(Closure $mock_builder, int $amount)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getAnonymousTemplateContext(OrgUnitUserService $org_unit_user_service, ilMailEnvironmentHelper $il_mail_environment_helper, ilMailUserHelper $mail_user_helper, ilMailLanguageHelper $language_helper)
testGlobalPlaceholdersCanBeResolvedWithCorrespondingValues(callable $user_callable, callable $ou_user_callable)