‪TYPO3CMS  9.5
TransportFactoryTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪TransportFactoryTest extends UnitTestCase
29 {
33  protected ‪$resetSingletonInstances = true;
34 
39  {
40  $mailSettings = [
41  'transport' => 'mail',
42  'transport_smtp_server' => 'localhost:25',
43  'transport_smtp_encrypt' => '',
44  'transport_smtp_username' => '',
45  'transport_smtp_password' => '',
46  'transport_sendmail_command' => '',
47  'transport_mbox_file' => '',
48  'defaultMailFromAddress' => '',
49  'defaultMailFromName' => '',
50  'transport_spool_type' => 'file',
51  'transport_spool_filepath' => '.',
52  ];
53 
54  // Register fixture class
55  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\Swift_FileSpool::class]['className'] = Fixtures\FakeFileSpoolFixture::class;
56 
57  $transport = (new ‪TransportFactory())->get($mailSettings);
58  $this->assertInstanceOf(\Swift_SpoolTransport::class, $transport);
59 
61  $spool = $transport->getSpool();
62  $this->assertInstanceOf(\Swift_FileSpool::class, $spool);
63 
64  $path = $spool->getPath();
65  $this->assertContains($mailSettings['transport_spool_filepath'], $path);
66  }
67 
72  {
73  $mailSettings = [
74  'transport' => 'mail',
75  'transport_smtp_server' => 'localhost:25',
76  'transport_smtp_encrypt' => '',
77  'transport_smtp_username' => '',
78  'transport_smtp_password' => '',
79  'transport_sendmail_command' => '',
80  'transport_mbox_file' => '',
81  'defaultMailFromAddress' => '',
82  'defaultMailFromName' => '',
83  'transport_spool_type' => 'memory',
84  'transport_spool_filepath' => ‪Environment::getVarPath() . '/messages/',
85  ];
86 
87  // Register fixture class
88  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][MemorySpool::class]['className'] = Fixtures\FakeMemorySpoolFixture::class;
89 
90  $transport = (new ‪TransportFactory())->get($mailSettings);
91  $this->assertInstanceOf(\Swift_SpoolTransport::class, $transport);
92 
94  $spool = $transport->getSpool();
95  $this->assertInstanceOf(\Swift_MemorySpool::class, $spool);
96  }
97 
102  {
103  $mailSettings = [
104  'transport' => 'mail',
105  'transport_smtp_server' => 'localhost:25',
106  'transport_smtp_encrypt' => '',
107  'transport_smtp_username' => '',
108  'transport_smtp_password' => '',
109  'transport_sendmail_command' => '',
110  'transport_mbox_file' => '',
111  'defaultMailFromAddress' => '',
112  'defaultMailFromName' => '',
113  'transport_spool_type' => FakeValidSpoolFixture::class,
114  'transport_spool_filepath' => ‪Environment::getVarPath() . '/messages/',
115  ];
116 
117  $transport = (new ‪TransportFactory())->get($mailSettings);
118  $this->assertInstanceOf(\Swift_SpoolTransport::class, $transport);
119 
121  $spool = $transport->getSpool();
122  $this->assertInstanceOf(Fixtures\FakeValidSpoolFixture::class, $spool);
123 
124  $this->assertSame($mailSettings, $spool->getSettings());
125  }
126 
131  {
132  $this->expectException(\RuntimeException::class);
133  $this->expectExceptionCode(1466799482);
134 
135  $mailSettings = [
136  'transport' => 'mail',
137  'transport_smtp_server' => 'localhost:25',
138  'transport_smtp_encrypt' => '',
139  'transport_smtp_username' => '',
140  'transport_smtp_password' => '',
141  'transport_sendmail_command' => '',
142  'transport_mbox_file' => '',
143  'defaultMailFromAddress' => '',
144  'defaultMailFromName' => '',
145  'transport_spool_type' => FakeInvalidSpoolFixture::class,
146  'transport_spool_filepath' => ‪Environment::getVarPath() . '/messages/',
147  ];
148 
149  (new ‪TransportFactory())->get($mailSettings);
150  }
151 
155  public function ‪getReturnsSwiftMailTransport(): void
156  {
157  $mailSettings = [
158  'transport' => 'mail',
159  'transport_smtp_server' => 'localhost:25',
160  'transport_smtp_encrypt' => '',
161  'transport_smtp_username' => '',
162  'transport_smtp_password' => '',
163  'transport_sendmail_command' => '',
164  'transport_mbox_file' => '',
165  'defaultMailFromAddress' => '',
166  'defaultMailFromName' => '',
167  'transport_spool_type' => '',
168  'transport_spool_filepath' => ‪Environment::getVarPath() . '/messages/',
169  ];
170 
171  $transport = (new ‪TransportFactory())->get($mailSettings);
172  $this->assertInstanceOf(\Swift_MailTransport::class, $transport);
173  }
174 }
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: TransportFactoryTest.php:32
‪TYPO3\CMS\Core\Mail\MemorySpool
Definition: MemorySpool.php:37
‪TYPO3\CMS\Core\Tests\Unit\Mail
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\getThrowsRuntimeExceptionForInvalidCustomSpool
‪getThrowsRuntimeExceptionForInvalidCustomSpool()
Definition: TransportFactoryTest.php:129
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\getReturnsSwiftSpoolTransportUsingSwiftMemorySpool
‪getReturnsSwiftSpoolTransportUsingSwiftMemorySpool()
Definition: TransportFactoryTest.php:70
‪TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeInvalidSpoolFixture
Definition: FakeInvalidSpoolFixture.php:21
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\getReturnsSwiftSpoolTransportUsingCustomSpool
‪getReturnsSwiftSpoolTransportUsingCustomSpool()
Definition: TransportFactoryTest.php:100
‪TYPO3\CMS\Core\Tests\Unit\Mail\Fixtures\FakeValidSpoolFixture
Definition: FakeValidSpoolFixture.php:21
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\getReturnsSwiftSpoolTransportUsingSwiftFileSpool
‪getReturnsSwiftSpoolTransportUsingSwiftFileSpool()
Definition: TransportFactoryTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest\getReturnsSwiftMailTransport
‪getReturnsSwiftMailTransport()
Definition: TransportFactoryTest.php:154
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165
‪TYPO3\CMS\Core\Tests\Unit\Mail\TransportFactoryTest
Definition: TransportFactoryTest.php:29
‪TYPO3\CMS\Core\Mail\TransportFactory
Definition: TransportFactory.php:26