[TASK] Make Link/TypolinkViewHelper compilable
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Link / TypolinkViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Link;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16
17 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
18 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\ViewHelpers\Link\TypolinkViewHelper;
21
22 /**
23 * Class TypolinkViewHelperTest
24 */
25 class TypolinkViewHelperTest extends ViewHelperBaseTestcase {
26
27 /**
28 * @var TypolinkViewHelper|\PHPUnit_Framework_MockObject_MockObject $subject
29 */
30 protected $subject;
31
32 public function setUp() {
33 $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, array('renderChildren'));
34 /** @var RenderingContext $renderingContext */
35 $renderingContext = $this->getMock(RenderingContext::class);
36 $this->subject->setRenderingContext($renderingContext);
37 }
38
39 /**
40 * @test
41 */
42 public function renderReturnsResultOfContentObjectRenderer() {
43 $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
44 $contentObjectRendererMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array(), array(), '', FALSE);
45 $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
46 GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $contentObjectRendererMock);
47 $this->assertEquals('foo', $this->subject->render('42'));
48 }
49
50 /**
51 * @return array
52 */
53 public function typoScriptConfigurationData() {
54 return array(
55 'empty input' => array(
56 '', // input from link field
57 '', // target from fluid
58 '', // class from fluid
59 '', // title from fluid
60 '', // additional parameters from fluid
61 array(),
62 ),
63 'simple id input' => array(
64 19,
65 '',
66 '',
67 '',
68 '',
69 array(
70 0 => '"19"',
71 ),
72 ),
73 'external url with target' => array(
74 'www.web.de _blank',
75 '',
76 '',
77 '',
78 '',
79 array(
80 0 => '"www.web.de"',
81 1 => '"_blank"',
82 ),
83 ),
84 'page with class' => array(
85 '42 - css-class',
86 '',
87 '',
88 '',
89 '',
90 array(
91 0 => '"42"',
92 1 => '-',
93 2 => '"css-class"',
94 ),
95 ),
96 'page with extended class' => array(
97 '42 - css-class',
98 '',
99 'fluid_class',
100 '',
101 '',
102 array(
103 0 => '"42"',
104 1 => '-',
105 2 => '"css-class fluid_class"',
106 ),
107 ),
108 'page with title' => array(
109 '42 - - "a link title"',
110 '',
111 '',
112 '',
113 '',
114 array(
115 0 => '"42"',
116 1 => '-',
117 2 => '-',
118 3 => '"a link title"'
119 )
120 ),
121 'page with overridden title' => array(
122 '42 - - "a link title"',
123 '',
124 '',
125 'another link title',
126 '',
127 array(
128 0 => '"42"',
129 1 => '-',
130 2 => '-',
131 3 => '"another link title"',
132 ),
133 ),
134 'page with title and parameters' => array(
135 '42 - - "a link title" &x=y',
136 '',
137 '',
138 '',
139 '',
140 array(
141 0 => '"42"',
142 1 => '-',
143 2 => '-',
144 3 => '"a link title"',
145 4 => '"&x=y"',
146 ),
147 ),
148 'page with title and extended parameters' => array(
149 '42 - - "a link title" &x=y',
150 '',
151 '',
152 '',
153 '&a=b',
154 array(
155 0 => '"42"',
156 1 => '-',
157 2 => '-',
158 3 => '"a link title"',
159 4 => '"&x=y&a=b"',
160 ),
161 ),
162 'full parameter usage' => array(
163 '19 _blank css-class "testtitle with whitespace" &X=y',
164 '-',
165 'fluid_class',
166 'a new title',
167 '&a=b',
168 array(
169 0 => '"19"',
170 1 => '-',
171 2 => '"css-class fluid_class"',
172 3 => '"a new title"',
173 4 => '"&X=y&a=b"',
174 ),
175 ),
176 'only page id and overwrite' => array(
177 '42',
178 '',
179 '',
180 '',
181 '&a=b',
182 array(
183 0 => '"42"',
184 1 => '-',
185 2 => '-',
186 3 => '-',
187 4 => '"&a=b"',
188 ),
189 ),
190 'email' => array(
191 'a@b.tld',
192 '',
193 '',
194 '',
195 '',
196 array(
197 '"a@b.tld"',
198 ),
199 ),
200 );
201 }
202
203 /**
204 * @test
205 * @dataProvider typoScriptConfigurationData
206 */
207 public function createTypolinkParameterArrayFromArgumentsReturnsExpectedArray($input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid, $expected) {
208 $result = $this->subject->_call('createTypolinkParameterArrayFromArguments', $input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid);
209 $this->assertSame($expected, $result);
210 }
211
212 }