TYPO3 CMS  TYPO3_8-7
TypolinkViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
22 
26 class TypolinkViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected $subject;
32 
36  protected function setUp()
37  {
38  $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, ['renderChildren']);
40  $renderingContext = $this->createMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class);
41  $this->subject->setRenderingContext($renderingContext);
42  }
43 
48  {
49  $addQueryString = true;
50  $addQueryStringMethod = 'GET,POST';
51  $addQueryStringExclude = 'cHash';
52 
53  $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
54  $this->subject->setArguments([
55  'parameter' => '42',
56  'target' => '',
57  'class' => '',
58  'title' => '',
59  'additionalParams' => '',
60  'additionalAttributes' => [],
61  'addQueryString' => $addQueryString,
62  'addQueryStringMethod' => $addQueryStringMethod,
63  'addQueryStringExclude' => $addQueryStringExclude,
64  'absolute' => false
65  ]);
66  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
67  $contentObjectRendererMock->expects($this->once())
68  ->method('stdWrap')
69  ->with(
70  'innerContent',
71  [
72  'typolink.' => [
73  'parameter' => '42',
74  'ATagParams' => '',
75  'useCacheHash' => false,
76  'addQueryString' => $addQueryString,
77  'addQueryString.' => [
78  'method' => $addQueryStringMethod,
79  'exclude' => $addQueryStringExclude,
80  ],
81  'forceAbsoluteUrl' => false,
82  ],
83  ]
84  )
85  ->will($this->returnValue('foo'));
86  GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
87  $this->assertEquals('foo', $this->subject->render());
88  }
89 
94  {
95  $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
96  $this->subject->setArguments([
97  'parameter' => '42',
98  'target' => '',
99  'class' => '',
100  'title' => '',
101  'additionalParams' => '',
102  'additionalAttributes' => [],
103  ]);
104  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
105  $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
106  GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
107  $this->assertEquals('foo', $this->subject->render());
108  }
109 
113  public function typoScriptConfigurationData()
114  {
115  return [
116  'empty input' => [
117  '', // input from link field
118  '', // target from fluid
119  '', // class from fluid
120  '', // title from fluid
121  '', // additional parameters from fluid
122  '',
123  ],
124  'simple id input' => [
125  19,
126  '',
127  '',
128  '',
129  '',
130  '19',
131  ],
132  'external url with target' => [
133  'www.web.de _blank',
134  '',
135  '',
136  '',
137  '',
138  'www.web.de _blank',
139  ],
140  'page with extended class' => [
141  '42 - css-class',
142  '',
143  'fluid_class',
144  '',
145  '',
146  '42 - "css-class fluid_class"',
147  ],
148  'classes are unique' => [
149  '42 - css-class',
150  '',
151  'css-class',
152  '',
153  '',
154  '42 - css-class',
155  ],
156  'page with overridden title' => [
157  '42 - - "a link title"',
158  '',
159  '',
160  'another link title',
161  '',
162  '42 - - "another link title"',
163  ],
164  'page with title and extended parameters' => [
165  '42 - - "a link title" &x=y',
166  '',
167  '',
168  '',
169  '&a=b',
170  '42 - - "a link title" &x=y&a=b',
171  ],
172  'page with complex title and extended parameters' => [
173  '42 - - "a \\"link\\" title with \\\\" &x=y',
174  '',
175  '',
176  '',
177  '&a=b',
178  '42 - - "a \\"link\\" title with \\\\" &x=y&a=b',
179  ],
180  'full parameter usage' => [
181  '19 _blank css-class "testtitle with whitespace" &X=y',
182  '-',
183  'fluid_class',
184  'a new title',
185  '&a=b',
186  '19 - "css-class fluid_class" "a new title" &X=y&a=b',
187  ],
188  'only page id and overwrite' => [
189  '42',
190  '',
191  '',
192  '',
193  '&a=b',
194  '42 - - - &a=b',
195  ],
196  ];
197  }
198 
209  public function createTypolinkParameterArrayFromArgumentsReturnsExpectedArray($input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid, $expected)
210  {
211  $result = $this->subject->_call('createTypolinkParameterArrayFromArguments', $input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid);
212  $this->assertSame($expected, $result);
213  }
214 }
static addInstance($className, $instance)