ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailAddressParserTest.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
3 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
10 {
11  const DEFAULT_HOST = 'ilias';
12 
16  public function emailAddressesProvider() : array
17  {
18  return [
19  'Username Addresses' => [
20  'phpunit@' . self::DEFAULT_HOST . ',phpunit',
21  [
22  new ilMailAddress('phpunit', self::DEFAULT_HOST),
23  new ilMailAddress('phpunit', self::DEFAULT_HOST),
24  ]
25  ],
26  'Email Address' => [
27  'phpunit@ilias.de',
28  [
29  new ilMailAddress('phpunit', 'ilias.de'),
30  ]
31  ],
32  'Email Addresses with Umlauts' => [
33  'phpünit@ilias.de,phpnitü@ilias.de,üphpnit@iliäs.de',
34  [
35  new ilMailAddress('phpünit', 'ilias.de'),
36  new ilMailAddress('phpnitü', 'ilias.de'),
37  new ilMailAddress('üphpnit', 'iliäs.de'),
38  ]
39  ],
40  'Trailing Dot in Local Part of Email Address' => [
41  'phpunit.@ilias.de',
42  [
43  new ilMailAddress('phpunit.', 'ilias.de')
44  ]
45  ],
46  'Mailing List Address' => [
47  '#il_ml_4711',
48  [
49  new ilMailAddress('#il_ml_4711', self::DEFAULT_HOST),
50  ]
51  ],
52  'Role Address' => [
53  '#il_role_1000',
54  [
55  new ilMailAddress('#il_role_1000', self::DEFAULT_HOST),
56  ]
57  ],
58  'Local Role Address' => [
59  '#il_crs_member_998',
60  [
61  new ilMailAddress('#il_crs_member_998', self::DEFAULT_HOST),
62  ]
63  ],
64  'Course Role Address With Role Names for Course and Role' => [
65  '#member@[French Course]',
66  [
67  new ilMailAddress('#member', '[French Course]'),
68  ]
69  ],
70  'Course Role Recipient with Course Role Address (Role Names for Course and Role)' => [
71  'Course Administrator <#admin@[Math Course]>',
72  [
73  new ilMailAddress('#admin', '[Math Course]'),
74  ]
75  ],
76  'Course Role Recipient with Course Role Address (Numeric Id for Course Role)' => [
77  'Course Administrator <#il_crs_admin_2581>',
78  [
79  new ilMailAddress('#il_crs_admin_2581', self::DEFAULT_HOST),
80  ]
81  ],
82  ];
83  }
84 
88  public function emailInvalidAddressesProvider() : array
89  {
90  return [
91  'Trailing Quote in Local Part' => [
92  'phpunit"@'
93  ],
94  'Trailing Quote in Local Part of Email Address' => [
95  'phpunit"@ilias.de'
96  ],
97  ];
98  }
99 
105  public function testBuiltInAddressParser(string $addresses, array $expected) : void
106  {
107  if (!function_exists('imap_rfc822_parse_adrlist')) {
108  $this->markTestSkipped('Skipped test, imap extension required');
109  }
110 
111  $parser = new ilMailImapRfc822AddressParser($addresses);
112  $parsedAddresses = $parser->parse();
113 
114  $this->assertCount(count($expected), $parsedAddresses);
115  $this->assertEquals($expected, $parsedAddresses);
116  }
117 
123  public function testPearAddressParser(string $addresses, array $expected) : void
124  {
126  $parsedAddresses = $parser->parse();
127 
128  $this->assertCount(count($expected), $parsedAddresses);
129  $this->assertEquals($expected, $parsedAddresses);
130  }
131 
137  {
138  $this->expectException(ilMailException::class);
139 
141  $parser->parse();
142  }
143 
148  {
149  $wrappedParser = $this->getMockBuilder(ilBaseMailRfc822AddressParser::class)
150  ->setConstructorArgs(['phpunit', 'ilias'])
151  ->getMock();
152  $wrappedParser->expects($this->once())->method('parse');
153 
154  $parser = new ilMailRfc822AddressParser($wrappedParser);
155  $parser->parse();
156  }
157 }
Class ilMailPearRfc822WrapperAddressParser.
testPearAddressParser(string $addresses, array $expected)
Class ilMailBaseTest.
Class ilMailRfc822AddressParser.
testBuiltInAddressParser(string $addresses, array $expected)
Class ilMailImapRfc822AddressParser.
testExceptionShouldBeRaisedIfEmailCannotBeParsedWithPearAddressParser(string $addresses)
emailInvalidAddressesProvider
$parser
Definition: BPMN2Parser.php:23
Class ilMailAddressParserTest.
Class ilMailAddress.