[BUGFIX] Avoid duplicated classes in typolink VH
[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\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
19 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
20 use TYPO3\CMS\Fluid\ViewHelpers\Link\TypolinkViewHelper;
21 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
22
23 /**
24 * Class TypolinkViewHelperTest
25 */
26 class TypolinkViewHelperTest extends ViewHelperBaseTestcase
27 {
28 /**
29 * @var TypolinkViewHelper|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
30 */
31 protected $subject;
32
33 /**
34 * @throws \InvalidArgumentException
35 */
36 protected function setUp()
37 {
38 $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, ['renderChildren']);
39 /** @var RenderingContext $renderingContext */
40 $renderingContext = $this->getMock(RenderingContext::class);
41 $this->subject->setRenderingContext($renderingContext);
42 }
43
44 /**
45 * @test
46 */
47 public function renderReturnsResultOfContentObjectRenderer()
48 {
49 $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
50 $contentObjectRendererMock = $this->getMock(ContentObjectRenderer::class, [], [], '', false);
51 $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
52 GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
53 $this->assertEquals('foo', $this->subject->render('42'));
54 }
55
56 /**
57 * @return array
58 */
59 public function typoScriptConfigurationData()
60 {
61 return [
62 'empty input' => [
63 '', // input from link field
64 '', // target from fluid
65 '', // class from fluid
66 '', // title from fluid
67 '', // additional parameters from fluid
68 '',
69 ],
70 'simple id input' => [
71 19,
72 '',
73 '',
74 '',
75 '',
76 '19',
77 ],
78 'external url with target' => [
79 'www.web.de _blank',
80 '',
81 '',
82 '',
83 '',
84 'www.web.de _blank',
85 ],
86 'page with extended class' => [
87 '42 - css-class',
88 '',
89 'fluid_class',
90 '',
91 '',
92 '42 - "css-class fluid_class"',
93 ],
94 'classes are unique' => [
95 '42 - css-class',
96 '',
97 'css-class',
98 '',
99 '',
100 '42 - css-class',
101 ],
102 'page with overridden title' => [
103 '42 - - "a link title"',
104 '',
105 '',
106 'another link title',
107 '',
108 '42 - - "another link title"',
109 ],
110 'page with title and extended parameters' => [
111 '42 - - "a link title" &x=y',
112 '',
113 '',
114 '',
115 '&a=b',
116 '42 - - "a link title" &x=y&a=b',
117 ],
118 'page with complex title and extended parameters' => [
119 '42 - - "a \\"link\\" title with \\\\" &x=y',
120 '',
121 '',
122 '',
123 '&a=b',
124 '42 - - "a \\"link\\" title with \\\\" &x=y&a=b',
125 ],
126 'full parameter usage' => [
127 '19 _blank css-class "testtitle with whitespace" &X=y',
128 '-',
129 'fluid_class',
130 'a new title',
131 '&a=b',
132 '19 - "css-class fluid_class" "a new title" &X=y&a=b',
133 ],
134 'only page id and overwrite' => [
135 '42',
136 '',
137 '',
138 '',
139 '&a=b',
140 '42 - - - &a=b',
141 ],
142 ];
143 }
144
145 /**
146 * @test
147 * @dataProvider typoScriptConfigurationData
148 * @param string $input
149 * @param string $targetFromFluid
150 * @param string $classFromFluid
151 * @param string $titleFromFluid
152 * @param string $additionalParametersFromFluid
153 * @param string $expected
154 */
155 public function createTypolinkParameterArrayFromArgumentsReturnsExpectedArray($input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid, $expected)
156 {
157 $result = $this->subject->_call('createTypolinkParameterArrayFromArguments', $input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid);
158 $this->assertSame($expected, $result);
159 }
160 }