[TASK] Re-work/simplify copyright header in PHP files - Part 4
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase for the TYPO3\CMS\Core\Mail\Mailer class.
19 *
20 * @author Helmut Hummel <helmut.hummel@typo3.org>
21 */
22 class MailerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Mail\Mailer
26 */
27 protected $fixture;
28
29 public function setUp() {
30 $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Mail\\Mailer', array('noMethodMocked'), array(), '', FALSE);
31 }
32
33 //////////////////////////
34 // Tests concerning TYPO3\CMS\Core\Mail\Mailer
35 //////////////////////////
36 /**
37 * @test
38 */
39 public function injectedSettingsAreNotReplacedByGlobalSettings() {
40 $settings = array('transport' => 'mbox', 'transport_mbox_file' => '/path/to/file');
41 $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail');
42 $this->fixture->injectMailSettings($settings);
43 $this->fixture->__construct();
44 $this->assertAttributeSame($settings, 'mailSettings', $this->fixture);
45 }
46
47 /**
48 * @test
49 */
50 public function globalSettingsAreUsedIfNoSettingsAreInjected() {
51 $settings = ($GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail'));
52 $this->fixture->__construct();
53 $this->assertAttributeSame($settings, 'mailSettings', $this->fixture);
54 }
55
56 /**
57 * Data provider for wrongConfigigurationThrowsException
58 *
59 * @return array Data sets
60 */
61 static public function wrongConfigigurationProvider() {
62 return array(
63 'smtp but no host' => array(array('transport' => 'smtp')),
64 'sendmail but no command' => array(array('transport' => 'sendmail')),
65 'mbox but no file' => array(array('transport' => 'mbox')),
66 'no instance of Swift_Transport' => array(array('transport' => 'TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage'))
67 );
68 }
69
70 /**
71 * @test
72 * @param $settings
73 * @dataProvider wrongConfigigurationProvider
74 * @expectedException \TYPO3\CMS\Core\Exception
75 */
76 public function wrongConfigigurationThrowsException($settings) {
77 $this->fixture->injectMailSettings($settings);
78 $this->fixture->__construct();
79 }
80
81 /**
82 * @test
83 */
84 public function providingCorrectClassnameDoesNotThrowException() {
85 if (!class_exists('t3lib_mail_SwiftMailerFakeTransport')) {
86 // Create fake custom transport class
87 eval('class t3lib_mail_SwiftMailerFakeTransport extends \\TYPO3\\CMS\\Core\\Mail\\MboxTransport {
88 public function __construct($settings) {}
89 }');
90 }
91 $this->fixture->injectMailSettings(array('transport' => 't3lib_mail_SwiftMailerFakeTransport'));
92 $this->fixture->__construct();
93 }
94
95 /**
96 * @test
97 */
98 public function noPortSettingSetsPortTo25() {
99 $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost'));
100 $this->fixture->__construct();
101 $port = $this->fixture->getTransport()->getPort();
102 $this->assertEquals(25, $port);
103 }
104
105 /**
106 * @test
107 */
108 public function emptyPortSettingSetsPortTo25() {
109 $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:'));
110 $this->fixture->__construct();
111 $port = $this->fixture->getTransport()->getPort();
112 $this->assertEquals(25, $port);
113 }
114
115 /**
116 * @test
117 */
118 public function givenPortSettingIsRespected() {
119 $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:12345'));
120 $this->fixture->__construct();
121 $port = $this->fixture->getTransport()->getPort();
122 $this->assertEquals(12345, $port);
123 }
124 }