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