3 namespace Drupal\Tests\Component\Utility;
5 use Drupal\Component\Utility\Mail;
6 use PHPUnit\Framework\TestCase;
9 * Test mail helpers implemented in Mail component.
13 * @coversDefaultClass \Drupal\Component\Utility\Mail
15 class MailTest extends TestCase {
18 * Tests RFC-2822 'display-name' formatter.
20 * @dataProvider providerTestDisplayName
21 * @covers ::formatDisplayName
23 public function testFormatDisplayName($string, $safe_display_name) {
24 $this->assertEquals($safe_display_name, Mail::formatDisplayName($string));
28 * Data provider for testFormatDisplayName().
30 * @see testFormatDisplayName()
33 * An array containing a string and its 'display-name' safe value.
35 public function providerTestDisplayName() {
37 // Simple ASCII characters.
38 ['Test site', 'Test site'],
39 // ASCII with html entity.
40 ['Test & site', 'Test & site'],
41 // Non-ASCII characters.
42 ['Tést site', '=?UTF-8?B?VMOpc3Qgc2l0ZQ==?='],
43 // Non-ASCII with special characters.
44 ['Tést; site', '=?UTF-8?B?VMOpc3Q7IHNpdGU=?='],
45 // Non-ASCII with html entity.
46 ['Tést; site', '=?UTF-8?B?VMOpc3Q7IHNpdGU=?='],
47 // ASCII with special characters.
48 ['Test; site', '"Test; site"'],
49 // ASCII with special characters as html entity.
50 ['Test < site', '"Test < site"'],
51 // ASCII with special characters and '\'.
52 ['Test; \ "site"', '"Test; \\\\ \"site\""'],
53 // String already RFC-2822 compliant.
54 ['"Test; site"', '"Test; site"'],
55 // String already RFC-2822 compliant.
56 ['"Test; \\\\ \"site\""', '"Test; \\\\ \"site\""'],