‪TYPO3CMS  ‪main
UrlLinkHandlerTest.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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪UrlLinkHandlerTest extends UnitTestCase
27 {
31  public static function ‪resolveParametersForNonFilesDataProvider(): array
32  {
33  return [
34  'URL without a scheme' => [
35  [
36  'url' => 'www.have.you/ever?did=this',
37  ],
38  [
39  'url' => 'http://www.have.you/ever?did=this',
40  ],
41  'http://www.have.you/ever?did=this',
42  ],
43  'http URL' => [
44  [
45  'url' => 'http://www.have.you/ever?did=this',
46  ],
47  [
48  'url' => 'http://www.have.you/ever?did=this',
49  ],
50  'http://www.have.you/ever?did=this',
51  ],
52  'https URL' => [
53  [
54  'url' => 'https://www.have.you/ever?did=this',
55  ],
56  [
57  'url' => 'https://www.have.you/ever?did=this',
58  ],
59  'https://www.have.you/ever?did=this',
60  ],
61  'https URL with port' => [
62  [
63  'url' => 'https://www.have.you:8088/ever?did=this',
64  ],
65  [
66  'url' => 'https://www.have.you:8088/ever?did=this',
67  ],
68  'https://www.have.you:8088/ever?did=this',
69  ],
70  'ftp URL' => [
71  [
72  'url' => 'ftp://www.have.you/ever?did=this',
73  ],
74  [
75  'url' => 'ftp://www.have.you/ever?did=this',
76  ],
77  'ftp://www.have.you/ever?did=this',
78  ],
79  'afp URL' => [
80  [
81  'url' => 'afp://www.have.you/ever?did=this',
82  ],
83  [
84  'url' => 'afp://www.have.you/ever?did=this',
85  ],
86  'afp://www.have.you/ever?did=this',
87  ],
88  'sftp URL' => [
89  [
90  'url' => 'sftp://nice:andsecret@www.have.you:23/ever?did=this',
91  ],
92  [
93  'url' => 'sftp://nice:andsecret@www.have.you:23/ever?did=this',
94  ],
95  'sftp://nice:andsecret@www.have.you:23/ever?did=this',
96  ],
97  'tel URL' => [
98  ['url' => 'tel:+1-2345-6789'],
99  ['url' => 'tel:+1-2345-6789'],
100  'tel:+1-2345-6789',
101  ],
102  'URL without scheme with host' => [
103  ['url' => 'www.example.com'],
104  ['url' => 'http://www.example.com'],
105  'http://www.example.com',
106  ],
107  'URL without scheme with host and path' => [
108  ['url' => 'www.example.com/my-products'],
109  ['url' => 'http://www.example.com/my-products'],
110  'http://www.example.com/my-products',
111  ],
112  'URL without scheme without host and path' => [
113  ['url' => '/my-products'],
114  ['url' => '/my-products'],
115  '/my-products',
116  ],
117  'URL that could be a host or a relative path' => [
118  ['url' => 'my-products.com'],
119  ['url' => 'http://my-products.com'],
120  'http://my-products.com',
121  ],
122  'URL that could be a host or an absolute path' => [
123  ['url' => '/www.my-products.com'],
124  ['url' => '/www.my-products.com'],
125  '/www.my-products.com',
126  ],
127  'javascript URL (denied)' => [
128  ['url' => 'javascript:alert(\'XSS\')'],
129  ['url' => ''],
130  '',
131  ],
132  'data URL (denied)' => [
133  ['url' => 'data:text/html;base64,SGVsbG8sIFdvcmxkIQ%3D%3D'],
134  ['url' => ''],
135  '',
136  ],
137  ];
138  }
139 
140  #[DataProvider('resolveParametersForNonFilesDataProvider')]
141  #[Test]
142  public function ‪resolveReturnsSplitParameters(array $input, array $expected, string $finalString): void
143  {
144  $subject = new ‪UrlLinkHandler();
145  self::assertEquals($expected, $subject->resolveHandlerData($input));
146  }
147 
148  #[DataProvider('resolveParametersForNonFilesDataProvider')]
149  #[Test]
150  public function ‪splitParametersToUnifiedIdentifier(array $input, array $parameters, string $expected): void
151  {
152  $subject = new ‪UrlLinkHandler();
153  self::assertEquals($expected, $subject->asString($parameters));
154  }
155 
156  #[Test]
158  {
159  unset(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultScheme']);
160 
162 
163  self::assertSame(‪LinkHandlingInterface::DEFAULT_SCHEME, $result);
164  }
165 
166  #[Test]
168  {
169  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultScheme'] = '';
170 
172 
173  self::assertSame(‪LinkHandlingInterface::DEFAULT_SCHEME, $result);
174  }
175 
176  #[Test]
178  {
179  $scheme = 'https';
180  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultScheme'] = $scheme;
181 
183 
184  self::assertSame($scheme, $result);
185  }
186 }
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25