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