TYPO3 CMS  TYPO3_8-7
MailerTest.php
Go to the documentation of this file.
1 <?php
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  */
17 
21 class MailerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
26  protected $subject;
27 
28  protected function setUp()
29  {
30  $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Mail\Mailer::class)
31  ->setMethods(['emitPostInitializeMailerSignal'])
32  ->disableOriginalConstructor()
33  ->getMock();
34  }
35 
37  // Tests concerning TYPO3\CMS\Core\Mail\Mailer
39 
43  {
44  $settings = ['transport' => 'mbox', 'transport_mbox_file' => '/path/to/file'];
45  $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = ['transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail'];
46  $this->subject->injectMailSettings($settings);
47  $this->subject->__construct();
48  $this->assertAttributeSame($settings, 'mailSettings', $this->subject);
49  }
50 
55  {
56  $settings = ($GLOBALS['TYPO3_CONF_VARS']['MAIL'] = ['transport' => 'sendmail', 'transport_sendmail_command' => 'sendmail']);
57  $this->subject->__construct();
58  $this->assertAttributeSame($settings, 'mailSettings', $this->subject);
59  }
60 
66  public static function wrongConfigurationProvider()
67  {
68  return [
69  'smtp but no host' => [['transport' => 'smtp']],
70  'sendmail but no command' => [['transport' => 'sendmail']],
71  'mbox but no file' => [['transport' => 'mbox']],
72  'no instance of Swift_Transport' => [['transport' => \TYPO3\CMS\Core\Controller\ErrorPageController::class]]
73  ];
74  }
75 
81  public function wrongConfigurationThrowsException($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 
94  {
95  $this->subject->injectMailSettings(['transport' => FakeTransportFixture::class]);
96  $this->subject->__construct();
97  }
98 
102  public function noPortSettingSetsPortTo25()
103  {
104  $this->subject->injectMailSettings(['transport' => 'smtp', 'transport_smtp_server' => 'localhost']);
105  $this->subject->__construct();
106  $port = $this->subject->getTransport()->getPort();
107  $this->assertEquals(25, $port);
108  }
109 
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 givenPortSettingIsRespected()
125  {
126  $this->subject->injectMailSettings(['transport' => 'smtp', 'transport_smtp_server' => 'localhost:12345']);
127  $this->subject->__construct();
128  $port = $this->subject->getTransport()->getPort();
129  $this->assertEquals(12345, $port);
130  }
131 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']