[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / LinkHandling / PageLinkHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\LinkHandling;
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\LinkHandling\PageLinkHandler;
18
19 class PageLinkHandlerTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
20 {
21
22 /**
23 * Data to resolve strings to arrays and vice versa, external, mail, page
24 *
25 * @return array
26 */
27 public function resolveParametersForNonFilesDataProvider()
28 {
29 return [
30 'current page - cool style' => [
31 [
32 'uid' => 'current'
33 ],
34 [
35 'pageuid' => 'current'
36 ],
37 't3://page?uid=current'
38 ],
39 'current empty page - cool style' => [
40 [
41
42 ],
43 [
44 'pageuid' => 'current'
45 ],
46 't3://page?uid=current'
47 ],
48 'simple page - cool style' => [
49 [
50 'uid' => 13
51 ],
52 [
53 'pageuid' => 13
54 ],
55 't3://page?uid=13'
56 ],
57 'page with alias - cool style' => [
58 [
59 'alias' => 'alias13'
60 ],
61 [
62 'pagealias' => 'alias13'
63 ],
64 't3://page?alias=alias13'
65 ],
66 'page with alias and type - cool style' => [
67 [
68 'alias' => 'alias13',
69 'type' => 31
70 ],
71 [
72 'pagealias' => 'alias13',
73 'pagetype' => '31'
74 ],
75 't3://page?alias=alias13&type=31'
76 ],
77 'page with alias and parameters - cool style' => [
78 [
79 'alias' => 'alias13',
80 'my' => 'additional',
81 'parameter' => 'that',
82 'are' => 'nice'
83 ],
84 [
85 'pagealias' => 'alias13',
86 'parameters' => 'my=additional&parameter=that&are=nice'
87 ],
88 't3://page?alias=alias13&my=additional&parameter=that&are=nice',
89 ],
90 'page with alias and parameters and fragment - cool style' => [
91 [
92 'alias' => 'alias13',
93 'my' => 'additional',
94 'parameter' => 'that',
95 'are' => 'nice'
96 ],
97 [
98 'pagealias' => 'alias13',
99 'parameters' => 'my=additional&parameter=that&are=nice',
100 'fragment' => 'again'
101 ],
102 't3://page?alias=alias13&my=additional&parameter=that&are=nice#again',
103 ]
104 ];
105 }
106
107 /**
108 * @test
109 *
110 * @param string $input
111 * @param array $expected
112 * @param string $finalString
113 *
114 * @dataProvider resolveParametersForNonFilesDataProvider
115 */
116 public function resolveReturnsSplitParameters($input, $expected, $finalString)
117 {
118 $subject = new PageLinkHandler();
119 // fragment it is processed outside handler data
120 if (isset($expected['fragment'])) {
121 unset($expected['fragment']);
122 }
123 $this->assertEquals($expected, $subject->resolveHandlerData($input));
124 }
125
126 /**
127 * @test
128 *
129 * @param string $input
130 * @param array $parameters
131 * @param string $expected
132 *
133 * @dataProvider resolveParametersForNonFilesDataProvider
134 */
135 public function splitParametersToUnifiedIdentifier($input, $parameters, $expected)
136 {
137 $subject = new PageLinkHandler();
138 $this->assertEquals($expected, $subject->asString($parameters));
139 }
140 }