TYPO3  7.6
TypoLinkCodecServiceTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Service;
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\Tests\UnitTestCase;
19 
23 class TypoLinkCodecServiceTest extends UnitTestCase
24 {
28  protected $subject;
29 
33  protected function setUp()
34  {
35  $this->subject = new TypoLinkCodecService();
36  }
37 
44  public function encodeReturnsExpectedResult(array $parts, $expected)
45  {
46  $this->assertSame($expected, $this->subject->encode($parts));
47  }
48 
53  {
54  return [
55  'empty input' => [
56  [
57  'url' => '',
58  'target' => '',
59  'class' => '',
60  'title' => '',
61  'additionalParams' => ''
62  ],
63  ''
64  ],
65  'full parameter usage' => [
66  [
67  'url' => '19',
68  'target' => '_blank',
69  'class' => 'css-class',
70  'title' => 'testtitle with whitespace',
71  'additionalParams' => '&x=y'
72  ],
73  '19 _blank css-class "testtitle with whitespace" &x=y'
74  ],
75  'crazy title and partial items only' => [
76  [
77  'url' => 'foo',
78  'title' => 'a "link\\ ti\\"tle',
79  ],
80  'foo - - "a \\"link\\\\ ti\\\\\\"tle"'
81  ]
82  ];
83  }
84 
91  public function decodeReturnsExpectedResult($typoLink, array $expected)
92  {
93  $this->assertSame($expected, $this->subject->decode($typoLink));
94  }
95 
100  {
101  return [
102  'empty input' => [
103  '',
104  [
105  'url' => '',
106  'target' => '',
107  'class' => '',
108  'title' => '',
109  'additionalParams' => ''
110  ],
111  ],
112  'simple id input' => [
113  '19',
114  [
115  'url' => '19',
116  'target' => '',
117  'class' => '',
118  'title' => '',
119  'additionalParams' => ''
120  ],
121  ],
122  'external url with target' => [
123  'www.web.de _blank',
124  [
125  'url' => 'www.web.de',
126  'target' => '_blank',
127  'class' => '',
128  'title' => '',
129  'additionalParams' => ''
130  ],
131  ],
132  'page with class' => [
133  '42 - css-class',
134  [
135  'url' => '42',
136  'target' => '',
137  'class' => 'css-class',
138  'title' => '',
139  'additionalParams' => ''
140  ],
141  ],
142  'page with title' => [
143  '42 - - "a link title"',
144  [
145  'url' => '42',
146  'target' => '',
147  'class' => '',
148  'title' => 'a link title',
149  'additionalParams' => ''
150  ],
151  ],
152  'page with crazy title' => [
153  '42 - - "a \\"link\\\\ ti\\\\\\"tle"',
154  [
155  'url' => '42',
156  'target' => '',
157  'class' => '',
158  'title' => 'a "link\\ ti\\"tle',
159  'additionalParams' => ''
160  ],
161  ],
162  'page with title and parameters' => [
163  '42 - - "a link title" &x=y',
164  [
165  'url' => '42',
166  'target' => '',
167  'class' => '',
168  'title' => 'a link title',
169  'additionalParams' => '&x=y'
170  ],
171  ],
172  'page with complex title' => [
173  '42 - - "a \\"link\\" title with \\\\" &x=y',
174  [
175  'url' => '42',
176  'target' => '',
177  'class' => '',
178  'title' => 'a "link" title with \\',
179  'additionalParams' => '&x=y'
180  ],
181  ],
182  'full parameter usage' => [
183  '19 _blank css-class "testtitle with whitespace" &X=y',
184  [
185  'url' => '19',
186  'target' => '_blank',
187  'class' => 'css-class',
188  'title' => 'testtitle with whitespace',
189  'additionalParams' => '&X=y'
190  ],
191  ],
192  ];
193  }
194 }