[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Service / TypoLinkCodecServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Service;
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\Frontend\Service\TypoLinkCodecService;
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class TypoLinkCodecServiceTest extends UnitTestCase
24 {
25 /**
26 * @var TypoLinkCodecService
27 */
28 protected $subject;
29
30 /**
31 * Set up test subject
32 */
33 protected function setUp()
34 {
35 $this->subject = new TypoLinkCodecService();
36 }
37
38 /**
39 * @test
40 * @dataProvider encodeReturnsExpectedResultDataProvider
41 * @param array $parts
42 * @param string$expected
43 */
44 public function encodeReturnsExpectedResult(array $parts, $expected)
45 {
46 $this->assertSame($expected, $this->subject->encode($parts));
47 }
48
49 /**
50 * @return array
51 */
52 public function encodeReturnsExpectedResultDataProvider()
53 {
54 return [
55 'empty input' => [
56 [
57 'url' => '',
58 'target' => '',
59 'class' => '',
60 'title' => '',
61 'additionalParams' => ''
62 ],
63 ''
64 ],
65 'full parameter usage' => [
66 [
67 'url' => '19',
68 'target' => '_blank',
69 'class' => 'css-class',
70 'title' => 'testtitle with whitespace',
71 'additionalParams' => '&x=y'
72 ],
73 '19 _blank css-class "testtitle with whitespace" &x=y'
74 ],
75 'crazy title and partial items only' => [
76 [
77 'url' => 'foo',
78 'title' => 'a "link\\ ti\\"tle',
79 ],
80 'foo - - "a \\"link\\\\ ti\\\\\\"tle"'
81 ]
82 ];
83 }
84
85 /**
86 * @test
87 * @dataProvider decodeReturnsExpectedResultDataProvider
88 * @param string $typoLink
89 * @param array $expected
90 */
91 public function decodeReturnsExpectedResult($typoLink, array $expected)
92 {
93 $this->assertSame($expected, $this->subject->decode($typoLink));
94 }
95
96 /**
97 * @return array
98 */
99 public function decodeReturnsExpectedResultDataProvider()
100 {
101 return [
102 'empty input' => [
103 '',
104 [
105 'url' => '',
106 'target' => '',
107 'class' => '',
108 'title' => '',
109 'additionalParams' => ''
110 ],
111 ],
112 'simple id input' => [
113 '19',
114 [
115 'url' => '19',
116 'target' => '',
117 'class' => '',
118 'title' => '',
119 'additionalParams' => ''
120 ],
121 ],
122 'external url with target' => [
123 'www.web.de _blank',
124 [
125 'url' => 'www.web.de',
126 'target' => '_blank',
127 'class' => '',
128 'title' => '',
129 'additionalParams' => ''
130 ],
131 ],
132 'page with class' => [
133 '42 - css-class',
134 [
135 'url' => '42',
136 'target' => '',
137 'class' => 'css-class',
138 'title' => '',
139 'additionalParams' => ''
140 ],
141 ],
142 'page with title' => [
143 '42 - - "a link title"',
144 [
145 'url' => '42',
146 'target' => '',
147 'class' => '',
148 'title' => 'a link title',
149 'additionalParams' => ''
150 ],
151 ],
152 'page with crazy title' => [
153 '42 - - "a \\"link\\\\ ti\\\\\\"tle"',
154 [
155 'url' => '42',
156 'target' => '',
157 'class' => '',
158 'title' => 'a "link\\ ti\\"tle',
159 'additionalParams' => ''
160 ],
161 ],
162 'page with title and parameters' => [
163 '42 - - "a link title" &x=y',
164 [
165 'url' => '42',
166 'target' => '',
167 'class' => '',
168 'title' => 'a link title',
169 'additionalParams' => '&x=y'
170 ],
171 ],
172 'page with complex title' => [
173 '42 - - "a \\"link\\" title with \\\\" &x=y',
174 [
175 'url' => '42',
176 'target' => '',
177 'class' => '',
178 'title' => 'a "link" title with \\',
179 'additionalParams' => '&x=y'
180 ],
181 ],
182 'full parameter usage' => [
183 '19 _blank css-class "testtitle with whitespace" &X=y',
184 [
185 'url' => '19',
186 'target' => '_blank',
187 'class' => 'css-class',
188 'title' => 'testtitle with whitespace',
189 'additionalParams' => '&X=y'
190 ],
191 ],
192 ];
193 }
194 }