[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / VersionNumberUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
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\Unit\Utility\Fixtures\VersionNumberUtilityFixture;
18 use TYPO3\CMS\Core\Utility\VersionNumberUtility;
19
20 /**
21 * Testcase for class \TYPO3\CMS\Core\Utility\VersionNumberUtility
22 */
23 class VersionNumberUtilityTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * Data Provider for convertVersionNumberToIntegerConvertsVersionNumbersToIntegers
27 *
28 * @return array
29 */
30 public function validVersionNumberDataProvider()
31 {
32 return [
33 ['4003003', '4.3.3'],
34 ['4012003', '4.12.3'],
35 ['5000000', '5.0.0'],
36 ['5000001', '5.0.1'],
37 ['3008001', '3.8.1'],
38 ['1012', '0.1.12']
39 ];
40 }
41
42 /**
43 * Data Provider for convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber
44 *
45 * @see http://php.net/manual/en/language.types.php
46 * @return array
47 */
48 public function invalidVersionNumberDataProvider()
49 {
50 return [
51 'boolean' => [true],
52 'float' => [5.4],
53 'array' => [[]],
54 'string' => ['300ABCD'],
55 'object' => [new \stdClass()],
56 'NULL' => [null],
57 'function' => [function () {
58 }]
59 ];
60 }
61
62 /**
63 * @test
64 * @dataProvider validVersionNumberDataProvider
65 */
66 public function convertVersionNumberToIntegerConvertsVersionNumbersToIntegers($expected, $version)
67 {
68 $this->assertEquals($expected, VersionNumberUtility::convertVersionNumberToInteger($version));
69 }
70
71 /**
72 * @test
73 * @dataProvider validVersionNumberDataProvider
74 */
75 public function convertIntegerToVersionNumberConvertsIntegerToVersionNumber($versionNumber, $expected)
76 {
77 // Make sure incoming value is an integer
78 $versionNumber = (int)$versionNumber;
79 $this->assertEquals($expected, VersionNumberUtility::convertIntegerToVersionNumber($versionNumber));
80 }
81
82 /**
83 * @test
84 * @dataProvider invalidVersionNumberDataProvider
85 */
86 public function convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber($version)
87 {
88 $this->expectException(\InvalidArgumentException::class);
89 $this->expectExceptionCode(1334072223);
90 VersionNumberUtility::convertIntegerToVersionNumber($version);
91 }
92
93 /**
94 * @return array
95 */
96 public function getNumericTypo3VersionNumberDataProvider()
97 {
98 return [
99 [
100 '6.0-dev',
101 '6.0.0'
102 ],
103 [
104 '4.5-alpha',
105 '4.5.0'
106 ],
107 [
108 '4.5-beta',
109 '4.5.0'
110 ],
111 [
112 '4.5-RC',
113 '4.5.0'
114 ],
115 [
116 '6.0.1',
117 '6.0.1'
118 ],
119 [
120 '6.2.0beta5',
121 '6.2.0'
122 ],
123 ];
124 }
125
126 /**
127 * Check whether getNumericTypo3Version handles all kinds of valid
128 * version strings
129 *
130 * @dataProvider getNumericTypo3VersionNumberDataProvider
131 * @test
132 * @param string $currentVersion
133 * @param string $expectedVersion
134 */
135 public function getNumericTypo3VersionNumber($currentVersion, $expectedVersion)
136 {
137 VersionNumberUtilityFixture::$versionNumber = $currentVersion;
138 $this->assertEquals($expectedVersion, VersionNumberUtilityFixture::getNumericTypo3Version());
139 }
140
141 /**
142 * Data provider for convertVersionsStringToVersionNumbersForcesVersionNumberInRange
143 *
144 * @return array
145 */
146 public function convertVersionsStringToVersionNumbersForcesVersionNumberInRangeDataProvider()
147 {
148 return [
149 'everything ok' => [
150 '4.2.0-4.4.99',
151 [
152 '4.2.0',
153 '4.4.99'
154 ]
155 ],
156 'too high value' => [
157 '4.2.0-4.4.2990',
158 [
159 '4.2.0',
160 '4.4.999'
161 ]
162 ],
163 'empty high value' => [
164 '4.2.0-0.0.0',
165 [
166 '4.2.0',
167 ''
168 ]
169 ]
170 ];
171 }
172
173 /**
174 * @test
175 * @dataProvider convertVersionsStringToVersionNumbersForcesVersionNumberInRangeDataProvider
176 */
177 public function convertVersionsStringToVersionNumbersForcesVersionNumberInRange($versionString, $expectedResult)
178 {
179 $versions = VersionNumberUtility::convertVersionsStringToVersionNumbers($versionString);
180 $this->assertEquals($expectedResult, $versions);
181 }
182 }