[TASK] Unit test for t3lib_utility_Mail should check From user
authorXavier Perseguers <xavier@typo3.org>
Mon, 24 Oct 2011 15:07:10 +0000 (17:07 +0200)
committerXavier Perseguers <xavier@typo3.org>
Mon, 24 Oct 2011 19:40:02 +0000 (21:40 +0200)
Unit tests t3lib_utility_Mail do not test if additional headers are generated
when $TYPO3_CONF_VARS['MAIL']['defaultMailFromAddress'] and
$TYPO3_CONF_VARS['MAIL']['defaultMailFromName'] are set.

Change-Id: I437181b5c6b08d789ebd0236ffb6ab2745f3badc
Resolves: #31228
Releases: 4.6
Reviewed-on: http://review.typo3.org/6243
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
tests/t3lib/utility/class.t3lib_utility_mailTest.php

index c08f4d1..c80019f 100644 (file)
@@ -64,12 +64,37 @@ class t3lib_utility_MailTest extends tx_phpunit_testcase {
         * @test
         */
        public function mailCallsHook() {
+               $this->doMailCallsHook();
+       }
+
+       /**
+        * @test
+        */
+       public function mailCallsHookWithDefaultMailFrom() {
+               $this->doMailCallsHook('no-reply@localhost', 'TYPO3 Mailer');
+       }
+
+       /**
+        * Method called from tests mailCallsHook() and mailCallsHookWithDefaultMailFrom().
+        */
+       protected function doMailCallsHook($fromAddress = '', $fromName = '') {
+                       // Backup configuration
+               $mailConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
+
+               $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = $fromAddress;
+               $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = $fromName;
+
                $to = 'john@example.com';
                $subject = 'Good news everybody!';
                $messageBody = 'The hooks works!';
                $additionalHeaders = 'Reply-to: jane@example.com';
                $additionalParameters = '-f postmaster@example.com';
 
+               $additionalHeadersExpected = $additionalHeaders;
+               if ($fromAddress !== '' && $fromName !== '') {
+                       $additionalHeadersExpected .= LF . sprintf('From: "%s" <%s>', $fromName, $fromAddress);
+               }
+
                $mockMailer = $this->getMock('mockMailer', array('mail'));
                $mockMailer->expects($this->once())->method('mail')
                        ->with(
@@ -77,7 +102,7 @@ class t3lib_utility_MailTest extends tx_phpunit_testcase {
                                        'to' => $to,
                                        'subject' => $subject,
                                        'messageBody' => $messageBody,
-                                       'additionalHeaders' => $additionalHeaders,
+                                       'additionalHeaders' => $additionalHeadersExpected,
                                        'additionalParameters' => $additionalParameters,
                                ),
                                FALSE
@@ -93,6 +118,9 @@ class t3lib_utility_MailTest extends tx_phpunit_testcase {
                        $to, $subject, $messageBody, $additionalHeaders,
                        $additionalParameters
                );
+
+                       // Restore configuration
+               $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $mailConfigurationBackup;
        }
 
     /**