[FEATURE] Add method to convert integer to version number
[Packages/TYPO3.CMS.git] / tests / t3lib / utility / class.t3lib_utility_versionNumberTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Susanne Moog <typo3@susanne-moog.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class t3lib_utility_VersionNumber
27 *
28 * @author Susanne Moog <typo3@susanne-moog.de>
29 * @package TYPO3
30 * @subpackage t3lib
31 */
32 class t3lib_utility_VersionNumberTest extends tx_phpunit_testcase {
33
34 /**
35 * Data Provider for convertVersionNumberToIntegerConvertsVersionNumbersToIntegers
36 *
37 * return array
38 */
39 public function validVersionNumberDataProvider() {
40 return array(
41 array('4003003', '4.3.3'),
42 array('4012003', '4.12.3'),
43 array('5000000', '5.0.0'),
44 array('3008001', '3.8.1'),
45 array('1012', '0.1.12')
46 );
47 }
48
49 /**
50 * Data Provider for convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber
51 *
52 * @see http://php.net/manual/en/language.types.php
53 * return array
54 */
55 public function invalidVersionNumberDataProvider() {
56 return array(
57 'boolean' => array(TRUE),
58 'float' => array(5.4),
59 'array' => array(array()),
60 'string' => array('300ABCD'),
61 'object' => array(new stdClass()),
62 'NULL' => array(NULL),
63 'function' => array(function(){}),
64 );
65 }
66
67 /**
68 * @test
69 * @dataProvider validVersionNumberDataProvider
70 */
71 public function convertVersionNumberToIntegerConvertsVersionNumbersToIntegers($expected, $version) {
72 $this->assertEquals($expected, t3lib_utility_VersionNumber::convertVersionNumberToInteger($version));
73 }
74
75 /**
76 * @test
77 * @dataProvider validVersionNumberDataProvider
78 */
79 public function convertIntegerToVersionNumberConvertsIntegerToVersionNumber($versionNumber, $expected) {
80 // Make sure incoming value is an integer
81 $versionNumber = (int) $versionNumber;
82 $this->assertEquals($expected, t3lib_utility_VersionNumber::convertIntegerToVersionNumber($versionNumber));
83 }
84
85 /**
86 * @test
87 * @dataProvider invalidVersionNumberDataProvider
88 */
89 public function convertIntegerToVersionNumberConvertsOtherTypesAsIntegerToVersionNumber($version) {
90 $this->setExpectedException('\InvalidArgumentException', '', 1334072223);
91 t3lib_utility_VersionNumber::convertIntegerToVersionNumber($version);
92 }
93 }
94
95 ?>