‪TYPO3CMS  11.5
EmailSoftReferenceParserTest.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 {
23  {
24  return [
25  'Simple email address found' => [
26  'foo@bar.baz',
27  [
28  'content' => 'foo@bar.baz',
29  'elements' => [
30  2 => [
31  'matchString' => 'foo@bar.baz',
32  ],
33  ],
34  ],
35  ],
36  'Multiple email addresses found' => [
37  'This is my first email: foo@bar.baz and this is my second email: foo-_2@bar.baz',
38  [
39  'content' => 'This is my first email: foo@bar.baz and this is my second email: foo-_2@bar.baz',
40  'elements' => [
41  2 => [
42  'matchString' => 'foo@bar.baz',
43  ],
44  5 => [
45  'matchString' => 'foo-_2@bar.baz',
46  ],
47  ],
48  ],
49  ],
50  'Invalid emails are ignored' => [
51  'abc-@mail.com
52  abc..def@mail.com
53  .abc@mail.com
54  abc#def@mail.com
55  abc.def@mail.c
56  abc.def@mail#archive.com
57  abc.def@mail
58  abc.def@mail..com',
59  null,
60  ],
61  'E-Mails in html match' => [
62  '<a href="mailto:foo@bar.de">foo@bar.baz</a>',
63  [
64  'content' => '<a href="mailto:foo@bar.de">foo@bar.baz</a>',
65  'elements' => [
66  2 => [
67  'matchString' => 'foo@bar.de',
68  ],
69  5 => [
70  'matchString' => 'foo@bar.baz',
71  ],
72  ],
73  ],
74  ],
75  ];
76  }
77 
82  public function ‪emailSoftReferenceParserTest(string $content, ?array $expected): void
83  {
84  $subject = $this->‪getParserByKey('email');
85  $result = $subject->parse('be_users', 'email', 1, $content)->toNullableArray();
86  self::assertSame($expected, $result);
87  }
88 
93  {
94  $content = 'My email is: foo@bar.baz';
95  $subject = $this->‪getParserByKey('email');
96  $subject->setParserKey('email', ['subst']);
97  $result = $subject->parse('be_users', 'email', 1, $content)->toNullableArray();
98  self::assertArrayHasKey('subst', $result['elements'][2]);
99  self::assertArrayHasKey('tokenID', $result['elements'][2]['subst']);
100  unset($result['elements'][2]['subst']['tokenID']);
101 
102  $expected = [
103  2 => [
104  'matchString' => 'foo@bar.baz',
105  'subst' => [
106  'type' => 'string',
107  'tokenValue' => 'foo@bar.baz',
108  ],
109  ],
110  ];
111  self::assertSame($expected, $result['elements']);
112  }
113 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\EmailSoftReferenceParserTest
Definition: EmailSoftReferenceParserTest.php:21
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\EmailSoftReferenceParserTest\emailSoftReferenceParserTestDataProvider
‪emailSoftReferenceParserTestDataProvider()
Definition: EmailSoftReferenceParserTest.php:22
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\EmailSoftReferenceParserTest\emailSoftReferenceParserSubstituteTest
‪emailSoftReferenceParserSubstituteTest()
Definition: EmailSoftReferenceParserTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\EmailSoftReferenceParserTest\emailSoftReferenceParserTest
‪emailSoftReferenceParserTest(string $content, ?array $expected)
Definition: EmailSoftReferenceParserTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference
Definition: AbstractSoftReferenceParserTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\AbstractSoftReferenceParserTest
Definition: AbstractSoftReferenceParserTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\AbstractSoftReferenceParserTest\getParserByKey
‪getParserByKey($softrefKey)
Definition: AbstractSoftReferenceParserTest.php:43