2 namespace TYPO3\CMS\Core\Tests\Unit\Mail
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeTransportFixture
;
19 * Testcase for the TYPO3\CMS\Core\Mail\Mailer class.
21 class MailerTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
24 * @var \TYPO3\CMS\Core\Mail\Mailer
28 protected function setUp()
30 $this->subject
= $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer
::class)
31 ->setMethods(array('emitPostInitializeMailerSignal'))
32 ->disableOriginalConstructor()
36 //////////////////////////
37 // Tests concerning TYPO3\CMS\Core\Mail\Mailer
38 //////////////////////////
42 public function injectedSettingsAreNotReplacedByGlobalSettings()
44 $settings = array('transport' => 'mbox', 'transport_mbox_file' => '/path/to/file');
45 $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail');
46 $this->subject
->injectMailSettings($settings);
47 $this->subject
->__construct();
48 $this->assertAttributeSame($settings, 'mailSettings', $this->subject
);
54 public function globalSettingsAreUsedIfNoSettingsAreInjected()
56 $settings = ($GLOBALS['TYPO3_CONF_VARS']['MAIL'] = array('transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail'));
57 $this->subject
->__construct();
58 $this->assertAttributeSame($settings, 'mailSettings', $this->subject
);
62 * Data provider for wrongConfigurationThrowsException
64 * @return array Data sets
66 public static function wrongConfigurationProvider()
69 'smtp but no host' => array(array('transport' => 'smtp')),
70 'sendmail but no command' => array(array('transport' => 'sendmail')),
71 'mbox but no file' => array(array('transport' => 'mbox')),
72 'no instance of Swift_Transport' => array(array('transport' => \TYPO3\CMS\Core\Controller\ErrorPageController
::class))
79 * @dataProvider wrongConfigurationProvider
81 public function wrongConfigurationThrowsException($settings)
83 $this->expectException(\TYPO3\CMS\Core\Exception
::class);
84 $this->expectExceptionCode(1291068569);
86 $this->subject
->injectMailSettings($settings);
87 $this->subject
->__construct();
93 public function providingCorrectClassnameDoesNotThrowException()
95 $this->subject
->injectMailSettings(array('transport' => FakeTransportFixture
::class));
96 $this->subject
->__construct();
102 public function noPortSettingSetsPortTo25()
104 $this->subject
->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost'));
105 $this->subject
->__construct();
106 $port = $this->subject
->getTransport()->getPort();
107 $this->assertEquals(25, $port);
113 public function emptyPortSettingSetsPortTo25()
115 $this->subject
->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:'));
116 $this->subject
->__construct();
117 $port = $this->subject
->getTransport()->getPort();
118 $this->assertEquals(25, $port);
124 public function givenPortSettingIsRespected()
126 $this->subject
->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:12345'));
127 $this->subject
->__construct();
128 $port = $this->subject
->getTransport()->getPort();
129 $this->assertEquals(12345, $port);