TYPO3 CMS  TYPO3_8-7
LinkServiceTest.php
Go to the documentation of this file.
1 <?php
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 
19 
20 class LinkServiceTest extends UnitTestCase
21 {
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  'email without protocol and subject parameter' => [
152  'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen',
153  [
154  'type' => LinkService::TYPE_EMAIL,
155  'email' => 'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen'
156  ],
157  'mailto:email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen'
158  ],
159  'current page - cool style' => [
160  't3://page?uid=current',
161  [
162  'type' => LinkService::TYPE_PAGE,
163  'pageuid' => 'current'
164  ],
165  't3://page?uid=current'
166  ],
167  'current empty page - cool style' => [
168  't3://page',
169  [
170  'type' => LinkService::TYPE_PAGE,
171  'pageuid' => 'current'
172  ],
173  't3://page?uid=current'
174  ],
175  'simple page - cool style' => [
176  't3://page?uid=13',
177  [
178  'type' => LinkService::TYPE_PAGE,
179  'pageuid' => 13
180  ],
181  't3://page?uid=13'
182  ],
183  'page with alias - cool style' => [
184  't3://page?alias=alias13',
185  [
186  'type' => LinkService::TYPE_PAGE,
187  'pagealias' => 'alias13'
188  ],
189  't3://page?alias=alias13'
190  ],
191  'page with alias and type - cool style' => [
192  't3://page?alias=alias13&type=31',
193  [
194  'type' => LinkService::TYPE_PAGE,
195  'pagealias' => 'alias13',
196  'pagetype' => '31'
197  ],
198  't3://page?alias=alias13&type=31'
199  ],
200  'page with alias and parameters - cool style' => [
201  't3://page?alias=alias13&my=additional&parameter=that&are=nice',
202  [
203  'type' => LinkService::TYPE_PAGE,
204  'pagealias' => 'alias13',
205  'parameters' => 'my=additional&parameter=that&are=nice'
206  ],
207  't3://page?alias=alias13&my=additional&parameter=that&are=nice',
208  ],
209  'page with alias and parameters and fragment - cool style' => [
210  't3://page?alias=alias13&my=additional&parameter=that&are=nice#again',
211  [
212  'type' => LinkService::TYPE_PAGE,
213  'pagealias' => 'alias13',
214  'parameters' => 'my=additional&parameter=that&are=nice',
215  'fragment' => 'again'
216  ],
217  't3://page?alias=alias13&my=additional&parameter=that&are=nice#again',
218  ]
219  ];
220  }
221 
231  public function resolveReturnsSplitParameters($input, $expected, $finalString)
232  {
233  $subject = new LinkService();
234  $this->assertEquals($expected, $subject->resolve($input));
235  }
236 
246  public function splitParametersToUnifiedIdentifier($input, $parameters, $expected)
247  {
248  $subject = new LinkService();
249  $this->assertEquals($expected, $subject->asString($parameters));
250  }
251 }