[TASK] Doctrine: Migrate DatabaseWriter
[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 use TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeTransportFixture;
17
18 /**
19 * Testcase for the TYPO3\CMS\Core\Mail\Mailer class.
20 */
21 class MailerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
22 {
23 /**
24 * @var \TYPO3\CMS\Core\Mail\Mailer
25 */
26 protected $subject;
27
28 protected function setUp()
29 {
30 $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer::class)
31 ->setMethods(array('emitPostInitializeMailerSignal'))
32 ->disableOriginalConstructor()
33 ->getMock();
34 }
35
36 //////////////////////////
37 // Tests concerning TYPO3\CMS\Core\Mail\Mailer
38 //////////////////////////
39 /**
40 * @test
41 */
42 public function injectedSettingsAreNotReplacedByGlobalSettings()
43 {
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);
49 }
50
51 /**
52 * @test
53 */
54 public function globalSettingsAreUsedIfNoSettingsAreInjected()
55 {
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);
59 }
60
61 /**
62 * Data provider for wrongConfigigurationThrowsException
63 *
64 * @return array Data sets
65 */
66 public static function wrongConfigigurationProvider()
67 {
68 return array(
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\Messaging\ErrorpageMessage::class))
73 );
74 }
75
76 /**
77 * @test
78 * @param $settings
79 * @dataProvider wrongConfigigurationProvider
80 */
81 public function wrongConfigigurationThrowsException($settings)
82 {
83 $this->expectException(\TYPO3\CMS\Core\Exception::class);
84 $this->expectExceptionCode(1291068569);
85
86 $this->subject->injectMailSettings($settings);
87 $this->subject->__construct();
88 }
89
90 /**
91 * @test
92 */
93 public function providingCorrectClassnameDoesNotThrowException()
94 {
95 $this->subject->injectMailSettings(array('transport' => FakeTransportFixture::class));
96 $this->subject->__construct();
97 }
98
99 /**
100 * @test
101 */
102 public function noPortSettingSetsPortTo25()
103 {
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);
108 }
109
110 /**
111 * @test
112 */
113 public function emptyPortSettingSetsPortTo25()
114 {
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);
119 }
120
121 /**
122 * @test
123 */
124 public function givenPortSettingIsRespected()
125 {
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);
130 }
131 }