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