19 declare(strict_types=1);
29 protected function setUp(): void
40 return $this->getMockBuilder(ilGroupNameAsMailValidator::class)
41 ->disableOriginalConstructor()
42 ->onlyMethods([
'validate'])
48 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
49 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
50 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->getMock();
51 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
52 $mailingLists = $this->getMockBuilder(ilMailingLists::class)->disableOriginalConstructor()->getMock();
53 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->getMock();
56 $groupNameValidatorMock,
69 $refl =
new ReflectionObject($type);
70 $inner = $refl->getProperty(
'inner');
71 $inner->setAccessible(
true);
73 return $inner->getValue($type);
82 $groupNameValidatorMock->method(
'validate')->willReturn(
true);
86 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#il_ml_4711',
''),
false);
94 $groupNameValidatorMock->method(
'validate')->willReturn(
true);
98 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#MyGroup',
''),
false);
106 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
110 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'phpunit',
''),
false);
112 $this->assertInstanceOf(
'ilMailLoginOrEmailAddressAddressType', $this->
getWrappedAddressType($result));
118 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
122 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#member',
''),
false);
130 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
134 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#il_grp_admin_98',
''),
false);
142 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
146 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#il_grp_member_98',
''),
false);
154 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
158 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#il_crs_admin_98',
''),
false);
166 $groupNameValidatorMock->method(
'validate')->willReturn(
false);
170 $result = $mailAddressTypeFactory->getByPrefix(
new ilMailAddress(
'#il_crs_member_98',
''),
false);
177 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
178 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
179 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
181 $addressTypeHelper->expects($this->once())->method(
'getInstallationHost')->willReturn(
'ilias');
182 $addressTypeHelper->expects($this->once())->method(
'getUserIdByLogin')->willReturn(4711);
191 $usrIds = $type->resolve();
193 $this->assertCount(1, $usrIds);
194 $this->assertArrayHasKey(0, $usrIds);
195 $this->assertSame(4711, $usrIds[0]);
200 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
201 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
202 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
204 $addressTypeHelper->expects($this->once())->method(
'getInstallationHost')->willReturn(
'ilias');
205 $addressTypeHelper->expects($this->once())->method(
'getUserIdByLogin')->willReturn(0);
214 $usrIds = $type->resolve();
216 $this->assertCount(0, $usrIds);
221 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
222 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
223 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
225 $addressTypeHelper->expects($this->once())->method(
'getInstallationHost')->willReturn(
'ilias');
226 $addressTypeHelper->expects($this->once())->method(
'getUserIdByLogin')->willReturn(0);
235 $usrIds = $type->resolve();
237 $this->assertCount(0, $usrIds);
242 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
243 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
245 $addressTypeHelper->expects($this->atLeast(3))->method(
'getInstallationHost')->willReturn(
'ilias');
246 $addressTypeHelper->expects($this->exactly(2))->method(
'getUserIdByLogin')->willReturnOnConsecutiveCalls(
252 $addressTypeHelper->method(
'receivesInternalMailsOnly')->willReturn(
true);
254 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
255 $rbacsystem->expects($this->exactly(2))->method(
'checkAccessOfUser')->willReturnOnConsecutiveCalls(
266 $this->assertTrue($type->validate(666));
267 $this->assertCount(0, $type->getErrors());
269 $this->assertFalse($type->validate(666));
270 $this->assertArrayHasKey(0, $type->getErrors());
271 $this->assertSame(
'user_cant_receive_mail', $type->getErrors()[0]->getLanguageVariable());
279 $this->assertTrue($type->validate(666));
280 $this->assertCount(0, $type->getErrors());
285 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
286 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
288 $group = $this->getMockBuilder(ilObjGroup::class)->disableOriginalConstructor()->onlyMethods([
'getGroupMemberIds'])->getMock();
289 $group->expects($this->once())->method(
'getGroupMemberIds')->willReturn([666, 777]);
291 $addressTypeHelper->expects($this->once())->method(
'getGroupObjIdByTitle')->willReturn(1);
292 $addressTypeHelper->expects($this->once())->method(
'getAllRefIdsForObjId')->with(1)->willReturn([2]);
293 $addressTypeHelper->expects($this->once())->method(
'getInstanceByRefId')->with(2)->willReturn($group);
301 $usrIds = $type->resolve();
303 $this->assertCount(2, $usrIds);
308 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
309 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
311 $group = $this->getMockBuilder(ilObjGroup::class)->disableOriginalConstructor()->onlyMethods([
'getGroupMemberIds'])->getMock();
312 $group->expects($this->never())->method(
'getGroupMemberIds');
314 $addressTypeHelper->expects($this->once())->method(
'getGroupObjIdByTitle')->willReturn(0);
315 $addressTypeHelper->expects($this->once())->method(
'getAllRefIdsForObjId')->with(0)->willReturn([]);
316 $addressTypeHelper->expects($this->never())->method(
'getInstanceByRefId');
324 $usrIds = $type->resolve();
326 $this->assertCount(0, $usrIds);
331 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
332 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
334 $addressTypeHelper->expects($this->once())->method(
'doesGroupNameExists')->with(
'PhpUnit')->willReturn(
false);
341 $this->assertFalse($type->validate(666));
346 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
347 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
349 $addressTypeHelper->expects($this->once())->method(
'doesGroupNameExists')->with(
'PhpUnit')->willReturn(
true);
356 $this->assertTrue($type->validate(666));
361 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
362 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
364 $list = $this->getMockBuilder(ilMailingList::class)->disableOriginalConstructor()->onlyMethods([
365 'getAssignedEntries',
367 $list->expects($this->exactly(2))->method(
'getAssignedEntries')->willReturnOnConsecutiveCalls(
368 [[
'usr_id' => 1], [
'usr_id' => 2], [
'usr_id' => 3]],
372 $lists = $this->getMockBuilder(ilMailingLists::class)->disableOriginalConstructor()->onlyMethods([
374 'getCurrentMailingList',
376 $lists->expects($this->exactly(3))->method(
'mailingListExists')->with(
'#il_ml_4711')->willReturnOnConsecutiveCalls(
381 $lists->expects($this->exactly(2))->method(
'getCurrentMailingList')->willReturn($list);
390 $usrIds = $type->resolve();
392 $this->assertCount(3, $usrIds);
394 $usrIds = $type->resolve();
396 $this->assertCount(0, $usrIds);
398 $usrIds = $type->resolve();
400 $this->assertCount(0, $usrIds);
405 $lists = $this->getMockBuilder(ilMailingLists::class)->disableOriginalConstructor()->onlyMethods([
408 $lists->expects($this->exactly(2))->method(
'mailingListExists')->with(
'#il_ml_4711')->willReturnOnConsecutiveCalls(
412 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
413 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
422 $this->assertTrue($type->validate(666));
423 $this->assertCount(0, $type->getErrors());
425 $this->assertFalse($type->validate(666));
426 $this->assertCount(1, $type->getErrors());
427 $this->assertArrayHasKey(0, $type->getErrors());
428 $this->assertSame(
'mail_no_valid_mailing_list', $type->getErrors()[0]->getLanguageVariable());
433 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
434 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
435 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->onlyMethods([
'assignedUsers'])->getMock();
436 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
437 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->onlyMethods([
'searchRoleIdsByAddressString'])->getMock();
439 $roleMailboxSearch->expects($this->once())->method(
'searchRoleIdsByAddressString')->willReturn([1, 2, 3]);
440 $rbacreview->expects($this->exactly(3))->method(
'assignedUsers')->willReturnOnConsecutiveCalls(
455 $usrIds = $type->resolve();
457 $this->assertCount(6, $usrIds);
462 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
463 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
464 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->onlyMethods([
'assignedUsers'])->getMock();
465 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
466 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->onlyMethods([
'searchRoleIdsByAddressString'])->getMock();
468 $roleMailboxSearch->expects($this->once())->method(
'searchRoleIdsByAddressString')->willReturn([]);
469 $rbacreview->expects($this->never())->method(
'assignedUsers');
480 $usrIds = $type->resolve();
482 $this->assertCount(0, $usrIds);
487 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
488 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
489 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->onlyMethods([
'assignedUsers'])->getMock();
490 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
491 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->onlyMethods([
'searchRoleIdsByAddressString'])->getMock();
493 $roleMailboxSearch->expects($this->once())->method(
'searchRoleIdsByAddressString')->willReturn([1]);
494 $rbacreview->expects($this->once())->method(
'assignedUsers')->willReturn([]);
505 $usrIds = $type->resolve();
507 $this->assertCount(0, $usrIds);
512 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
513 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
514 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->getMock();
515 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
516 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->onlyMethods([
'searchRoleIdsByAddressString'])->getMock();
518 $roleMailboxSearch->expects($this->once())->method(
'searchRoleIdsByAddressString')->willReturnOnConsecutiveCalls([1]);
519 $rbacsystem->expects($this->never())->method(
'checkAccessOfUser');
531 $this->assertCount(0, $type->getErrors());
536 $logger = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
537 $rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->onlyMethods([
'checkAccessOfUser'])->getMock();
538 $rbacreview = $this->getMockBuilder(ilRbacReview::class)->disableOriginalConstructor()->onlyMethods([
'isGlobalRole'])->getMock();
539 $addressTypeHelper = $this->getMockBuilder(ilMailAddressTypeHelper::class)->getMock();
540 $roleMailboxSearch = $this->getMockBuilder(ilRoleMailboxSearch::class)->disableOriginalConstructor()->onlyMethods([
'searchRoleIdsByAddressString'])->getMock();
542 $roleMailboxSearch->expects($this->exactly(4))->method(
'searchRoleIdsByAddressString')->willReturnOnConsecutiveCalls(
548 $rbacsystem->expects($this->exactly(4))->method(
'checkAccessOfUser')->willReturnOnConsecutiveCalls(
554 $rbacreview->expects($this->once())->method(
'isGlobalRole')->with(1)->willReturn(
true);
565 $this->assertFalse($type->validate(4711));
566 $this->assertCount(1, $type->getErrors());
567 $this->assertArrayHasKey(0, $type->getErrors());
568 $this->assertSame(
'mail_to_global_roles_not_allowed', $type->getErrors()[0]->getLanguageVariable());
570 $this->assertFalse($type->validate(4711));
571 $this->assertCount(1, $type->getErrors());
572 $this->assertArrayHasKey(0, $type->getErrors());
573 $this->assertSame(
'mail_recipient_not_found', $type->getErrors()[0]->getLanguageVariable());
575 $this->assertFalse($type->validate(4711));
576 $this->assertCount(1, $type->getErrors());
577 $this->assertArrayHasKey(0, $type->getErrors());
578 $this->assertSame(
'mail_multiple_role_recipients_found', $type->getErrors()[0]->getLanguageVariable());
580 $this->assertTrue($type->validate(4711));
581 $this->assertCount(0, $type->getErrors());
586 $origin = $this->getMockBuilder(ilMailAddressType::class)->getMock();
588 $origin->expects($this->once())->method(
'resolve');
589 $origin->expects($this->once())->method(
'validate');
601 $origin = $this->getMockBuilder(ilMailAddressType::class)->getMock();
603 $origin->expects($this->exactly(3))->method(
'resolve');
604 $origin->expects($this->exactly(3))->method(
'validate');
testNoUserIdCanBeResolvedFromEmailAddress()
testNoUserIdsCanBeResolvedFromRoleAddressWithoutAnyUsersBeingAssinged()
testFactoryWillReturnGroupAddressTypeForGroupName()
testNoUserIdsCanBeResolvedFromInvalidRoleAddress()
testPermissionsAreCheckedForRegularUsersWhenValidatingGlobalRoleAddresses()
Class ilGroupNameAsMailValidator.
Class ilMailMailingListAddressType.
testUserIdsCanBeResolvedFromRoleAddress()
testCacheOnlyResolvesAndValidatesRecipientsOnceIfCachingIsEnabled()
testValidationForAnonymousUserAsSystemActorSucceedsAlwaysForGlobalRoleAddresses()
testValidationSucceedsForExistingGroupName()
testAddressCanBeValidatedFromLoginOrEmailAddressType()
testAdminGroupNameIsAValidMailAddressTypes()
Interface ilMailAddressType.
Class ilMailAddressTypesTest.
testMemberCourseNameIsAValidMailAddressType()
getAddressTypeFactory(ilGroupNameAsMailValidator $groupNameValidatorMock)
testUserIdCanBeResolvedFromLoginAddress()
testAdminCourseNameIsAValidMailAddressType()
Class ilMailCachedAddressType.
testMailingListAddressCanBeValidated()
Class ilMailRoleAddressType.
testFactoryWillReturnLoginOrEmailAddressAddressType()
testMemberGroupNameIsAValidMailAddressType()
testUserIdsCanBeResolvedFromMailingListAddress()
testFactoryWillReturnRoleAddressType()
Class ilMailGroupAddressType.
createGroupNameAsValidatorMock()
testNoUserIdCanBeResolvedFromUnknownLoginAddress()
testCacheResolvesAndValidatesRecipientsOnEveryCallIfCachingIsDisabled()
testValidationFailsForNonExistingGroupNameAddress()
testUserIdsCannotBeResolvedFromNonExistingGroupNameAddress()
testFactoryWillReturnListAddressTypeForListName()
getWrappedAddressType(ilMailAddressType $type)
Class ilMailAddressTypeFactory.
testUserIdsCanBeResolvedFromGroupNameAddress()
Class ilMailLoginOrEmailAddressAddressType.