‪TYPO3CMS  10.4
TypoLinkCodecServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪TypoLinkCodecServiceTest extends UnitTestCase
25 {
29  protected ‪$subject;
30 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->subject = new ‪TypoLinkCodecService();
38  }
39 
46  public function ‪encodeReturnsExpectedResult(array $parts, $expected)
47  {
48  self::assertSame($expected, $this->subject->encode($parts));
49  }
50 
55  {
56  return [
57  'empty input' => [
58  [
59  'url' => '',
60  'target' => '',
61  'class' => '',
62  'title' => '',
63  'additionalParams' => ''
64  ],
65  ''
66  ],
67  'full parameter usage' => [
68  [
69  'url' => '19',
70  'target' => '_blank',
71  'class' => 'css-class',
72  'title' => 'testtitle with whitespace',
73  'additionalParams' => '&x=y'
74  ],
75  '19 _blank css-class "testtitle with whitespace" &x=y'
76  ],
77  'crazy title and partial items only' => [
78  [
79  'url' => 'foo',
80  'title' => 'a "link\\ ti\\"tle',
81  ],
82  'foo - - "a \\"link\\\\ ti\\\\\\"tle"'
83  ]
84  ];
85  }
86 
93  public function ‪decodeReturnsExpectedResult($typoLink, array $expected)
94  {
95  self::assertSame($expected, $this->subject->decode($typoLink));
96  }
97 
102  {
103  return [
104  'empty input' => [
105  '',
106  [
107  'url' => '',
108  'target' => '',
109  'class' => '',
110  'title' => '',
111  'additionalParams' => ''
112  ],
113  ],
114  'simple id input' => [
115  '19',
116  [
117  'url' => '19',
118  'target' => '',
119  'class' => '',
120  'title' => '',
121  'additionalParams' => ''
122  ],
123  ],
124  'external url with target' => [
125  'www.web.de _blank',
126  [
127  'url' => 'www.web.de',
128  'target' => '_blank',
129  'class' => '',
130  'title' => '',
131  'additionalParams' => ''
132  ],
133  ],
134  'page with class' => [
135  '42 - css-class',
136  [
137  'url' => '42',
138  'target' => '',
139  'class' => 'css-class',
140  'title' => '',
141  'additionalParams' => ''
142  ],
143  ],
144  'page with title' => [
145  '42 - - "a link title"',
146  [
147  'url' => '42',
148  'target' => '',
149  'class' => '',
150  'title' => 'a link title',
151  'additionalParams' => ''
152  ],
153  ],
154  'page with crazy title' => [
155  '42 - - "a \\"link\\\\ ti\\\\\\"tle"',
156  [
157  'url' => '42',
158  'target' => '',
159  'class' => '',
160  'title' => 'a "link\\ ti\\"tle',
161  'additionalParams' => ''
162  ],
163  ],
164  'page with title and parameters' => [
165  '42 - - "a link title" &x=y',
166  [
167  'url' => '42',
168  'target' => '',
169  'class' => '',
170  'title' => 'a link title',
171  'additionalParams' => '&x=y'
172  ],
173  ],
174  'page with complex title' => [
175  '42 - - "a \\"link\\" title with \\\\" &x=y',
176  [
177  'url' => '42',
178  'target' => '',
179  'class' => '',
180  'title' => 'a "link" title with \\',
181  'additionalParams' => '&x=y'
182  ],
183  ],
184  'full parameter usage' => [
185  '19 _blank css-class "testtitle with whitespace" &X=y',
186  [
187  'url' => '19',
188  'target' => '_blank',
189  'class' => 'css-class',
190  'title' => 'testtitle with whitespace',
191  'additionalParams' => '&X=y'
192  ],
193  ],
194  ];
195  }
196 }
‪TYPO3\CMS\Frontend\Tests\Unit\Service
Definition: TypoLinkCodecServiceTest.php:16