ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMailAddressListTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\Attributes\DataProvider;
22
24{
25 public static function addressTestProvider(): array
26 {
27 return [
28 'Username Addresses' => [
29 [
30 new ilMailAddress('phpunit', 'ilias'),
31 ],
32 [
33 new ilMailAddress('user', 'ilias'),
34 new ilMailAddress('max.mustermann', 'ilias.de'),
35 ],
36 1,
37 ],
38 'Role Addresses' => [
39 [
40 new ilMailAddress('#il_ml_4711', 'ilias'),
41 new ilMailAddress('#il_ml_4712', 'ilias'),
42 new ilMailAddress('#il_ml_4713', 'ilias'),
43 ],
44 [
45 new ilMailAddress('#il_ml_4713', 'ilias'),
46 new ilMailAddress('#il_role_1000', 'ilias'),
47 new ilMailAddress('#admin', '[Math Course]'),
48 ],
49 2,
50 ],
51 ];
52 }
53
54 #[DataProvider('addressTestProvider')]
56 array $left_addresses,
57 array $right_addresses,
58 int $num_expected_items
59 ): void {
60 $left = new ilMailAddressListImpl($left_addresses);
61 $right = new ilMailAddressListImpl($right_addresses);
62
63 $list = new ilMailDiffAddressList($left, $right);
64 $this->assertCount($num_expected_items, $list->value());
65 }
66
67 public static function externalAddressTestProvider(): array
68 {
69 return [
70 'Username' => [
71 new ilMailAddress('user', 'ilias'),
72 0
73 ],
74 'Email Address exists as Username' => [
75 new ilMailAddress('max.mustermann', 'ilias.de'),
76 0
77 ],
78 'Email Address' => [
79 new ilMailAddress('phpunit', 'gmail.com'),
80 1
81 ],
82 'Mailing List' => [
83 new ilMailAddress('#il_ml_4713', 'ilias'),
84 0
85 ],
86 'Role (technical)' => [
87 new ilMailAddress('#il_role_1000', 'ilias'),
88 0
89 ],
90 'Role (human readable)' => [
91 new ilMailAddress('#admin', '[Math Course]'),
92 0
93 ],
94 ];
95 }
96
97 #[DataProvider('externalAddressTestProvider')]
99 ilMailAddress $address,
100 int $num_expected_items
101 ): void {
102 $list = new ilMailAddressListImpl([$address]);
103 $external_list = new ilMailOnlyExternalAddressList($list, 'ilias', static function (string $address): int {
104 if ($address === 'max.mustermann@ilias.de') {
105 return 4711;
106 }
107
108 return 0;
109 });
110
111 $this->assertCount($num_expected_items, $external_list->value());
112 }
113}
testExternalAddressListDecoratorFiltersExternalAddresses(ilMailAddress $address, int $num_expected_items)
testDiffAddressListCanCalculateTheDifferenceOfTwoLists(array $left_addresses, array $right_addresses, int $num_expected_items)