32a1092181ad85e2758e99863b31dc781997e46c
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Mail / MailerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Mail;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Ernesto Baschny (ernst@cron-it.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for the TYPO3\CMS\Core\Mail\Mailer class.
29 *
30 * @author Helmut Hummel <helmut.hummel@typo3.org>
31 */
32 class MailerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Mail\Mailer
36 */
37 protected $fixture;
38
39 /**
40 * @var array
41 */
42 protected $globalMailSettings;
43
44 public function setUp() {
45 $this->globalMailSettings = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
46 $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Mail\\Mailer', array('noMethodMocked'), array(), '', FALSE);
47 }
48
49 public function tearDown() {
50 unset($this->fixture);
51 $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $this->globalMailSettings;
52 }
53
54 /**
55 * @test
56 */
57 public function injectedSettingsAreNotReplacedByGlobalSettings() {
58 $settings = array('transport' => 'mbox', 'transport_mbox_file' => '/path/to/file');
59 $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail');
60 $this->fixture->injectMailSettings($settings);
61 $this->fixture->__construct();
62 $this->assertAttributeSame($settings, 'mailSettings', $this->fixture);
63 }
64
65 /**
66 * @test
67 */
68 public function globalSettingsAreUsedIfNoSettingsAreInjected() {
69 $settings = ($GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail'));
70 $this->fixture->__construct();
71 $this->assertAttributeSame($settings, 'mailSettings', $this->fixture);
72 }
73
74 /**
75 * Data provider for wrongConfigigurationThrowsException
76 *
77 * @return array Data sets
78 */
79 static public function wrongConfigigurationProvider() {
80 return array(
81 'smtp but no host' => array(array('transport' => 'smtp')),
82 'sendmail but no command' => array(array('transport' => 'sendmail')),
83 'mbox but no file' => array(array('transport' => 'mbox')),
84 'no instance of Swift_Transport' => array(array('transport' => 'TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage'))
85 );
86 }
87
88 /**
89 * @test
90 * @param $settings
91 * @dataProvider wrongConfigigurationProvider
92 * @expectedException \TYPO3\CMS\Core\Exception
93 */
94 public function wrongConfigigurationThrowsException($settings) {
95 $this->fixture->injectMailSettings($settings);
96 $this->fixture->__construct();
97 }
98
99 /**
100 * @test
101 */
102 public function providingCorrectClassnameDoesNotThrowException() {
103 if (!class_exists('t3lib_mail_SwiftMailerFakeTransport')) {
104 // Create fake custom transport class
105 eval('class t3lib_mail_SwiftMailerFakeTransport extends \\TYPO3\\CMS\\Core\\Mail\\MboxTransport {
106 public function __construct($settings) {}
107 }');
108 }
109 $this->fixture->injectMailSettings(array('transport' => 't3lib_mail_SwiftMailerFakeTransport'));
110 $this->fixture->__construct();
111 }
112
113 }
114
115 ?>