[TASK] Convert log levels from string to integer
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Log / LogLevelTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Log;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Ingo Renner (ingo@typo3.org)
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 /**
28 * Testcase for \TYPO3\CMS\Core\Log\Level.
29 *
30 * @author Ingo Renner <ingo@typo3.org>
31 */
32 class LevelTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @test
36 */
37 public function isValidLevelValidatesValidLevels() {
38 $validLevels = array(0, 1, 2, 3, 4, 5, 6, 7);
39 foreach ($validLevels as $validLevel) {
40 $this->assertTrue(\TYPO3\CMS\Core\Log\LogLevel::isValidLevel($validLevel));
41 }
42 }
43
44 /**
45 * @test
46 */
47 public function isValidLevelDoesNotValidateInvalidLevels() {
48 $invalidLevels = array(-1, 8, 1.5, 'string', array(), new \stdClass(), FALSE, NULL);
49 foreach ($invalidLevels as $invalidLevel) {
50 $this->assertFalse(\TYPO3\CMS\Core\Log\LogLevel::isValidLevel($invalidLevel));
51 }
52 }
53
54 /**
55 * Data provider or isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo
56 */
57 public function isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider() {
58 return array(
59 'negative integer' => array(-1),
60 'higher level than expected' => array(8),
61 'float' => array(1.5),
62 'string' => array('string'),
63 'array' => array(array()),
64 'object' => array(new \stdClass()),
65 'boolean FALSE' => array(FALSE),
66 'NULL' => array(NULL)
67 );
68 }
69
70 /**
71 * @test
72 * @dataProvider isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider
73 * @expectedException \RangeException
74 */
75 public function isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo($inputValue) {
76 \TYPO3\CMS\Core\Log\LogLevel::validateLevel($inputValue);
77 }
78
79 /**
80 * @test
81 */
82 public function normalizeLevelConvertsValidLevelFromStringToInteger() {
83 $this->assertEquals(7, \TYPO3\CMS\Core\Log\LogLevel::normalizeLevel('debug'));
84 }
85
86 /**
87 * @test
88 */
89 public function normalizeLevelDoesNotConvertInvalidLevel() {
90 $levelString = 'invalid';
91 $this->assertEquals($levelString, \TYPO3\CMS\Core\Log\LogLevel::normalizeLevel($levelString));
92 }
93 }
94
95 ?>