a29867c960b476ae6706a9546598d2fd41baf3c2
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Uri / TypolinkViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Uri;
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\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Class TypolinkViewHelperTest
22 */
23 class TypolinkViewHelperTest extends ViewHelperBaseTestcase {
24
25 /**
26 * @return array
27 */
28 public function typoScriptConfigurationData() {
29 return array(
30 'empty input' => array(
31 '', // input from link field
32 '', // additional parameters from fluid
33 array(), //expected typolink Array
34 '' // expected URI
35 ),
36 'simple id input' => array(
37 19,
38 '',
39 array(
40 0 => '"19"',
41 ),
42 'index.php?id=19'
43 ),
44 'external url with target' => array(
45 'www.web.de _blank',
46 '',
47 array(
48 0 => '"www.web.de"',
49 1 => '"_blank"',
50 ),
51 'http://www.web.de'
52 ),
53 'page with class' => array(
54 '42 - css-class',
55 '',
56 array(
57 0 => '"42"',
58 1 => '-',
59 2 => '"css-class"',
60 ),
61 "index.php?id=42"
62 ),
63 'page with title' => array(
64 '42 - - "a link title"',
65 '',
66 array(
67 0 => '"42"',
68 1 => '-',
69 2 => '-',
70 3 => '"a link title"'
71 ),
72 "index.php?id=42"
73 ),
74 'page with title and parameters' => array(
75 '42 - - "a link title" &x=y',
76 '',
77 array(
78 0 => '"42"',
79 1 => '-',
80 2 => '-',
81 3 => '"a link title"',
82 4 => '"&x=y"',
83 ),
84 "index.php?id=42&x=y"
85 ),
86 'page with title and extended parameters' => array(
87 '42 - - "a link title" &x=y',
88 '&a=b',
89 array(
90 0 => '"42"',
91 1 => '-',
92 2 => '-',
93 3 => '"a link title"',
94 4 => '"&x=y&a=b"',
95 ),
96 "index.php?id=42&x=y&a=b"
97 ),
98 'full parameter usage' => array(
99 '19 _blank css-class "testtitle with whitespace" &X=y',
100 '&a=b',
101 array(
102 0 => '"19"',
103 1 => '"_blank"',
104 2 => '"css-class"',
105 3 => '"testtitle with whitespace"',
106 4 => '"&X=y&a=b"',
107 ),
108 "index.php?id=19&X=y&a=b"
109 ),
110 'only page id and overwrite' => array(
111 '42',
112 '&a=b',
113 array(
114 0 => '"42"',
115 1 => '-',
116 2 => '-',
117 3 => '-',
118 4 => '"&a=b"',
119 ),
120 "index.php?id=42&a=b"
121 ),
122 'email' => array(
123 'a@b.tld',
124 '',
125 array(
126 '"a@b.tld"',
127 ),
128 'mailto:a@b.tld'
129 ),
130 );
131 }
132
133 /**
134 * @test
135 * @dataProvider typoScriptConfigurationData
136 */
137 public function createTypolinkParameterArrayFromArgumentsReturnsExpectedArray($input, $additionalParametersFromFluid, $expected) {
138 /** @var \TYPO3\CMS\Fluid\ViewHelpers\Uri\TypolinkViewHelper|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
139 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Uri\\TypolinkViewHelper', array('dummy'));
140 $result = $subject->_call('createTypolinkParameterArrayFromArguments', $input, $additionalParametersFromFluid);
141 $this->assertSame($expected, $result);
142 }
143 }