[TASK] Make LinkServiceTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / LinkHandling / LinkServiceTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\LinkHandling;
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
18 use TYPO3\CMS\Core\LinkHandling\LinkService;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 class LinkServiceTest extends UnitTestCase
22 {
23 /**
24 * Data to resolve strings to arrays and vice versa, external, mail, page
25 *
26 * @return array
27 */
28 public function resolveParametersForNonFilesDataProvider()
29 {
30 return [
31 'simple page - old style' => [
32 // original input value
33 '13',
34 // splitted values
35 [
36 'type' => LinkService::TYPE_PAGE,
37 'pageuid' => 13
38 ],
39 // final unified URN
40 't3://page?uid=13'
41 ],
42 'page with type - old style' => [
43 '13,31',
44 [
45 'type' => LinkService::TYPE_PAGE,
46 'pageuid' => 13,
47 'pagetype' => 31
48 ],
49 't3://page?uid=13&type=31'
50 ],
51 'page with type and fragment - old style' => [
52 '13,31#uncool',
53 [
54 'type' => LinkService::TYPE_PAGE,
55 'pageuid' => '13',
56 'pagetype' => '31',
57 'fragment' => 'uncool'
58 ],
59 't3://page?uid=13&type=31#uncool'
60 ],
61 'page with type and parameters and fragment - old style' => [
62 '13,31?unbel=ievable#uncool',
63 [
64 'type' => LinkService::TYPE_PAGE,
65 'pageuid' => '13',
66 'pagetype' => '31',
67 'parameters' => 'unbel=ievable',
68 'fragment' => 'uncool'
69 ],
70 't3://page?uid=13&type=31&unbel=ievable#uncool'
71 ],
72 'page with alias - old style' => [
73 'alias13',
74 [
75 'type' => LinkService::TYPE_PAGE,
76 'pagealias' => 'alias13'
77 ],
78 't3://page?alias=alias13'
79 ],
80 'http URL' => [
81 'http://www.have.you/ever?did=this',
82 [
83 'type' => LinkService::TYPE_URL,
84 'url' => 'http://www.have.you/ever?did=this'
85 ],
86 'http://www.have.you/ever?did=this'
87 ],
88 'http URL without scheme' => [
89 'www.have.you/ever?did=this',
90 [
91 'type' => LinkService::TYPE_URL,
92 'url' => 'http://www.have.you/ever?did=this'
93 ],
94 'http://www.have.you/ever?did=this'
95 ],
96 'https URL' => [
97 'https://www.have.you/ever?did=this',
98 [
99 'type' => LinkService::TYPE_URL,
100 'url' => 'https://www.have.you/ever?did=this'
101 ],
102 'https://www.have.you/ever?did=this'
103 ],
104 'https URL with port' => [
105 'https://www.have.you:8088/ever?did=this',
106 [
107 'type' => LinkService::TYPE_URL,
108 'url' => 'https://www.have.you:8088/ever?did=this'
109 ],
110 'https://www.have.you:8088/ever?did=this'
111 ],
112 'ftp URL' => [
113 'ftp://www.have.you/ever?did=this',
114 [
115 'type' => LinkService::TYPE_URL,
116 'url' => 'ftp://www.have.you/ever?did=this'
117 ],
118 'ftp://www.have.you/ever?did=this'
119 ],
120 'afp URL' => [
121 'afp://www.have.you/ever?did=this',
122 [
123 'type' => LinkService::TYPE_URL,
124 'url' => 'afp://www.have.you/ever?did=this'
125 ],
126 'afp://www.have.you/ever?did=this'
127 ],
128 'sftp URL' => [
129 'sftp://nice:andsecret@www.have.you:23/ever?did=this',
130 [
131 'type' => LinkService::TYPE_URL,
132 'url' => 'sftp://nice:andsecret@www.have.you:23/ever?did=this'
133 ],
134 'sftp://nice:andsecret@www.have.you:23/ever?did=this'
135 ],
136 'email with protocol' => [
137 'mailto:one@love.com',
138 [
139 'type' => LinkService::TYPE_EMAIL,
140 'email' => 'one@love.com'
141 ],
142 'mailto:one@love.com'
143 ],
144 'email without protocol' => [
145 'one@love.com',
146 [
147 'type' => LinkService::TYPE_EMAIL,
148 'email' => 'one@love.com'
149 ],
150 'mailto:one@love.com'
151 ],
152 'email without protocol and subject parameter' => [
153 'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen',
154 [
155 'type' => LinkService::TYPE_EMAIL,
156 'email' => 'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen'
157 ],
158 'mailto:email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen'
159 ],
160 'current page - cool style' => [
161 't3://page?uid=current',
162 [
163 'type' => LinkService::TYPE_PAGE,
164 'pageuid' => 'current'
165 ],
166 't3://page?uid=current'
167 ],
168 'current empty page - cool style' => [
169 't3://page',
170 [
171 'type' => LinkService::TYPE_PAGE,
172 'pageuid' => 'current'
173 ],
174 't3://page?uid=current'
175 ],
176 'simple page - cool style' => [
177 't3://page?uid=13',
178 [
179 'type' => LinkService::TYPE_PAGE,
180 'pageuid' => 13
181 ],
182 't3://page?uid=13'
183 ],
184 'page with alias - cool style' => [
185 't3://page?alias=alias13',
186 [
187 'type' => LinkService::TYPE_PAGE,
188 'pagealias' => 'alias13'
189 ],
190 't3://page?alias=alias13'
191 ],
192 'page with alias and type - cool style' => [
193 't3://page?alias=alias13&type=31',
194 [
195 'type' => LinkService::TYPE_PAGE,
196 'pagealias' => 'alias13',
197 'pagetype' => '31'
198 ],
199 't3://page?alias=alias13&type=31'
200 ],
201 'page with alias and parameters - cool style' => [
202 't3://page?alias=alias13&my=additional&parameter=that&are=nice',
203 [
204 'type' => LinkService::TYPE_PAGE,
205 'pagealias' => 'alias13',
206 'parameters' => 'my=additional&parameter=that&are=nice'
207 ],
208 't3://page?alias=alias13&my=additional&parameter=that&are=nice',
209 ],
210 'page with alias and parameters and fragment - cool style' => [
211 't3://page?alias=alias13&my=additional&parameter=that&are=nice#again',
212 [
213 'type' => LinkService::TYPE_PAGE,
214 'pagealias' => 'alias13',
215 'parameters' => 'my=additional&parameter=that&are=nice',
216 'fragment' => 'again'
217 ],
218 't3://page?alias=alias13&my=additional&parameter=that&are=nice#again',
219 ]
220 ];
221 }
222
223 /**
224 * @test
225 *
226 * @param string $input
227 * @param array $expected
228 * @param string $finalString
229 *
230 * @dataProvider resolveParametersForNonFilesDataProvider
231 */
232 public function resolveReturnsSplitParameters($input, $expected, $finalString)
233 {
234 $subject = new LinkService();
235 $this->assertEquals($expected, $subject->resolve($input));
236 }
237
238 /**
239 * @test
240 *
241 * @param string $input
242 * @param array $parameters
243 * @param string $expected
244 *
245 * @dataProvider resolveParametersForNonFilesDataProvider
246 */
247 public function splitParametersToUnifiedIdentifier($input, $parameters, $expected)
248 {
249 $subject = new LinkService();
250 $this->assertEquals($expected, $subject->asString($parameters));
251 }
252 }