Added feature #9876: Provide $severity in t3lib_div::sysLog() Hook (Thanks to Michael...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_div_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
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 /**
27 * Testcase for class t3lib_div
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_div_testcase extends tx_phpunit_testcase {
34
35 /**
36 * @test
37 */
38 public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() {
39 $testString = ' a , b , c ,d ,, e,f,';
40 $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', '');
41 $actualArray = t3lib_div::trimExplode(',', $testString);
42
43 $this->assertEquals($expectedArray, $actualArray);
44 }
45
46 /**
47 * @test
48 */
49 public function checkTrimExplodeRemovesNewLines() {
50 $testString = ' a , b , ' . chr(10) . ' ,d ,, e,f,';
51 $expectedArray = array('a', 'b', 'd', 'e', 'f');
52 $actualArray = t3lib_div::trimExplode(',', $testString, true);
53
54 $this->assertEquals($expectedArray, $actualArray);
55 }
56
57 /**
58 * @test
59 */
60 public function checkTrimExplodeRemovesEmptyElements() {
61 $testString = 'a , b , c , ,d ,, ,e,f,';
62 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f');
63 $actualArray = t3lib_div::trimExplode(',', $testString, true);
64
65 $this->assertEquals($expectedArray, $actualArray);
66 }
67
68 /**
69 * @test
70 */
71 public function checkTrimExplodeLimitsResultsToFirstXElementsWithPositiveParameter() {
72 $testString = ' a , b , c , , d,, ,e ';
73 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
74 $actualArray = t3lib_div::trimExplode(',', $testString, false, 3);
75
76 $this->assertEquals($expectedArray, $actualArray);
77 }
78
79 /**
80 * @test
81 */
82 public function checkTrimExplodeLimitsResultsToLastXElementsWithNegativeParameter() {
83 $testString = ' a , b , c , d, ,e, f , , ';
84 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
85 $actualArray = t3lib_div::trimExplode(',', $testString, true, -3);
86
87 $this->assertEquals($expectedArray, $actualArray);
88 }
89
90 /**
91 * @test
92 */
93 public function checkTrimExplodeKeepsZeroAsString() {
94 $testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
95 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
96 $actualArray = t3lib_div::trimExplode(',', $testString, true);
97
98 $this->assertEquals($expectedArray, $actualArray);
99 }
100
101 /**
102 * Checks whether measurement strings like "100k" return the accordant
103 * byte representation like 102400 in this case.
104 *
105 * @test
106 */
107 public function checkGetBytesFromSizeMeasurement() {
108 $this->assertEquals(
109 '102400',
110 t3lib_div::getBytesFromSizeMeasurement('100k')
111 );
112
113 $this->assertEquals(
114 '104857600',
115 t3lib_div::getBytesFromSizeMeasurement('100m')
116 );
117
118 $this->assertEquals(
119 '107374182400',
120 t3lib_div::getBytesFromSizeMeasurement('100g')
121 );
122 }
123
124 /**
125 * @test
126 */
127 public function checkIndpEnvTypo3SitePathNotEmpty() {
128 $actualEnv = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
129 $this->assertTrue(strlen($actualEnv) >= 1);
130 $this->assertEquals('/', $actualEnv{0});
131 $this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1});
132 }
133 }
134
135 ?>