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