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