TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $singletonInstances = [];
26 
27  protected function setUp()
28  {
30  }
31 
32  protected function tearDown()
33  {
35  parent::tearDown();
36  }
37 
42  {
43  $this->assertEmpty(\TYPO3\CMS\Core\Utility\MailUtility::breakLinesForEmail(''));
44  }
45 
50  {
51  $newlineChar = LF;
52  $lineWidth = 76;
53  $str = 'This text is not longer than 76 chars and therefore will not be broken.';
54  $returnString = \TYPO3\CMS\Core\Utility\MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
55  $this->assertEquals(1, count(explode($newlineChar, $returnString)));
56  }
57 
62  {
63  $newlineChar = LF;
64  $lineWidth = 50;
65  $str = 'This text is longer than 50 chars and therefore will be broken.';
66  $returnString = \TYPO3\CMS\Core\Utility\MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
67  $this->assertEquals(2, count(explode($newlineChar, $returnString)));
68  }
69 
74  {
75  $newlineChar = LF;
76  $lineWidth = 10;
77  // first space after 20 chars (more than $lineWidth)
78  $str = 'abcdefghijklmnopqrst uvwxyz 123456';
79  $returnString = \TYPO3\CMS\Core\Utility\MailUtility::breakLinesForEmail($str, $newlineChar, $lineWidth);
80  $this->assertEquals($returnString, 'abcdefghijklmnopqrst' . LF . 'uvwxyz' . LF . '123456');
81  }
82 
87  {
88  $str = 'Mein Link auf eine News (Link: http://zzzzzzzzzzzzz.xxxxxxxxx.de/index.php?id=10&tx_ttnews%5Btt_news%5D=1&cHash=66f5af320da29b7ae1cda49047ca7358)';
90  $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)');
91  }
92 
98  public function parseAddressesProvider()
99  {
100  return [
101  'name &ltemail&gt;' => ['name <email@example.org>', ['email@example.org' => 'name']],
102  '&lt;email&gt;' => ['<email@example.org>', ['email@example.org']],
103  '@localhost' => ['@localhost', []],
104  '000@example.com' => ['000@example.com', ['000@example.com']],
105  'email' => ['email@example.org', ['email@example.org']],
106  'email1,email2' => ['email1@example.org,email2@example.com', ['email1@example.org', 'email2@example.com']],
107  'name &ltemail&gt;,email2' => ['name <email1@example.org>,email2@example.com', ['email1@example.org' => 'name', 'email2@example.com']],
108  '"last, first" &lt;name@example.org&gt;' => ['"last, first" <email@example.org>', ['email@example.org' => '"last, first"']],
109  'email,name &ltemail&gt;,"last, first" &lt;name@example.org&gt;' => [
110  'email1@example.org, name <email2@example.org>, "last, first" <email3@example.org>',
111  [
112  'email1@example.org',
113  'email2@example.org' => 'name',
114  'email3@example.org' => '"last, first"'
115  ]
116  ]
117  ];
118  }
119 
124  public function parseAddressesTest($source, $addressList)
125  {
126  $returnArray = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($source);
127  $this->assertEquals($addressList, $returnArray);
128  }
129 }
static breakLinesForEmail($str, $newlineChar=LF, $lineWidth=76)
static resetSingletonInstances(array $newSingletonInstances)