‪TYPO3CMS  10.4
MailUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪MailUtilityTest extends UnitTestCase
25 {
29  protected ‪$resetSingletonInstances = true;
30 
35  {
36  self::assertEmpty(‪MailUtility::breakLinesForEmail(''));
37  }
38 
43  {
44  $newlineChar = LF;
45  $lineWidth = 76;
46  $str = 'This text is not longer than 76 chars and therefore will not be broken.';
47  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
48  self::assertEquals(1, count(explode($newlineChar, $returnString)));
49  }
50 
55  {
56  $newlineChar = LF;
57  $lineWidth = 50;
58  $str = 'This text is longer than 50 chars and therefore will be broken.';
59  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
60  self::assertEquals(2, count(explode($newlineChar, $returnString)));
61  }
62 
67  {
68  $newlineChar = LF;
69  $lineWidth = 10;
70  // first space after 20 chars (more than $lineWidth)
71  $str = 'abcdefghijklmnopqrst uvwxyz 123456';
72  $returnString = ‪MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
73  self::assertEquals($returnString, 'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456');
74  }
75 
80  {
81  $str = 'Mein Link auf eine News (Link: http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)';
82  $returnString = ‪MailUtility::breakLinesForEmail($str);
83  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)');
84  }
85 
91  public function ‪parseAddressesProvider()
92  {
93  return [
94  'name &ltemail&gt;' => ['name <email@example.org>', ['email@example.org' => 'name']],
95  '&lt;email&gt;' => ['<email@example.org>', ['email@example.org']],
96  '@localhost' => ['@localhost', []],
97  '000@example.com' => ['000@example.com', ['000@example.com']],
98  'email' => ['email@example.org', ['email@example.org']],
99  'email1,email2' => ['email1@example.org,email2@example.com', ['email1@example.org', 'email2@example.com']],
100  'name &ltemail&gt;,email2' => ['name <email1@example.org>,email2@example.com', ['email1@example.org' => 'name', 'email2@example.com']],
101  '"last, first" &lt;name@example.org&gt;' => ['"last, first" <email@example.org>', ['email@example.org' => '"last, first"']],
102  'email,name &ltemail&gt;,"last, first" &lt;name@example.org&gt;' => [
103  'email1@example.org, name <email2@example.org>, "last, first" <email3@example.org>',
104  [
105  'email1@example.org',
106  'email2@example.org' => 'name',
107  'email3@example.org' => '"last, first"'
108  ]
109  ]
110  ];
111  }
112 
117  public function ‪parseAddressesTest($source, $addressList)
118  {
119  $returnArray = ‪MailUtility::parseAddresses($source);
120  self::assertEquals($addressList, $returnArray);
121  }
122 
126  public function ‪replyToProvider(): array
127  {
128  return [
129  'only address' => [
130  ['defaultMailReplyToAddress' => 'noreply@example.org', 'defaultMailReplyToName' => ''],
131  ['noreply@example.org'],
132  ],
133  'name and address' => [
134  ['defaultMailReplyToAddress' => 'noreply@example.org', 'defaultMailReplyToName' => 'John Doe'],
135  ['noreply@example.org' => 'John Doe'],
136  ],
137  'no address' => [
138  ['defaultMailReplyToAddress' => '', 'defaultMailReplyToName' => ''],
139  [],
140  ],
141  'invalid address' => [
142  ['defaultMailReplyToAddress' => 'foo', 'defaultMailReplyToName' => ''],
143  [],
144  ],
145  ];
146  }
147 
154  public function ‪getSystemReplyToTest(array $configuration, array $expectedReplyTo)
155  {
156  ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $configuration;
157  $returnArray = ‪MailUtility::getSystemReplyTo();
158  self::assertSame($expectedReplyTo, $returnArray);
159  }
160 }
‪TYPO3\CMS\Core\Utility\MailUtility\getSystemReplyTo
‪static array getSystemReplyTo()
Definition: MailUtility.php:95
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\replyToProvider
‪array replyToProvider()
Definition: MailUtilityTest.php:125
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextIfCharWithIsExceeded
‪breakLinesForEmailBreaksTextIfCharWithIsExceeded()
Definition: MailUtilityTest.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: MailUtilityTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\parseAddressesTest
‪parseAddressesTest($source, $addressList)
Definition: MailUtilityTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\parseAddressesProvider
‪array parseAddressesProvider()
Definition: MailUtilityTest.php:90
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailReturnsOneLineIfCharWithIsNotExceeded
‪breakLinesForEmailReturnsOneLineIfCharWithIsNotExceeded()
Definition: MailUtilityTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest
Definition: MailUtilityTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\getSystemReplyToTest
‪getSystemReplyToTest(array $configuration, array $expectedReplyTo)
Definition: MailUtilityTest.php:153
‪TYPO3\CMS\Core\Utility\MailUtility\parseAddresses
‪static array parseAddresses($rawAddresses)
Definition: MailUtility.php:171
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextWithNoSpaceFoundBeforeLimit
‪breakLinesForEmailBreaksTextWithNoSpaceFoundBeforeLimit()
Definition: MailUtilityTest.php:65
‪TYPO3\CMS\Core\Utility\MailUtility
Definition: MailUtility.php:24
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailReturnsEmptyStringIfEmptyStringIsGiven
‪breakLinesForEmailReturnsEmptyStringIfEmptyStringIsGiven()
Definition: MailUtilityTest.php:33
‪TYPO3\CMS\Core\Utility\MailUtility\breakLinesForEmail
‪static string breakLinesForEmail($str, $newlineChar=LF, $lineWidth=76)
Definition: MailUtility.php:121
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\Utility\MailUtilityTest\breakLinesForEmailBreaksTextIfLineIsLongerThanTheLineWidth
‪breakLinesForEmailBreaksTextIfLineIsLongerThanTheLineWidth()
Definition: MailUtilityTest.php:78