‪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 
22 use TYPO3\TestingFramework\Fluid\Unit\Core\Rendering\RenderingContextFixture;
23 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
24 
28 class ‪TypolinkViewHelperTest extends ViewHelperBaseTestcase
29 {
33  protected ‪$subject;
34 
38  protected function ‪setUp()
39  {
40  $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, ['renderChildren']);
42  $renderingContext = $this->createMock(RenderingContextFixture::class);
43  $this->subject->setRenderingContext($renderingContext);
44  }
45 
50  {
51  $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
52  $this->subject->setArguments([
53  'parameter' => '42',
54  'target' => '',
55  'class' => '',
56  'title' => '',
57  'additionalParams' => '',
58  'additionalAttributes' => [],
59  ]);
60  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
61  $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
62  GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
63  $this->assertEquals('foo', $this->subject->render());
64  }
65 
70  {
71  $addQueryString = true;
72  $addQueryStringMethod = 'GET,POST';
73  $addQueryStringExclude = 'cHash';
74 
75  $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
76  $this->subject->setArguments([
77  'parameter' => '42',
78  'target' => '',
79  'class' => '',
80  'title' => '',
81  'additionalParams' => '',
82  'additionalAttributes' => [],
83  'addQueryString' => $addQueryString,
84  'addQueryStringMethod' => $addQueryStringMethod,
85  'addQueryStringExclude' => $addQueryStringExclude,
86  'absolute' => false
87  ]);
88  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
89  $contentObjectRendererMock->expects($this->once())
90  ->method('stdWrap')
91  ->with(
92  'innerContent',
93  [
94  'typolink.' => [
95  'parameter' => '42',
96  'ATagParams' => '',
97  'useCacheHash' => false,
98  'addQueryString' => $addQueryString,
99  'addQueryString.' => [
100  'method' => $addQueryStringMethod,
101  'exclude' => $addQueryStringExclude,
102  ],
103  'forceAbsoluteUrl' => false,
104  ],
105  ]
106  )
107  ->will($this->returnValue('foo'));
108  GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
109  $this->assertEquals('foo', $this->subject->render());
110  }
111 
115  public function ‪typoScriptConfigurationData()
116  {
117  return [
118  'empty input' => [
119  '', // input from link field
120  '', // target from fluid
121  '', // class from fluid
122  '', // title from fluid
123  '', // additional parameters from fluid
124  '',
125  ],
126  'simple id input' => [
127  19,
128  '',
129  '',
130  '',
131  '',
132  '19',
133  ],
134  'external url with target' => [
135  'www.web.de _blank',
136  '',
137  '',
138  '',
139  '',
140  'www.web.de _blank',
141  ],
142  'page with extended class' => [
143  '42 - css-class',
144  '',
145  'fluid_class',
146  '',
147  '',
148  '42 - "css-class fluid_class"',
149  ],
150  'classes are unique' => [
151  '42 - css-class',
152  '',
153  'css-class',
154  '',
155  '',
156  '42 - css-class',
157  ],
158  'page with overridden title' => [
159  '42 - - "a link title"',
160  '',
161  '',
162  'another link title',
163  '',
164  '42 - - "another link title"',
165  ],
166  'page with title and extended parameters' => [
167  '42 - - "a link title" &x=y',
168  '',
169  '',
170  '',
171  '&a=b',
172  '42 - - "a link title" &x=y&a=b',
173  ],
174  'page with complex title and extended parameters' => [
175  '42 - - "a \\"link\\" title with \\\\" &x=y',
176  '',
177  '',
178  '',
179  '&a=b',
180  '42 - - "a \\"link\\" title with \\\\" &x=y&a=b',
181  ],
182  'full parameter usage' => [
183  '19 _blank css-class "testtitle with whitespace" &X=y',
184  '-',
185  'fluid_class',
186  'a new title',
187  '&a=b',
188  '19 - "css-class fluid_class" "a new title" &X=y&a=b',
189  ],
190  'only page id and overwrite' => [
191  '42',
192  '',
193  '',
194  '',
195  '&a=b',
196  '42 - - - &a=b',
197  ],
198  't3:// with extended class' => [
199  't3://url?url=https://example.org?param=1&other=dude - css-class',
200  '',
201  'fluid_class',
202  '',
203  '',
204  't3://url?url=https://example.org?param=1&other=dude - "css-class fluid_class"',
205  ],
206  't3:// classes are unique' => [
207  't3://url?url=https://example.org?param=1&other=dude - css-class',
208  '',
209  'css-class',
210  '',
211  '',
212  't3://url?url=https://example.org?param=1&other=dude - css-class',
213  ],
214  't3:// with overridden title' => [
215  't3://url?url=https://example.org?param=1&other=dude - - "a link title"',
216  '',
217  '',
218  'another link title',
219  '',
220  't3://url?url=https://example.org?param=1&other=dude - - "another link title"',
221  ],
222  't3:// with title and extended parameters' => [
223  't3://url?url=https://example.org?param=1&other=dude - - "a link title" &x=y',
224  '',
225  '',
226  '',
227  '&a=b',
228  't3://url?url=https://example.org?param=1&other=dude - - "a link title" &x=y&a=b',
229  ],
230  't3:// with complex title and extended parameters' => [
231  't3://url?url=https://example.org?param=1&other=dude - - "a \\"link\\" title with \\\\" &x=y',
232  '',
233  '',
234  '',
235  '&a=b',
236  't3://url?url=https://example.org?param=1&other=dude - - "a \\"link\\" title with \\\\" &x=y&a=b',
237  ],
238  't3:// parameter usage' => [
239  't3://url?url=https://example.org?param=1&other=dude _blank css-class "testtitle with whitespace" &X=y',
240  '-',
241  'fluid_class',
242  'a new title',
243  '&a=b',
244  't3://url?url=https://example.org?param=1&other=dude - "css-class fluid_class" "a new title" &X=y&a=b',
245  ],
246  'only t3:// and overwrite' => [
247  't3://url?url=https://example.org?param=1&other=dude',
248  '',
249  '',
250  '',
251  '&a=b',
252  't3://url?url=https://example.org?param=1&other=dude - - - &a=b',
253  ],
254  ];
255  }
256 
268  $input,
269  $targetFromFluid,
270  $classFromFluid,
271  $titleFromFluid,
272  $additionalParametersFromFluid,
273  $expected
274  ) {
275  $result = $this->subject->_call(
276  'createTypolinkParameterArrayFromArguments',
277  $input,
278  $targetFromFluid,
279  $classFromFluid,
280  $titleFromFluid,
281  $additionalParametersFromFluid
282  );
283  $this->assertSame($expected, $result);
284  }
285 }
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\Core\Rendering\RenderingContext
Definition: RenderingContext.php:36