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