‪TYPO3CMS  9.5
TypolinkViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 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 class ‪TypolinkViewHelperTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
21 {
22  private const ‪TEMPLATE_BASE_PATH = 'typo3/sysext/fluid/Tests/Functional/ViewHelpers/Fixtures/';
23 
27  protected ‪$testExtensionsToLoad = ['typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test'];
28 
32  protected ‪$coreExtensionsToLoad = ['fluid'];
33 
34  protected function ‪setUp()
35  {
36  parent::setUp();
37 
38  $this->importDataSet('typo3/sysext/fluid/Tests/Functional/ViewHelpers/Fixtures/pages.xml');
39 
40  $_GET = [
41  'foo' => 'bar',
42  'temp' => 'test',
43  ];
44  }
45 
57  public function ‪renderCreatesCorrectLink(
58  $parameter,
59  bool $addQueryString,
60  string $addQueryStringMethod,
61  string $addQueryStringExclude,
62  string $expected,
63  string $template
64  ) {
65  $view = new ‪StandaloneView();
66  $view->setTemplatePathAndFilename('typo3/sysext/fluid/Tests/Functional/ViewHelpers/Fixtures/' . $template . '.html');
67  $view->assignMultiple([
68  'parameter' => $parameter,
69  'uid' => 1,
70  'addQueryString' => $addQueryString,
71  'addQueryStringMethod' => $addQueryStringMethod,
72  'addQueryStringExclude' => $addQueryStringExclude,
73  ]);
74  $this->assertEquals($expected, trim(preg_replace('/\s+/', ' ', $view->render())));
75  }
76 
80  public function ‪renderCreatesCorrectLinkProvider(): array
81  {
82  return [
83  'link: default' => [
84  'parameter' => 1,
85  'addQueryString' => false,
86  'addQueryStringMethod' => 'GET',
87  'addQueryStringExclude' => '',
88  'expected' => '<a href="index.php?id=1">This is a testlink</a> <a href="index.php?id=1">This is a testlink</a>',
89  'template' => 'link_typolink_viewhelper',
90  ],
91  'link: with add query string' => [
92  'parameter' => 1,
93  'addQueryString' => true,
94  'addQueryStringMethod' => 'GET',
95  'addQueryStringExclude' => '',
96  'expected' => '<a href="index.php?id=1&amp;foo=bar&amp;temp=test">This is a testlink</a> <a href="index.php?id=1">This is a testlink</a>',
97  'template' => 'link_typolink_viewhelper',
98  ],
99  'link: with add query string and exclude' => [
100  'parameter' => 1,
101  'addQueryString' => true,
102  'addQueryStringMethod' => 'GET',
103  'addQueryStringExclude' => 'temp',
104  'expected' => '<a href="index.php?id=1&amp;foo=bar">This is a testlink</a> <a href="index.php?id=1">This is a testlink</a>',
105  'template' => 'link_typolink_viewhelper',
106  ],
107  'link: with add query string and method POST' => [
108  'parameter' => 1,
109  'addQueryString' => true,
110  'addQueryStringMethod' => 'POST',
111  'addQueryStringExclude' => 'temp',
112  'expected' => '<a href="index.php?id=1">This is a testlink</a> <a href="index.php?id=1">This is a testlink</a>',
113  'template' => 'link_typolink_viewhelper',
114  ],
115  'uri: default' => [
116  'parameter' => 1,
117  'addQueryString' => false,
118  'addQueryStringMethod' => 'GET',
119  'addQueryStringExclude' => '',
120  'expected' => 'index.php?id=1 index.php?id=1',
121  'template' => 'uri_typolink_viewhelper',
122  ],
123  'uri: with add query string' => [
124  'parameter' => 1,
125  'addQueryString' => true,
126  'addQueryStringMethod' => 'GET',
127  'addQueryStringExclude' => '',
128  'expected' => 'index.php?id=1&amp;foo=bar&amp;temp=test index.php?id=1',
129  'template' => 'uri_typolink_viewhelper',
130  ],
131  'uri: with add query string and exclude' => [
132  'parameter' => 1,
133  'addQueryString' => true,
134  'addQueryStringMethod' => 'GET',
135  'addQueryStringExclude' => 'temp',
136  'expected' => 'index.php?id=1&amp;foo=bar index.php?id=1',
137  'template' => 'uri_typolink_viewhelper',
138  ],
139  'uri: with add query string and method POST' => [
140  'parameter' => 1,
141  'addQueryString' => true,
142  'addQueryStringMethod' => 'POST',
143  'addQueryStringExclude' => 'temp',
144  'expected' => 'index.php?id=1 index.php?id=1',
145  'template' => 'uri_typolink_viewhelper',
146  ],
147  't3://url link: default' => [
148  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
149  'addQueryString' => false,
150  'addQueryStringMethod' => 'GET',
151  'addQueryStringExclude' => '',
152  'expected' => '<a href="https://example.org?param=1">This is a testlink</a> <a href="https://example.org?param=1">This is a testlink</a>',
153  'template' => 'link_typolink_viewhelper',
154  ],
155  't3://url link: with add query string' => [
156  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
157  'addQueryString' => true,
158  'addQueryStringMethod' => 'GET',
159  'addQueryStringExclude' => '',
160  'expected' => '<a href="https://example.org?param=1">This is a testlink</a> <a href="https://example.org?param=1">This is a testlink</a>',
161  'template' => 'link_typolink_viewhelper',
162  ],
163  't3://url link: with add query string and exclude' => [
164  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
165  'addQueryString' => true,
166  'addQueryStringMethod' => 'GET',
167  'addQueryStringExclude' => 'temp',
168  'expected' => '<a href="https://example.org?param=1">This is a testlink</a> <a href="https://example.org?param=1">This is a testlink</a>',
169  'template' => 'link_typolink_viewhelper',
170  ],
171  't3://url uri: default' => [
172  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
173  'addQueryString' => false,
174  'addQueryStringMethod' => 'GET',
175  'addQueryStringExclude' => '',
176  'expected' => 'https://example.org?param=1 https://example.org?param=1',
177  'template' => 'uri_typolink_viewhelper',
178  ],
179  't3://url uri: with add query string' => [
180  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
181  'addQueryString' => true,
182  'addQueryStringMethod' => 'GET',
183  'addQueryStringExclude' => '',
184  'expected' => 'https://example.org?param=1 https://example.org?param=1',
185  'template' => 'uri_typolink_viewhelper',
186  ],
187  't3://url uri: with add query string and exclude' => [
188  'parameter' => 't3://url?url=https://example.org?param=1&other=dude',
189  'addQueryString' => true,
190  'addQueryStringMethod' => 'GET',
191  'addQueryStringExclude' => 'temp',
192  'expected' => 'https://example.org?param=1 https://example.org?param=1',
193  'template' => 'uri_typolink_viewhelper',
194  ],
195  'mailto: link: default' => [
196  'parameter' => 'mailto:foo@typo3.org',
197  'addQueryString' => false,
198  'addQueryStringMethod' => 'GET',
199  'addQueryStringExclude' => '',
200  'expected' => '<a href="mailto:foo@typo3.org">This is a testlink</a> <a href="mailto:foo@typo3.org">This is a testlink</a>',
201  'template' => 'link_typolink_viewhelper',
202  ],
203  'mailto: link: with add query string' => [
204  'parameter' => 'mailto:foo@typo3.org',
205  'addQueryString' => true,
206  'addQueryStringMethod' => 'GET',
207  'addQueryStringExclude' => '',
208  'expected' => '<a href="mailto:foo@typo3.org">This is a testlink</a> <a href="mailto:foo@typo3.org">This is a testlink</a>',
209  'template' => 'link_typolink_viewhelper',
210  ],
211  'mailto: link: with add query string and exclude' => [
212  'parameter' => 'mailto:foo@typo3.org',
213  'addQueryString' => true,
214  'addQueryStringMethod' => 'GET',
215  'addQueryStringExclude' => 'temp',
216  'expected' => '<a href="mailto:foo@typo3.org">This is a testlink</a> <a href="mailto:foo@typo3.org">This is a testlink</a>',
217  'template' => 'link_typolink_viewhelper',
218  ],
219  'mailto: uri: default' => [
220  'parameter' => 'mailto:foo@typo3.org',
221  'addQueryString' => false,
222  'addQueryStringMethod' => 'GET',
223  'addQueryStringExclude' => '',
224  'expected' => 'mailto:foo@typo3.org mailto:foo@typo3.org',
225  'template' => 'uri_typolink_viewhelper',
226  ],
227  'mailto: uri: with add query string' => [
228  'parameter' => 'mailto:foo@typo3.org',
229  'addQueryString' => true,
230  'addQueryStringMethod' => 'GET',
231  'addQueryStringExclude' => '',
232  'expected' => 'mailto:foo@typo3.org mailto:foo@typo3.org',
233  'template' => 'uri_typolink_viewhelper',
234  ],
235  'mailto: uri: with add query string and exclude' => [
236  'parameter' => 'mailto:foo@typo3.org',
237  'addQueryString' => true,
238  'addQueryStringMethod' => 'GET',
239  'addQueryStringExclude' => 'temp',
240  'expected' => 'mailto:foo@typo3.org mailto:foo@typo3.org',
241  'template' => 'uri_typolink_viewhelper',
242  ],
243  'http://: link: default' => [
244  'parameter' => 'http://typo3.org/foo/?foo=bar',
245  'addQueryString' => false,
246  'addQueryStringMethod' => 'GET',
247  'addQueryStringExclude' => '',
248  'expected' => '<a href="http://typo3.org/foo/?foo=bar">This is a testlink</a> <a href="http://typo3.org/foo/?foo=bar">This is a testlink</a>',
249  'template' => 'link_typolink_viewhelper',
250  ],
251  'http://: link: with add query string' => [
252  'parameter' => 'http://typo3.org/foo/?foo=bar',
253  'addQueryString' => true,
254  'addQueryStringMethod' => 'GET',
255  'addQueryStringExclude' => '',
256  'expected' => '<a href="http://typo3.org/foo/?foo=bar">This is a testlink</a> <a href="http://typo3.org/foo/?foo=bar">This is a testlink</a>',
257  'template' => 'link_typolink_viewhelper',
258  ],
259  'http://: link: with add query string and exclude' => [
260  'parameter' => 'http://typo3.org/foo/?foo=bar',
261  'addQueryString' => true,
262  'addQueryStringMethod' => 'GET',
263  'addQueryStringExclude' => 'temp',
264  'expected' => '<a href="http://typo3.org/foo/?foo=bar">This is a testlink</a> <a href="http://typo3.org/foo/?foo=bar">This is a testlink</a>',
265  'template' => 'link_typolink_viewhelper',
266  ],
267  'http://: uri: default' => [
268  'parameter' => 'http://typo3.org/foo/?foo=bar',
269  'addQueryString' => false,
270  'addQueryStringMethod' => 'GET',
271  'addQueryStringExclude' => '',
272  'expected' => 'http://typo3.org/foo/?foo=bar http://typo3.org/foo/?foo=bar',
273  'template' => 'uri_typolink_viewhelper',
274  ],
275  'http://: uri: with add query string' => [
276  'parameter' => 'http://typo3.org/foo/?foo=bar',
277  'addQueryString' => true,
278  'addQueryStringMethod' => 'GET',
279  'addQueryStringExclude' => '',
280  'expected' => 'http://typo3.org/foo/?foo=bar http://typo3.org/foo/?foo=bar',
281  'template' => 'uri_typolink_viewhelper',
282  ],
283  'http://: uri: with add query string and exclude' => [
284  'parameter' => 'http://typo3.org/foo/?foo=bar',
285  'addQueryString' => true,
286  'addQueryStringMethod' => 'GET',
287  'addQueryStringExclude' => 'temp',
288  'expected' => 'http://typo3.org/foo/?foo=bar http://typo3.org/foo/?foo=bar',
289  'template' => 'uri_typolink_viewhelper',
290  ],
291  ];
292  }
293 
295  {
296  return [
297  [
298  [
299  'parameter' => 'http://typo3.org/ "_self" "<CSS>" "<Title>"',
300  'additionalAttributes' => [
301  'data-html' => '<div data-template="template">'
302  . '<img src="logo.png" alt="&quot;&lt;ALT&gt;&quot;"></div>',
303  'data-other' => '\'\'',
304  ],
305  ],
306  '<a href="http://typo3.org/" title="&lt;Title&gt;" target="_self"'
307  . ' class="&lt;CSS&gt;" data-html="&lt;div data-template=&quot;template&quot;&gt;'
308  . '&lt;img src=&quot;logo.png&quot; alt=&quot;&amp;quot;&amp;lt;ALT&amp;gt;&amp;quot;&quot;&gt;&lt;/div&gt;"'
309  . ' data-other="\'\'">Link Text</a>'
310  ]
311  ];
312  }
313 
321  public function ‪typoLinkAdditionalAttributesAreRendered(array $configuration, string $expectation): void
322  {
323  $view = new ‪StandaloneView();
324  $view->setTemplatePathAndFilename(
325  self::TEMPLATE_BASE_PATH . 'link_typolink_additionalAttributes.html'
326  );
327  $view->assignMultiple($configuration);
328  self::assertSame($expectation, trim($view->render()));
329  }
330 }
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32