‪TYPO3CMS  9.5
MailerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪MailerTest extends UnitTestCase
28 {
32  protected ‪$resetSingletonInstances = true;
33 
37  protected ‪$subject;
38 
42  protected function ‪setUp()
43  {
44  $this->subject = $this->getMockBuilder(Mailer::class)
45  ->setMethods(['emitPostInitializeMailerSignal'])
46  ->disableOriginalConstructor()
47  ->getMock();
48  }
49 
54  {
55  $settings = ['transport' => 'mbox', 'transport_mbox_file' => '/path/to/file'];
56  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'] = ['transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail'];
57  $this->subject->injectMailSettings($settings);
58  $this->subject->__construct();
59  $this->assertAttributeSame($settings, 'mailSettings', $this->subject);
60  }
61 
66  {
67  $settings = (‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'] = ['transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail']);
68  $this->subject->__construct();
69  $this->assertAttributeSame($settings, 'mailSettings', $this->subject);
70  }
71 
77  public static function ‪wrongConfigurationProvider()
78  {
79  return [
80  'smtp but no host' => [['transport' => 'smtp']],
81  'sendmail but no command' => [['transport' => 'sendmail']],
82  'mbox but no file' => [['transport' => 'mbox']],
83  'no instance of Swift_Transport' => [['transport' => ErrorPageController::class]]
84  ];
85  }
86 
92  public function ‪wrongConfigurationThrowsException($settings)
93  {
94  $this->expectException(Exception::class);
95  $this->expectExceptionCode(1291068569);
96 
97  $this->subject->injectMailSettings($settings);
98  $this->subject->__construct();
99  }
100 
105  {
106  $this->subject->injectMailSettings(['transport' => FakeTransportFixture::class]);
107  $this->subject->__construct();
108  }
109 
113  public function ‪noPortSettingSetsPortTo25()
114  {
115  $this->subject->injectMailSettings(['transport' => 'smtp', 'transport_smtp_server' => 'localhost']);
116  $this->subject->__construct();
117  $port = $this->subject->getTransport()->getPort();
118  $this->assertEquals(25, $port);
119  }
120 
124  public function ‪emptyPortSettingSetsPortTo25()
125  {
126  $this->subject->injectMailSettings(['transport' => 'smtp', 'transport_smtp_server' => 'localhost:']);
127  $this->subject->__construct();
128  $port = $this->subject->getTransport()->getPort();
129  $this->assertEquals(25, $port);
130  }
131 
135  public function ‪givenPortSettingIsRespected()
136  {
137  $this->subject->injectMailSettings(['transport' => 'smtp', 'transport_smtp_server' => 'localhost:12345']);
138  $this->subject->__construct();
139  $port = $this->subject->getTransport()->getPort();
140  $this->assertEquals(12345, $port);
141  }
142 
147  public function ‪getRealTransportReturnsNoSpoolTransport($settings)
148  {
149  $this->subject->injectMailSettings($settings);
150  $transport = $this->subject->getRealTransport();
151 
152  $this->assertInstanceOf(\Swift_Transport::class, $transport);
153  $this->assertNotInstanceOf(\Swift_SpoolTransport::class, $transport);
154  }
155 
162  {
163  return [
164  'without spool' => [[
165  'transport' => 'mail',
166  'spool' => '',
167  ]],
168  'with spool' => [[
169  'transport' => 'mail',
170  'spool' => 'memory',
171  ]],
172  ];
173  }
174 }
‪TYPO3\CMS\Core\Controller\ErrorPageController
Definition: ErrorPageController.php:31
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\wrongConfigurationProvider
‪static array wrongConfigurationProvider()
Definition: MailerTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\globalSettingsAreUsedIfNoSettingsAreInjected
‪globalSettingsAreUsedIfNoSettingsAreInjected()
Definition: MailerTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Mail
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\$subject
‪Mailer $subject
Definition: MailerTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\noPortSettingSetsPortTo25
‪noPortSettingSetsPortTo25()
Definition: MailerTest.php:111
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest
Definition: MailerTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\wrongConfigurationThrowsException
‪wrongConfigurationThrowsException($settings)
Definition: MailerTest.php:90
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\emptyPortSettingSetsPortTo25
‪emptyPortSettingSetsPortTo25()
Definition: MailerTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\setUp
‪setUp()
Definition: MailerTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\injectedSettingsAreNotReplacedByGlobalSettings
‪injectedSettingsAreNotReplacedByGlobalSettings()
Definition: MailerTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\getRealTransportReturnsNoSpoolTransport
‪getRealTransportReturnsNoSpoolTransport($settings)
Definition: MailerTest.php:145
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:29
‪TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeTransportFixture
Definition: FakeTransportFixture.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\providingCorrectClassnameDoesNotThrowException
‪providingCorrectClassnameDoesNotThrowException()
Definition: MailerTest.php:102
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: MailerTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\getRealTransportReturnsNoSpoolTransportProvider
‪static array getRealTransportReturnsNoSpoolTransportProvider()
Definition: MailerTest.php:159
‪TYPO3\CMS\Core\Tests\Unit\Mail\MailerTest\givenPortSettingIsRespected
‪givenPortSettingIsRespected()
Definition: MailerTest.php:133