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