[TASK] Refactor t3lib_mail_Mailer and add unit tests
[Packages/TYPO3.CMS.git] / tests / Unit / t3lib / mail / class.t3lib_mail_swiftmaileradapterTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Ernesto Baschny (ernst@cron-it.de)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the t3lib_mail_SwiftMailerAdapter class.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 *
31 * @author Ernesto Baschny <ernst@cron-it.de>
32 */
33 class t3lib_mail_SwiftMailerAdapterTest extends tx_phpunit_testcase {
34
35 /**
36 * @var t3lib_mail_SwiftMailerAdapter
37 */
38 protected $fixture;
39
40 public function setUp() {
41 if (!class_exists('t3lib_mail_SwiftMailerAdapterExposed')) {
42 // Make protected methods accessible so that they can be tested:
43 eval('class t3lib_mail_SwiftMailerAdapterExposed extends t3lib_mail_SwiftMailerAdapter {
44 public function parseAddressesExposed($args) {
45 return $this->parseAddresses($args);
46 }
47 }');
48 }
49 $this->fixture = new t3lib_mail_SwiftMailerAdapterExposed();
50 }
51
52 public function tearDown() {
53 }
54
55 //////////////////////////
56 // Tests concerning mail
57 //////////////////////////
58
59 /**
60 * Data provider for parseAddressesTest
61 *
62 * @return array Data sets
63 */
64 public static function parseAddressesProvider() {
65 return array(
66 'name &ltemail&gt;' => array('name <email@example.org>', array('email@example.org' => 'name')),
67 '&lt;email&gt;' => array('<email@example.org>', array('email@example.org')),
68 'email' => array('email@example.org', array('email@example.org')),
69 'email1,email2' => array('email1@example.org,email2@example.com', array('email1@example.org', 'email2@example.com')),
70 'name &ltemail&gt;,email2' => array('name <email1@example.org>,email2@example.com', array('email1@example.org' => 'name', 'email2@example.com')),
71 '"last, first" &lt;name@example.org&gt;' => array('"last, first" <email@example.org>', array('email@example.org' => '"last, first"')),
72 'email,name &ltemail&gt;,"last, first" &lt;name@example.org&gt;' =>
73 array(
74 'email1@example.org, name <email2@example.org>, "last, first" <email3@example.org>',
75 array(
76 'email1@example.org',
77 'email2@example.org' => 'name',
78 'email3@example.org' => '"last, first"',
79 )
80 ),
81 );
82 }
83
84 /**
85 * @test
86 * @dataProvider parseAddressesProvider
87 */
88 public function parseAddressesTest($source, $addressList) {
89 $this->assertEquals(
90 $addressList,
91 $this->fixture->parseAddressesExposed($source)
92 );
93 }
94 }
95 ?>