369d997a811218af62710df33d3ab3843e17a769
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Log / LogManagerTest.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 * (c) 2011-2013 Steffen Gebert (steffen.gebert@typo3.org)
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Testcase for \TYPO3\CMS\Core\Log\LogManager.
30 *
31 * @author Ingo Renner <ingo@typo3.org>
32 * @author Steffen Gebert <steffen.gebert@typo3.org>
33 */
34 class LogManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * @var \TYPO3\CMS\Core\Log\LogManager
38 */
39 protected $logManagerInstance = NULL;
40
41 public function setUp() {
42 $this->logManagerInstance = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
43 }
44
45 public function tearDown() {
46 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager')->reset();
47 parent::tearDown();
48 }
49
50 /**
51 * @test
52 */
53 public function logManagerReturnsLoggerWhenRequestedWithGetLogger() {
54 $this->assertInstanceOf('TYPO3\\CMS\\Core\\Log\\Logger', $this->logManagerInstance->getLogger('test'));
55 }
56
57 /**
58 * @test
59 */
60 public function logManagerTurnsUnderScoreStyleLoggerNamesIntoDotStyleLoggerNames() {
61 $this->assertSame('test.a.b', $this->logManagerInstance->getLogger('test_a_b')->getName());
62 }
63
64 /**
65 * @test
66 */
67 public function logManagerTurnsNamespaceStyleLoggerNamesIntoDotStyleLoggerNames() {
68 $this->assertSame('test.a.b', $this->logManagerInstance->getLogger('test\\a\\b')->getName());
69 }
70
71 /**
72 * @test
73 */
74 public function managerReturnsSameLoggerOnRepeatedRequest() {
75 $loggerName = uniqid('test.core.log');
76 $this->logManagerInstance->registerLogger($loggerName);
77 $logger1 = $this->logManagerInstance->getLogger($loggerName);
78 $logger2 = $this->logManagerInstance->getLogger($loggerName);
79 $this->assertSame($logger1, $logger2);
80 }
81
82 /**
83 * @test
84 */
85 public function configuresLoggerWithConfiguredWriter() {
86 $component = 'test';
87 $writer = 'TYPO3\\CMS\\Core\\Log\\Writer\\NullWriter';
88 $level = \TYPO3\CMS\Core\Log\LogLevel::DEBUG;
89 $GLOBALS['TYPO3_CONF_VARS']['LOG'][$component]['writerConfiguration'] = array(
90 $level => array(
91 $writer => array()
92 )
93 );
94 /** @var $logger \TYPO3\CMS\Core\Log\Logger */
95 $logger = $this->logManagerInstance->getLogger($component);
96 $writers = $logger->getWriters();
97 $this->assertInstanceOf($writer, $writers[$level][0]);
98 }
99
100 /**
101 * @test
102 */
103 public function configuresLoggerWithConfiguredProcessor() {
104 $component = 'test';
105 $processor = 'TYPO3\\CMS\\Core\\Log\\Processor\\NullProcessor';
106 $level = \TYPO3\CMS\Core\Log\LogLevel::DEBUG;
107 $GLOBALS['TYPO3_CONF_VARS']['LOG'][$component]['processorConfiguration'] = array(
108 $level => array(
109 $processor => array()
110 )
111 );
112 /** @var $logger \TYPO3\CMS\Core\Log\Logger */
113 $logger = $this->logManagerInstance->getLogger($component);
114 $processors = $logger->getProcessors();
115 $this->assertInstanceOf($processor, $processors[$level][0]);
116 }
117
118 }