Merge pull request #3179 from webpartners/master
[civicrm-core.git] / tests / phpunit / CRM / Utils / MailTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3
4 /**
5 * Class CRM_Utils_MailTest
6 */
7 class CRM_Utils_MailTest extends CiviUnitTestCase {
8 /**
9 * @return array
10 */
11 function get_info() {
12 return array(
13 'name' => 'Mail Test',
14 'description' => 'Test RFC822 formatting',
15 'group' => 'CiviCRM BAO Tests',
16 );
17 }
18
19 function setUp() {
20 parent::setUp();
21 }
22
23 /**
24 * test case for add( )
25 * test with empty params.
26 */
27 function testFormatRFC822() {
28
29 $values = array(
30 array('name' => "Test User",
31 'email' => "foo@bar.com",
32 'result' => "Test User <foo@bar.com>",
33 ),
34 array(
35 'name' => '"Test User"',
36 'email' => "foo@bar.com",
37 'result' => "Test User <foo@bar.com>",
38 ),
39 array(
40 'name' => "User, Test",
41 'email' => "foo@bar.com",
42 'result' => '"User, Test" <foo@bar.com>',
43 ),
44 array(
45 'name' => '"User, Test"',
46 'email' => "foo@bar.com",
47 'result' => '"User, Test" <foo@bar.com>',
48 ),
49 array(
50 'name' => '"Test User"',
51 'email' => "foo@bar.com",
52 'result' => '"Test User" <foo@bar.com>',
53 'useQuote' => TRUE,
54 ),
55 array(
56 'name' => "User, Test",
57 'email' => "foo@bar.com",
58 'result' => '"User, Test" <foo@bar.com>',
59 'useQuote' => TRUE,
60 ),
61 );
62 foreach ($values as $value) {
63 $result = CRM_Utils_Mail::formatRFC822Email($value['name'],
64 $value['email'],
65 CRM_Utils_Array::value('useQuote', $value, FALSE)
66 );
67 $this->assertEquals($result, $value['result'], 'Expected encoding does not match');
68 }
69 }
70 }
71