Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_mail_message.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Pu;
8 /**
9  * @author Anakeen
10  * @package Dcp\Pu
11  */
12 
13 require_once 'PU_testcase_dcp.php';
14 
16 {
17  /**
18  * @dataProvider dataMailAddrParser
19  */
20  public function testMailAddrParser($str, $expectedMails)
21  {
22  $p = new \Dcp\Mail\MailAddrParser();
23  $addrList = array();
24  $err = '';
25  try {
26  $addrList = $p->parse($str);
27  }
28  catch(\Dcp\Mail\MailAddrParserException $e) {
29  $err = $e->getMessage();
30  }
31  $this->assertEmpty($err, sprintf("Unexpected parse error: %s", $err));
32  foreach ($expectedMails as $expected) {
33  $found = false;
34  foreach ($addrList as $addr) {
35  if ($addr->address == $expected) {
36  $found = true;
37  break;
38  }
39  }
40  $this->assertTrue($found, sprintf("Expected address '%s' not found in [%s].", $expected, $str));
41  }
42  }
43 
44  public function dataMailAddrParser()
45  {
46  return array(
47  array(
48  'foo.bar@example.net',
49  array(
50  'foo.bar@example.net'
51  )
52  ) ,
53  array(
54  'bill.o\'reilly@example.net',
55  array(
56  'bill.o\'reilly@example.net'
57  )
58  ) ,
59  array(
60  ' John "Doe" Junior <john.doe@example.net> , "Foo \\"Bar, Baz\\" Buz" <foo.buz@example.net> ,
61  Bill O\'Reilly <bill.o\'reilly@example.net>,
62  foo.bar@example.net ,
63  <foo.bar@acme.corp> ,
64  "Foo <ACME Corp.>" <foo@acme.corp>
65 ',
66  array(
67  'john.doe@example.net',
68  'foo.buz@example.net',
69  'bill.o\'reilly@example.net',
70  'foo.bar@example.net',
71  'foo.bar@acme.corp',
72  'foo@acme.corp'
73  )
74  )
75  );
76  }
77 }
testMailAddrParser($str, $expectedMails)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen