ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailAddressParserTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
10  const DEFAULT_HOST = 'ilias';
11 
15  protected function setUp()
16  {
17  parent::setUp();
18  }
19 
23  public function emailAddressesProvider() : array
24  {
25  return [
26  ['phpunit@' . self::DEFAULT_HOST . ',phpunit', [
27  new \ilMailAddress('phpunit', self::DEFAULT_HOST),
28  new \ilMailAddress('phpunit', self::DEFAULT_HOST)
29  ]],
30  ['phpunit@ilias.de', [
31  new \ilMailAddress('phpunit', 'ilias.de')
32  ]],
33  ['phpunit.@ilias.de',
34  [
35  new ilMailAddress('phpunit.', 'ilias.de')
36  ]
37  ],
38  ['#il_ml_4711', [
39  new \ilMailAddress('#il_ml_4711', self::DEFAULT_HOST)
40  ]],
41  ['#il_role_1000', [
42  new \ilMailAddress('#il_role_1000', self::DEFAULT_HOST)
43  ]],
44  ['#il_crs_member_998', [
45  new \ilMailAddress('#il_crs_member_998', self::DEFAULT_HOST)
46  ]],
47  ['#member@[French Course]', [
48  new \ilMailAddress('#member', '[French Course]')
49  ]],
50  ['Course Administrator <#admin@[Math Course]>', [
51  new \ilMailAddress('#admin', '[Math Course]')
52  ]],
53  ['Course Administrator <#il_crs_admin_2581>', [
54  new \ilMailAddress('#il_crs_admin_2581', self::DEFAULT_HOST)
55  ]],
56  ];
57  }
58 
62  public function emailInvalidAddressesProvider() : array
63  {
64  return [
65  ['phpunit"@'],
66  ['phpunit"@ilias.de'],
67  ];
68  }
69 
75  public function testBuiltInAddressParser(string $addresses, array $expected)
76  {
77  if (!function_exists('imap_rfc822_parse_adrlist')) {
78  $this->markTestSkipped('Skipped test, imap extension required');
79  }
80 
81  $parser = new \ilMailImapRfc822AddressParser($addresses);
82  $parsedAddresses = $parser->parse();
83 
84  $this->assertCount(count($expected), $parsedAddresses);
85  $this->assertEquals($expected, $parsedAddresses);
86  }
87 
93  public function testPearAddressParser(string $addresses, array $expected)
94  {
95  $parser = new \ilMailPearRfc822WrapperAddressParser($addresses);
96  $parsedAddresses = $parser->parse();
97 
98  $this->assertCount(count($expected), $parsedAddresses);
99  $this->assertEquals($expected, $parsedAddresses);
100  }
101 
107  {
108  $this->expectException(ilMailException::class);
109 
111  $parser->parse();
112  }
113 
118  {
119  $wrappedParser = $this->getMockBuilder(\ilBaseMailRfc822AddressParser::class)
120  ->setConstructorArgs(['phpunit', 'ilias'])
121  ->getMock();
122  $wrappedParser->expects($this->once())->method('parse');
123 
124  $parser = new \ilMailRfc822AddressParser($wrappedParser);
125  $parser->parse();
126  }
127 }
Class ilMailPearRfc822WrapperAddressParser.
testPearAddressParser(string $addresses, array $expected)
Class ilMailBaseTest.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
testBuiltInAddressParser(string $addresses, array $expected)
testExceptionShouldBeRaisedIfEmailCannotBeParsedWithPearAddressParser(string $addresses)
emailInvalidAddressesProvider
$parser
Definition: BPMN2Parser.php:23
Class ilMailAddressParserTest.
Class ilMailAddress.