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