‪TYPO3CMS  11.5
UrlSoftReferenceParserTest.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 url matches' => [
26  'https://foo-bar.baz',
27  [
28  'content' => 'https://foo-bar.baz',
29  'elements' => [
30  2 => [
31  'matchString' => 'https://foo-bar.baz',
32  ],
33  ],
34  ],
35  ],
36  'Valid characters by RFC 3986 match' => [
37  'http://ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&\'()*+,;=.foo',
38  [
39  'content' => 'http://ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&\'()*+,;=.foo',
40  'elements' => [
41  2 => [
42  'matchString' => 'http://ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&\'()*+,;=.foo',
43  ],
44  ],
45  ],
46  ],
47  'URLs in content match' => [
48  'Lorem ipsum https://foo-bar.baz dolor sit',
49  [
50  'content' => 'Lorem ipsum https://foo-bar.baz dolor sit',
51  'elements' => [
52  2 => [
53  'matchString' => 'https://foo-bar.baz',
54  ],
55  ],
56  ],
57  ],
58  'FTP URLs match' => [
59  'ftp://foo-bar.baz',
60  [
61  'content' => 'ftp://foo-bar.baz',
62  'elements' => [
63  2 => [
64  'matchString' => 'ftp://foo-bar.baz',
65  ],
66  ],
67  ],
68  ],
69  'Full URLs match' => [
70  'https://foo-bar.baz?foo=bar&baz=fizz#anchor',
71  [
72  'content' => 'https://foo-bar.baz?foo=bar&baz=fizz#anchor',
73  'elements' => [
74  2 => [
75  'matchString' => 'https://foo-bar.baz?foo=bar&baz=fizz#anchor',
76  ],
77  ],
78  ],
79  ],
80  'URL encoded URLs match' => [
81  'https://foo-bar.baz?foo%3Dbar%26baz%3Dfi%20zz%23anchor',
82  [
83  'content' => 'https://foo-bar.baz?foo%3Dbar%26baz%3Dfi%20zz%23anchor',
84  'elements' => [
85  2 => [
86  'matchString' => 'https://foo-bar.baz?foo%3Dbar%26baz%3Dfi%20zz%23anchor',
87  ],
88  ],
89  ],
90  ],
91  'No space character after the last URL matches' => [
92  '<p>Lorem Ipsum<br> https://foo.bar.baz/abc/def/ghi/.</p>',
93  [
94  'content' => '<p>Lorem Ipsum<br> https://foo.bar.baz/abc/def/ghi/.</p>',
95  'elements' => [
96  2 => [
97  'matchString' => 'https://foo.bar.baz/abc/def/ghi/.',
98  ],
99  ],
100  ],
101  ],
102  // The two cases below are handled by typolink_tag
103  'URLs in anchor tag attributes do NOT match' => [
104  '<a href="https://foo-bar.baz">some link</a>',
105  null,
106  ],
107  'URLs in link tag attributes do NOT match' => [
108  '<link href="https://foo-bar.baz/style.css" rel="stylesheet">',
109  null,
110  ],
111  ];
112  }
113 
118  public function ‪urlSoftReferenceParserTest(string $content, ?array $expected): void
119  {
120  $subject = $this->‪getParserByKey('url');
121  $result = $subject->parse('pages', 'url', 1, $content)->toNullableArray();
122  self::assertSame($expected, $result);
123  }
124 
129  {
130  $content = 'My website is: https://www.foo-bar.baz';
131  $subject = $this->‪getParserByKey('url');
132  $subject->setParserKey('url', ['subst']);
133  $result = $subject->parse('pages', 'url', 1, $content)->toNullableArray();
134  self::assertArrayHasKey('subst', $result['elements'][2]);
135  self::assertArrayHasKey('tokenID', $result['elements'][2]['subst']);
136  unset($result['elements'][2]['subst']['tokenID']);
137 
138  $expected = [
139  2 => [
140  'matchString' => 'https://www.foo-bar.baz',
141  'subst' => [
142  'type' => 'string',
143  'tokenValue' => 'https://www.foo-bar.baz',
144  ],
145  ],
146  ];
147  self::assertSame($expected, $result['elements']);
148  }
149 }
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\UrlSoftReferenceParserTest\urlSoftReferenceParserSubstituteTest
‪urlSoftReferenceParserSubstituteTest()
Definition: UrlSoftReferenceParserTest.php:128
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\UrlSoftReferenceParserTest
Definition: UrlSoftReferenceParserTest.php:21
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference
Definition: AbstractSoftReferenceParserTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\UrlSoftReferenceParserTest\urlSoftReferenceParserTest
‪urlSoftReferenceParserTest(string $content, ?array $expected)
Definition: UrlSoftReferenceParserTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\DataHandling\SoftReference\UrlSoftReferenceParserTest\urlSoftReferenceParserTestDataProvider
‪urlSoftReferenceParserTestDataProvider()
Definition: UrlSoftReferenceParserTest.php:22
‪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