TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Link/TypolinkViewHelperTest.php
Go to the documentation of this file.
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  */
21 
26 {
30  protected $subject;
31 
35  protected function setUp()
36  {
37  $this->subject = $this->getAccessibleMock(TypolinkViewHelper::class, ['renderChildren']);
39  $renderingContext = $this->createMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class);
40  $this->subject->setRenderingContext($renderingContext);
41  }
42 
47  {
48  $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent'));
49  $this->subject->setArguments([
50  'parameter' => '42',
51  'target' => '',
52  'class' => '',
53  'title' => '',
54  'additionalParams' => '',
55  'additionalAttributes' => [],
56  ]);
57  $contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
58  $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo'));
59  GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererMock);
60  $this->assertEquals('foo', $this->subject->render());
61  }
62 
66  public function typoScriptConfigurationData()
67  {
68  return [
69  'empty input' => [
70  '', // input from link field
71  '', // target from fluid
72  '', // class from fluid
73  '', // title from fluid
74  '', // additional parameters from fluid
75  '',
76  ],
77  'simple id input' => [
78  19,
79  '',
80  '',
81  '',
82  '',
83  '19',
84  ],
85  'external url with target' => [
86  'www.web.de _blank',
87  '',
88  '',
89  '',
90  '',
91  'www.web.de _blank',
92  ],
93  'page with extended class' => [
94  '42 - css-class',
95  '',
96  'fluid_class',
97  '',
98  '',
99  '42 - "css-class fluid_class"',
100  ],
101  'classes are unique' => [
102  '42 - css-class',
103  '',
104  'css-class',
105  '',
106  '',
107  '42 - css-class',
108  ],
109  'page with overridden title' => [
110  '42 - - "a link title"',
111  '',
112  '',
113  'another link title',
114  '',
115  '42 - - "another link title"',
116  ],
117  'page with title and extended parameters' => [
118  '42 - - "a link title" &x=y',
119  '',
120  '',
121  '',
122  '&a=b',
123  '42 - - "a link title" &x=y&a=b',
124  ],
125  'page with complex title and extended parameters' => [
126  '42 - - "a \\"link\\" title with \\\\" &x=y',
127  '',
128  '',
129  '',
130  '&a=b',
131  '42 - - "a \\"link\\" title with \\\\" &x=y&a=b',
132  ],
133  'full parameter usage' => [
134  '19 _blank css-class "testtitle with whitespace" &X=y',
135  '-',
136  'fluid_class',
137  'a new title',
138  '&a=b',
139  '19 - "css-class fluid_class" "a new title" &X=y&a=b',
140  ],
141  'only page id and overwrite' => [
142  '42',
143  '',
144  '',
145  '',
146  '&a=b',
147  '42 - - - &a=b',
148  ],
149  ];
150  }
151 
162  public function createTypolinkParameterArrayFromArgumentsReturnsExpectedArray($input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid, $expected)
163  {
164  $result = $this->subject->_call('createTypolinkParameterArrayFromArguments', $input, $targetFromFluid, $classFromFluid, $titleFromFluid, $additionalParametersFromFluid);
165  $this->assertSame($expected, $result);
166  }
167 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static addInstance($className, $instance)