ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailAddressParserTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  private const DEFAULT_HOST = 'ilias';
28 
32  public static function emailAddressesProvider(): array
33  {
34  return [
35  'Username Addresses' => [
36  'phpunit@' . self::DEFAULT_HOST . ',phpunit',
37  [
38  new ilMailAddress('phpunit', self::DEFAULT_HOST),
39  new ilMailAddress('phpunit', self::DEFAULT_HOST),
40  ],
41  ],
42  'Email Address' => [
43  'phpunit@ilias.de',
44  [
45  new ilMailAddress('phpunit', 'ilias.de'),
46  ],
47  ],
48  'Email Addresses with Umlauts' => [
49  'phpünit@ilias.de,phpnitü@ilias.de,üphpnit@iliäs.de',
50  [
51  new ilMailAddress('phpünit', 'ilias.de'),
52  new ilMailAddress('phpnitü', 'ilias.de'),
53  new ilMailAddress('üphpnit', 'iliäs.de'),
54  ],
55  ],
56  'Trailing Dot in Local Part of Email Address' => [
57  'phpunit.@ilias.de',
58  [
59  new ilMailAddress('phpunit.', 'ilias.de'),
60  ],
61  ],
62  'Mailing List Address' => [
63  '#il_ml_4711',
64  [
65  new ilMailAddress('#il_ml_4711', self::DEFAULT_HOST),
66  ],
67  ],
68  'Role Address' => [
69  '#il_role_1000',
70  [
71  new ilMailAddress('#il_role_1000', self::DEFAULT_HOST),
72  ],
73  ],
74  'Local Role Address' => [
75  '#il_crs_member_998',
76  [
77  new ilMailAddress('#il_crs_member_998', self::DEFAULT_HOST),
78  ],
79  ],
80  'Course Role Address With Role Names for Course and Role' => [
81  '#member@[French Course]',
82  [
83  new ilMailAddress('#member', '[French Course]'),
84  ],
85  ],
86  'Course Role Recipient with Course Role Address (Role Names for Course and Role)' => [
87  'Course Administrator <#admin@[Math Course]>',
88  [
89  new ilMailAddress('#admin', '[Math Course]'),
90  ],
91  ],
92  'Course Role Recipient with Course Role Address (Numeric Id for Course Role)' => [
93  'Course Administrator <#il_crs_admin_2581>',
94  [
95  new ilMailAddress('#il_crs_admin_2581', self::DEFAULT_HOST),
96  ],
97  ],
98  'sepp@some.where;done@web.de' => [
99  // https://mantis.ilias.de/view.php?id=30306
100  'sepp@some.where;done@web.de',
101  [
102  new ilMailAddress('sepp', 'some.where'),
103  new ilMailAddress('done', 'web.de'),
104  ],
105  ],
106  ];
107  }
108 
112  public static function emailInvalidAddressesProvider(): array
113  {
114  return [
115  'Trailing Quote in Local Part' => [
116  'phpunit"@',
117  ],
118  'Trailing Quote in Local Part of Email Address' => [
119  'phpunit"@ilias.de',
120  ],
121  ];
122  }
123 
127  public function testBuiltInAddressParser(string $addresses, array $expected): void
128  {
129  if (!function_exists('imap_rfc822_parse_adrlist')) {
130  $this->markTestSkipped('Skipped test, imap extension required');
131  }
132 
133  $parser = new ilMailImapRfc822AddressParser($addresses);
134  $parsedAddresses = $parser->parse();
135 
136  $this->assertCount(count($expected), $parsedAddresses);
137  $this->assertEquals($expected, $parsedAddresses);
138  }
139 
143  public function testPearAddressParser(string $addresses, array $expected): void
144  {
145  $parser = new ilMailPearRfc822WrapperAddressParser($addresses);
146  $parsedAddresses = $parser->parse();
147 
148  $this->assertEquals($expected, $parsedAddresses);
149  $this->assertCount(count($expected), $parsedAddresses);
150  }
151 
153  {
154  $parser = new ilMailPearRfc822WrapperAddressParser('');
155  $parsedAddresses = $parser->parse();
156 
157  $this->assertCount(0, $parsedAddresses);
158  }
159 
164  {
165  $this->expectException(ilMailException::class);
166 
167  $parser = new ilMailPearRfc822WrapperAddressParser($addresses);
168  $parser->parse();
169  }
170 
175  {
176  $wrappedParser = $this->getMockBuilder(ilBaseMailRfc822AddressParser::class)
177  ->setConstructorArgs(['phpunit', 'ilias'])
178  ->getMock();
179  $wrappedParser->expects($this->once())->method('parse');
180 
181  $parser = new ilMailRfc822AddressParser($wrappedParser);
182  $parser->parse();
183  }
184 }
testPearAddressParser(string $addresses, array $expected)
emailAddressesProvider
Class ilMailBaseTest.
Class ilMailRfc822AddressParser.
testBuiltInAddressParser(string $addresses, array $expected)
emailAddressesProvider
Class ilMailImapRfc822AddressParser.
testExceptionShouldBeRaisedIfEmailCannotBeParsedWithPearAddressParser(string $addresses)
emailInvalidAddressesProvider
Class ilMailAddressParserTest.
Class ilMailAddress.