‪TYPO3CMS  11.5
TypoLinkCodecServiceTest.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 
20 use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪TypoLinkCodecServiceTest extends UnitTestCase
27 {
28  protected TypoLinkCodecService ‪$subject;
29 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->subject = new TypoLinkCodecService();
37  }
38 
45  public function ‪encodeReturnsExpectedResult(array $parts, string $expected): void
46  {
47  self::assertSame($expected, $this->subject->encode($parts));
48  }
49 
54  {
55  return [
56  'empty input' => [
57  [
58  'url' => '',
59  'target' => '',
60  'class' => '',
61  'title' => '',
62  'additionalParams' => '',
63  ],
64  '',
65  ],
66  'full parameter usage' => [
67  [
68  'url' => '19',
69  'target' => '_blank',
70  'class' => 'css-class',
71  'title' => 'testtitle with whitespace',
72  'additionalParams' => '&x=y',
73  ],
74  '19 _blank css-class "testtitle with whitespace" &x=y',
75  ],
76  'crazy title and partial items only' => [
77  [
78  'url' => 'foo',
79  'title' => 'a "link\\ ti\\"tle',
80  ],
81  'foo - - "a \\"link\\\\ ti\\\\\\"tle"',
82  ],
83  ];
84  }
85 
92  public function ‪decodeReturnsExpectedResult(string $typoLink, array $expected): void
93  {
94  self::assertSame($expected, $this->subject->decode($typoLink));
95  }
96 
101  {
102  return [
103  'empty input' => [
104  '',
105  [
106  'url' => '',
107  'target' => '',
108  'class' => '',
109  'title' => '',
110  'additionalParams' => '',
111  ],
112  ],
113  'simple id input' => [
114  '19',
115  [
116  'url' => '19',
117  'target' => '',
118  'class' => '',
119  'title' => '',
120  'additionalParams' => '',
121  ],
122  ],
123  'external url with target' => [
124  'www.web.de _blank',
125  [
126  'url' => 'www.web.de',
127  'target' => '_blank',
128  'class' => '',
129  'title' => '',
130  'additionalParams' => '',
131  ],
132  ],
133  'page with class' => [
134  '42 - css-class',
135  [
136  'url' => '42',
137  'target' => '',
138  'class' => 'css-class',
139  'title' => '',
140  'additionalParams' => '',
141  ],
142  ],
143  'page with title' => [
144  '42 - - "a link title"',
145  [
146  'url' => '42',
147  'target' => '',
148  'class' => '',
149  'title' => 'a link title',
150  'additionalParams' => '',
151  ],
152  ],
153  'page with crazy title' => [
154  '42 - - "a \\"link\\\\ ti\\\\\\"tle"',
155  [
156  'url' => '42',
157  'target' => '',
158  'class' => '',
159  'title' => 'a "link\\ ti\\"tle',
160  'additionalParams' => '',
161  ],
162  ],
163  'page with title and parameters' => [
164  '42 - - "a link title" &x=y',
165  [
166  'url' => '42',
167  'target' => '',
168  'class' => '',
169  'title' => 'a link title',
170  'additionalParams' => '&x=y',
171  ],
172  ],
173  'page with complex title' => [
174  '42 - - "a \\"link\\" title with \\\\" &x=y',
175  [
176  'url' => '42',
177  'target' => '',
178  'class' => '',
179  'title' => 'a "link" title with \\',
180  'additionalParams' => '&x=y',
181  ],
182  ],
183  'full parameter usage' => [
184  '19 _blank css-class "testtitle with whitespace" &X=y',
185  [
186  'url' => '19',
187  'target' => '_blank',
188  'class' => 'css-class',
189  'title' => 'testtitle with whitespace',
190  'additionalParams' => '&X=y',
191  ],
192  ],
193  ];
194  }
195 }
‪TYPO3\CMS\Frontend\Tests\Unit\Service
Definition: TypoLinkCodecServiceTest.php:18