‪TYPO3CMS  11.5
MailUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪MailUtilityTest extends UnitTestCase
27 {
31  protected ‪$resetSingletonInstances = true;
32 
37  {
38  self::assertEmpty(‪MailUtility::breakLinesForEmail(''));
39  }
40 
45  {
46  $newlineChar = LF;
47  $lineWidth = 76;
48  $str = 'This text is not longer than 76 chars and therefore will not be broken.';
49  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
50  self::assertCount(1, explode($newlineChar, $returnString));
51  }
52 
57  {
58  $newlineChar = LF;
59  $lineWidth = 50;
60  $str = 'This text is longer than 50 chars and therefore will be broken.';
61  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
62  self::assertCount(2, explode($newlineChar, $returnString));
63  }
64 
69  {
70  $newlineChar = LF;
71  $lineWidth = 10;
72  // first space after 20 chars (more than $lineWidth)
73  $str = 'abcdefghijklmnopqrst uvwxyz 123456';
74  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
75  self::assertEquals($returnString, 'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456');
76  }
77 
82  {
83  $str = 'Mein Link auf eine News (Link: http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)';
84  $returnString = ‪MailUtility::breakLinesForEmail($str);
85  self::assertEquals($returnString, 'Mein Link auf eine News (Link:' . LF . 'http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)');
86  }
87 
93  public function ‪parseAddressesProvider(): array
94  {
95  return [
96  'name &ltemail&gt;' => ['name <email@example.org>', ['email@example.org' => 'name']],
97  '&lt;email&gt;' => ['<email@example.org>', ['email@example.org']],
98  '@localhost' => ['@localhost', []],
99  '000@example.com' => ['000@example.com', ['000@example.com']],
100  'email' => ['email@example.org', ['email@example.org']],
101  'email1,email2' => ['email1@example.org,email2@example.com', ['email1@example.org', 'email2@example.com']],
102  'name &ltemail&gt;,email2' => ['name <email1@example.org>,email2@example.com', ['email1@example.org' => 'name', 'email2@example.com']],
103  '"last, first" &lt;name@example.org&gt;' => ['"last, first" <email@example.org>', ['email@example.org' => '"last, first"']],
104  'email,name &ltemail&gt;,"last, first" &lt;name@example.org&gt;' => [
105  'email1@example.org, name <email2@example.org>, "last, first" <email3@example.org>',
106  [
107  'email1@example.org',
108  'email2@example.org' => 'name',
109  'email3@example.org' => '"last, first"',
110  ],
111  ],
112  ];
113  }
114 
119  public function ‪parseAddressesTest($source, $addressList): void
120  {
121  $returnArray = ‪MailUtility::parseAddresses($source);
122  self::assertEquals($addressList, $returnArray);
123  }
124 
128  public function ‪replyToProvider(): array
129  {
130  return [
131  'only address' => [
132  ['defaultMailReplyToAddress' => 'noreply@example.org', 'defaultMailReplyToName' => ''],
133  ['noreply@example.org'],
134  ],
135  'name and address' => [
136  ['defaultMailReplyToAddress' => 'noreply@example.org', 'defaultMailReplyToName' => 'John Doe'],
137  ['noreply@example.org' => 'John Doe'],
138  ],
139  'no address' => [
140  ['defaultMailReplyToAddress' => '', 'defaultMailReplyToName' => ''],
141  [],
142  ],
143  'invalid address' => [
144  ['defaultMailReplyToAddress' => 'foo', 'defaultMailReplyToName' => ''],
145  [],
146  ],
147  ];
148  }
149 
156  public function ‪getSystemReplyToTest(array $configuration, array $expectedReplyTo): void
157  {
158  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $configuration;
159  $returnArray = MailUtility::getSystemReplyTo();
160  self::assertSame($expectedReplyTo, $returnArray);
161  }
162 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\replyToProvider
‪array replyToProvider()
Definition: MailUtilityTest.php:127
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextIfCharWithIsExceeded
‪breakLinesForEmailBreaksTextIfCharWithIsExceeded()
Definition: MailUtilityTest.php:55
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: MailUtilityTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\parseAddressesTest
‪parseAddressesTest($source, $addressList)
Definition: MailUtilityTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\parseAddressesProvider
‪array parseAddressesProvider()
Definition: MailUtilityTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailReturnsOneLineIfCharWithIsNotExceeded
‪breakLinesForEmailReturnsOneLineIfCharWithIsNotExceeded()
Definition: MailUtilityTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest
Definition: MailUtilityTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\getSystemReplyToTest
‪getSystemReplyToTest(array $configuration, array $expectedReplyTo)
Definition: MailUtilityTest.php:155
‪TYPO3\CMS\Core\Utility\MailUtility\parseAddresses
‪static array parseAddresses($rawAddresses)
Definition: MailUtility.php:182
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextWithNoSpaceFoundBeforeLimit
‪breakLinesForEmailBreaksTextWithNoSpaceFoundBeforeLimit()
Definition: MailUtilityTest.php:67
‪TYPO3\CMS\Core\Utility\MailUtility
Definition: MailUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailReturnsEmptyStringIfEmptyStringIsGiven
‪breakLinesForEmailReturnsEmptyStringIfEmptyStringIsGiven()
Definition: MailUtilityTest.php:35
‪TYPO3\CMS\Core\Utility\MailUtility\breakLinesForEmail
‪static string breakLinesForEmail($str, $newlineChar=LF, $lineWidth=76)
Definition: MailUtility.php:132
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextIfLineIsLongerThanTheLineWidth
‪breakLinesForEmailBreaksTextIfLineIsLongerThanTheLineWidth()
Definition: MailUtilityTest.php:80