‪TYPO3CMS  11.5
LinkServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪LinkServiceTest extends UnitTestCase
24 {
31  {
32  return [
33  'simple page - old style' => [
34  // original input value
35  '13',
36  // splitted values
37  [
38  'type' => ‪LinkService::TYPE_PAGE,
39  'pageuid' => 13,
40  ],
41  // final unified URN
42  't3://page?uid=13',
43  ],
44  'page with type - old style' => [
45  '13,31',
46  [
47  'type' => ‪LinkService::TYPE_PAGE,
48  'pageuid' => 13,
49  'pagetype' => 31,
50  ],
51  't3://page?uid=13&type=31',
52  ],
53  'page with type and fragment - old style' => [
54  '13,31#uncool',
55  [
56  'type' => ‪LinkService::TYPE_PAGE,
57  'pageuid' => '13',
58  'pagetype' => '31',
59  'fragment' => 'uncool',
60  ],
61  't3://page?uid=13&type=31#uncool',
62  ],
63  'page with type and parameters and fragment - old style' => [
64  '13,31?unbel=ievable#uncool',
65  [
66  'type' => ‪LinkService::TYPE_PAGE,
67  'pageuid' => '13',
68  'pagetype' => '31',
69  'parameters' => 'unbel=ievable',
70  'fragment' => 'uncool',
71  ],
72  't3://page?uid=13&type=31&unbel=ievable#uncool',
73  ],
74  'http URL' => [
75  'http://www.have.you/ever?did=this',
76  [
77  'type' => ‪LinkService::TYPE_URL,
78  'url' => 'http://www.have.you/ever?did=this',
79  ],
80  'http://www.have.you/ever?did=this',
81  ],
82  'http URL without scheme' => [
83  'www.have.you/ever?did=this',
84  [
85  'type' => ‪LinkService::TYPE_URL,
86  'url' => 'http://www.have.you/ever?did=this',
87  ],
88  'http://www.have.you/ever?did=this',
89  ],
90  'https URL' => [
91  'https://www.have.you/ever?did=this',
92  [
93  'type' => ‪LinkService::TYPE_URL,
94  'url' => 'https://www.have.you/ever?did=this',
95  ],
96  'https://www.have.you/ever?did=this',
97  ],
98  'https URL with port' => [
99  'https://www.have.you:8088/ever?did=this',
100  [
101  'type' => ‪LinkService::TYPE_URL,
102  'url' => 'https://www.have.you:8088/ever?did=this',
103  ],
104  'https://www.have.you:8088/ever?did=this',
105  ],
106  'ftp URL' => [
107  'ftp://www.have.you/ever?did=this',
108  [
109  'type' => ‪LinkService::TYPE_URL,
110  'url' => 'ftp://www.have.you/ever?did=this',
111  ],
112  'ftp://www.have.you/ever?did=this',
113  ],
114  'afp URL' => [
115  'afp://www.have.you/ever?did=this',
116  [
117  'type' => ‪LinkService::TYPE_URL,
118  'url' => 'afp://www.have.you/ever?did=this',
119  ],
120  'afp://www.have.you/ever?did=this',
121  ],
122  'sftp URL' => [
123  'sftp://nice:andsecret@www.have.you:23/ever?did=this',
124  [
125  'type' => ‪LinkService::TYPE_URL,
126  'url' => 'sftp://nice:andsecret@www.have.you:23/ever?did=this',
127  ],
128  'sftp://nice:andsecret@www.have.you:23/ever?did=this',
129  ],
130  'email with protocol' => [
131  'mailto:one@love.com',
132  [
133  'type' => ‪LinkService::TYPE_EMAIL,
134  'email' => 'one@love.com',
135  ],
136  'mailto:one@love.com',
137  ],
138  'email without protocol' => [
139  'one@love.com',
140  [
141  'type' => ‪LinkService::TYPE_EMAIL,
142  'email' => 'one@love.com',
143  ],
144  'mailto:one@love.com',
145  ],
146  'email without protocol and subject parameter' => [
147  'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen',
148  [
149  'type' => ‪LinkService::TYPE_EMAIL,
150  'email' => 'email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen',
151  ],
152  'mailto:email@mail.mail?subject=Anfrage:%20Text%20Text%20Lösungen',
153  ],
154  'current page - cool style' => [
155  't3://page?uid=current',
156  [
157  'type' => ‪LinkService::TYPE_PAGE,
158  'pageuid' => 'current',
159  ],
160  't3://page?uid=current',
161  ],
162  'current empty page - cool style' => [
163  't3://page',
164  [
165  'type' => ‪LinkService::TYPE_PAGE,
166  'pageuid' => 'current',
167  ],
168  't3://page?uid=current',
169  ],
170  'simple page - cool style' => [
171  't3://page?uid=13',
172  [
173  'type' => ‪LinkService::TYPE_PAGE,
174  'pageuid' => 13,
175  ],
176  't3://page?uid=13',
177  ],
178  ];
179  }
180 
185  public function ‪resolveReturnsSplitParameters(string $input, array $expected, string $finalString): void
186  {
187  $subject = new ‪LinkService();
188  self::assertEquals($expected, $subject->resolve($input));
189  }
190 
195  public function ‪splitParametersToUnifiedIdentifier(string $input, array $parameters, string $expected): void
196  {
197  $subject = new ‪LinkService();
198  self::assertEquals($expected, $subject->asString($parameters));
199  }
200 }