[BUGFIX] Failing test in VersionNumberUtility
[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 * Copyright notice
6 *
7 * (c) 2011-2013 Susanne Moog <typo3@susanne-moog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use \TYPO3\CMS\Core\Utility\VersionNumberUtility;
28
29 /**
30 * Testcase for class \TYPO3\CMS\Core\Utility\VersionNumberUtility
31 *
32 * @author Susanne Moog <typo3@susanne-moog.de>
33 */
34 class VersionNumberUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * Data Provider for convertVersionNumberToIntegerConvertsVersionNumbersToIntegers
38 *
39 * @return array
40 */
41 public function validVersionNumberDataProvider() {
42 return array(
43 array('4003003', '4.3.3'),
44 array('4012003', '4.12.3'),
45 array('5000000', '5.0.0'),
46 array('3008001', '3.8.1'),
47 array('1012', '0.1.12')
48 );
49 }
50
51 /**
52 * Data Provider for convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber
53 *
54 * @see http://php.net/manual/en/language.types.php
55 * @return array
56 */
57 public function invalidVersionNumberDataProvider() {
58 return array(
59 'boolean' => array(TRUE),
60 'float' => array(5.4),
61 'array' => array(array()),
62 'string' => array('300ABCD'),
63 'object' => array(new \stdClass()),
64 'NULL' => array(NULL),
65 'function' => array(function () {
66
67 })
68 );
69 }
70
71 /**
72 * @test
73 * @dataProvider validVersionNumberDataProvider
74 */
75 public function convertVersionNumberToIntegerConvertsVersionNumbersToIntegers($expected, $version) {
76 $this->assertEquals($expected, VersionNumberUtility::convertVersionNumberToInteger($version));
77 }
78
79 /**
80 * @test
81 * @dataProvider validVersionNumberDataProvider
82 */
83 public function convertIntegerToVersionNumberConvertsIntegerToVersionNumber($versionNumber, $expected) {
84 // Make sure incoming value is an integer
85 $versionNumber = (int) $versionNumber;
86 $this->assertEquals($expected, VersionNumberUtility::convertIntegerToVersionNumber($versionNumber));
87 }
88
89 /**
90 * @test
91 * @dataProvider invalidVersionNumberDataProvider
92 */
93 public function convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber($version) {
94 $this->setExpectedException('\\InvalidArgumentException', '', 1334072223);
95 VersionNumberUtility::convertIntegerToVersionNumber($version);
96 }
97
98 /**
99 * @return array
100 */
101 public function getNumericTypo3VersionNumberDataProvider() {
102 return array(
103 array(
104 '6.0-dev',
105 '6.0.0'
106 ),
107 array(
108 '4.5-alpha',
109 '4.5.0'
110 ),
111 array(
112 '4.5-beta',
113 '4.5.0'
114 ),
115 array(
116 '4.5-RC',
117 '4.5.0'
118 ),
119 array(
120 '6.0.1',
121 '6.0.1'
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 $className = uniqid('VersionNumberUtility');
137 eval(
138 'namespace ' . __NAMESPACE__ . ';' .
139 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\VersionNumberUtility {' .
140 ' public static function getCurrentTypo3Version() {' .
141 ' return \'' . $currentVersion . '\';' .
142 ' }' .
143 '}'
144 );
145 $className = __NAMESPACE__ . '\\' . $className;
146 $this->assertEquals($expectedVersion, $className::getNumericTypo3Version());
147 }
148
149 /**
150 * Data provider for convertVersionsStringToVersionNumbersForcesVersionNumberInRange
151 *
152 * @return array
153 */
154 public function convertVersionsStringToVersionNumbersForcesVersionNumberInRangeDataProvider() {
155 return array(
156 'everything ok' => array(
157 '4.2.0-4.4.99',
158 array(
159 '4.2.0',
160 '4.4.99'
161 )
162 ),
163 'too high value' => array(
164 '4.2.0-4.4.2990',
165 array(
166 '4.2.0',
167 '4.4.999'
168 )
169 ),
170 'empty high value' => array(
171 '4.2.0-0.0.0',
172 array(
173 '4.2.0',
174 ''
175 )
176 )
177 );
178 }
179
180 /**
181 * @test
182 * @dataProvider convertVersionsStringToVersionNumbersForcesVersionNumberInRangeDataProvider
183 */
184 public function convertVersionsStringToVersionNumbersForcesVersionNumberInRange($versionString, $expectedResult) {
185 $versions = VersionNumberUtility::convertVersionsStringToVersionNumbers($versionString);
186 $this->assertEquals($expectedResult, $versions);
187 }
188 }