[BUGFIX] Faulty check for missing SMTP port 04/23504/5
authorTomita Militaru <militarutomita@gmail.com>
Sat, 31 Aug 2013 07:56:41 +0000 (10:56 +0300)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 31 Aug 2013 22:08:46 +0000 (00:08 +0200)
Check also for null port to avoid a fatal error.

Resolves: #31998
Releases: 6.2, 6.1, 6.0, 4.7, 4.5
Change-Id: Ibf45b3c0783a70e5afba33f90d1d8e05f76834cf
Reviewed-on: https://review.typo3.org/23504
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Mail/Mailer.php
typo3/sysext/core/Tests/Unit/Mail/MailerTest.php

index 3dfe4e7..b1180e8 100644 (file)
@@ -97,7 +97,7 @@ class Mailer extends \Swift_Mailer {
                                if ($host === '') {
                                        throw new \TYPO3\CMS\Core\Exception('$TYPO3_CONF_VARS[\'MAIL\'][\'transport_smtp_server\'] needs to be set when transport is set to "smtp"', 1291068606);
                                }
-                               if ($port === '') {
+                               if ($port === NULL || $port === '') {
                                        $port = '25';
                                }
                                $useEncryption = $this->mailSettings['transport_smtp_encrypt'] ? $this->mailSettings['transport_smtp_encrypt'] : NULL;
index 7391773..93d7d34 100644 (file)
@@ -113,6 +113,35 @@ class MailerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->fixture->__construct();
        }
 
+       /**
+        * @test
+        */
+       public function noPortSettingSetsPortTo25() {
+               $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost'));
+               $this->fixture->__construct();
+               $port = $this->fixture->getTransport()->getPort();
+               $this->assertEquals(25, $port);
+       }
+
+       /**
+        * @test
+        */
+       public function emptyPortSettingSetsPortTo25() {
+               $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:'));
+               $this->fixture->__construct();
+               $port = $this->fixture->getTransport()->getPort();
+               $this->assertEquals(25, $port);
+       }
+
+       /**
+        * @test
+        */
+       public function givenPortSettingIsRespected() {
+               $this->fixture->injectMailSettings(array('transport' => 'smtp', 'transport_smtp_server' => 'localhost:12345'));
+               $this->fixture->__construct();
+               $port = $this->fixture->getTransport()->getPort();
+               $this->assertEquals(12345, $port);
+       }
 }
 
 ?>
\ No newline at end of file