mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
parent
3555e66018
commit
031c91ce4a
@ -27,170 +27,63 @@
|
|||||||
*/
|
*/
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Tests\Icinga\Application;
|
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use \Zend_Config;
|
|
||||||
use Icinga\Application\Logger;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
use Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
/**
|
// @codingStandardsIgnoreStart
|
||||||
* Test class for Logger
|
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||||
*
|
// @codingStandardsIgnoreEnd
|
||||||
* @backupStaticAttributes enabled
|
|
||||||
**/
|
use \Zend_Config;
|
||||||
|
use Icinga\Logger\Logger;
|
||||||
|
|
||||||
class LoggerTest extends BaseTestCase
|
class LoggerTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
private $tempDir;
|
/**
|
||||||
|
* @backupStaticAttributes enabled
|
||||||
private $logTarget;
|
*/
|
||||||
|
public function testLogfileCreation()
|
||||||
private $debugTarget;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
{
|
||||||
$this->tempDir = tempnam(sys_get_temp_dir(), 'icingaweb-log');
|
$target = tempnam(sys_get_temp_dir(), 'log');
|
||||||
unlink($this->tempDir); // tempnam create the file automatically
|
unlink($target);
|
||||||
|
Logger::create(
|
||||||
if (!is_dir($this->tempDir)) {
|
new Zend_Config(
|
||||||
mkdir($this->tempDir, 0755);
|
array(
|
||||||
}
|
'enable' => true,
|
||||||
|
'level' => Logger::$ERROR,
|
||||||
$this->debugTarget = $this->tempDir . '/debug.log';
|
'type' => 'stream',
|
||||||
$this->logTarget = $this->tempDir . '/application.log';
|
'target' => $target
|
||||||
|
)
|
||||||
$loggingConfigurationArray = array(
|
|
||||||
'enable' => 1,
|
|
||||||
'type' => 'stream',
|
|
||||||
'verbose' => 1,
|
|
||||||
'target' => $this->logTarget,
|
|
||||||
|
|
||||||
'debug' => array(
|
|
||||||
'enable' => 1,
|
|
||||||
'type' => 'stream',
|
|
||||||
'target' => $this->debugTarget
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$this->assertFileExists($target, 'Logger did not create the log file');
|
||||||
$loggingConfiguration = new Zend_Config($loggingConfigurationArray);
|
unlink($target);
|
||||||
|
|
||||||
Logger::reset();
|
|
||||||
Logger::create($loggingConfiguration);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
|
||||||
{
|
|
||||||
if (file_exists($this->debugTarget)) {
|
|
||||||
unlink($this->debugTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file_exists($this->logTarget)) {
|
|
||||||
unlink($this->logTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
rmdir($this->tempDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLogData()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
explode(PHP_EOL, file_get_contents($this->logTarget)),
|
|
||||||
explode(PHP_EOL, file_get_contents($this->debugTarget))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test error messages
|
* @backupStaticAttributes enabled
|
||||||
|
* @depends testLogfileCreation
|
||||||
*/
|
*/
|
||||||
public function testLoggingErrorMessages()
|
public function testLoggingErrorMessages()
|
||||||
{
|
{
|
||||||
Logger::error('test-error-1');
|
$target = tempnam(sys_get_temp_dir(), 'log');
|
||||||
Logger::error('test-error-2');
|
unlink($target);
|
||||||
|
Logger::create(
|
||||||
$this->assertFileExists($this->logTarget);
|
new Zend_Config(
|
||||||
$this->assertFileExists($this->debugTarget);
|
array(
|
||||||
|
'enable' => true,
|
||||||
list($main, $debug) = $this->getLogData();
|
'level' => Logger::$ERROR,
|
||||||
|
'type' => 'stream',
|
||||||
$this->assertCount(3, $main);
|
'target' => $target
|
||||||
$this->assertCount(3, $debug);
|
)
|
||||||
|
)
|
||||||
$this->assertContains(' ERR (3): test-error-1', $main[0]);
|
|
||||||
$this->assertContains(' ERR (3): test-error-2', $main[1]);
|
|
||||||
|
|
||||||
$this->assertContains(' ERR (3): test-error-1', $debug[0]);
|
|
||||||
$this->assertContains(' ERR (3): test-error-2', $debug[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test debug log and difference between error and debug messages
|
|
||||||
*/
|
|
||||||
public function testLoggingDebugMessages()
|
|
||||||
{
|
|
||||||
Logger::debug('test-debug-1');
|
|
||||||
Logger::error('test-error-1');
|
|
||||||
Logger::debug('test-debug-2');
|
|
||||||
|
|
||||||
$this->assertFileExists($this->logTarget);
|
|
||||||
$this->assertFileExists($this->debugTarget);
|
|
||||||
|
|
||||||
list($main, $debug) = $this->getLogData();
|
|
||||||
|
|
||||||
$this->assertCount(2, $main);
|
|
||||||
$this->assertCount(4, $debug);
|
|
||||||
|
|
||||||
$this->assertContains(' ERR (3): test-error-1', $main[0]);
|
|
||||||
|
|
||||||
$this->assertContains(' DEBUG (7): test-debug-1', $debug[0]);
|
|
||||||
$this->assertContains(' ERR (3): test-error-1', $debug[1]);
|
|
||||||
$this->assertContains(' DEBUG (7): test-debug-2', $debug[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoggingQueueIfNoWriterAvailable()
|
|
||||||
{
|
|
||||||
Logger::reset();
|
|
||||||
|
|
||||||
Logger::error('test-error-1');
|
|
||||||
Logger::debug('test-debug-1');
|
|
||||||
Logger::error('test-error-2');
|
|
||||||
|
|
||||||
list($main, $debug) = $this->getLogData();
|
|
||||||
|
|
||||||
$this->assertCount(1, $main);
|
|
||||||
$this->assertCount(1, $debug);
|
|
||||||
|
|
||||||
$this->assertTrue(Logger::hasErrorsOccurred());
|
|
||||||
|
|
||||||
$queue = Logger::getQueue();
|
|
||||||
|
|
||||||
$this->assertCount(3, $queue);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'test-error-1',
|
|
||||||
3
|
|
||||||
),
|
|
||||||
$queue[0]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'test-debug-1',
|
|
||||||
7
|
|
||||||
),
|
|
||||||
$queue[1]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'test-error-2',
|
|
||||||
3
|
|
||||||
),
|
|
||||||
$queue[2]
|
|
||||||
);
|
);
|
||||||
|
Logger::error('This is a test error');
|
||||||
|
$log = file_get_contents($target);
|
||||||
|
unlink($target);
|
||||||
|
$this->assertContains('This is a test error', $log, 'Log does not contain the error "This is a test error"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,12 @@ namespace Tests\Icinga\Authentication;
|
|||||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use Icinga\Application\Logger;
|
|
||||||
use \Icinga\Test\BaseTestCase;
|
use \Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
// @codingStandardsIgnoreStart
|
// @codingStandardsIgnoreStart
|
||||||
require_once 'Zend/Log.php';
|
require_once 'Zend/Log.php';
|
||||||
require_once 'Zend/Config.php';
|
require_once 'Zend/Config.php';
|
||||||
require_once BaseTestCase::$libDir . '/Application/Logger.php';
|
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||||
require_once BaseTestCase::$libDir . '/Authentication/Manager.php';
|
require_once BaseTestCase::$libDir . '/Authentication/Manager.php';
|
||||||
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
||||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||||
|
@ -14,7 +14,7 @@ require_once "Zend/Session.php";
|
|||||||
require_once "Zend/Log/Writer/Abstract.php";
|
require_once "Zend/Log/Writer/Abstract.php";
|
||||||
require_once "Zend/Log/Writer/Stream.php";
|
require_once "Zend/Log/Writer/Stream.php";
|
||||||
|
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Logger\Logger;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
class NotificationTest extends \PHPUnit_Framework_TestCase
|
class NotificationTest extends \PHPUnit_Framework_TestCase
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
/**
|
|
||||||
* This file is part of Icinga Web 2.
|
|
||||||
*
|
|
||||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
||||||
* Copyright (C) 2013 Icinga Development Team
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*
|
|
||||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
||||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
||||||
* @author Icinga Development Team <info@icinga.org>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
namespace Tests\Icinga\Regression;
|
|
||||||
|
|
||||||
use \Icinga\Test\BaseTestCase;
|
|
||||||
use \Icinga\Application\Logger;
|
|
||||||
use \Zend_Config;
|
|
||||||
|
|
||||||
require_once 'Zend/Log.php';
|
|
||||||
require_once 'Zend/Config.php';
|
|
||||||
require_once 'Zend/Log/Writer/Mock.php';
|
|
||||||
require_once 'Zend/Log/Writer/Null.php';
|
|
||||||
require_once 'Zend/Log/Filter/Priority.php';
|
|
||||||
|
|
||||||
require_once realpath(__DIR__ . '/../../../library/Icinga/Test/BaseTestCase.php');
|
|
||||||
require_once realpath(BaseTestCase::$libDir.'/Application/Logger.php');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bug 4595 : "If log disabled, default target (./var/log) is not writable / no path exist"
|
|
||||||
*
|
|
||||||
* This is caused because the logger ignored the 'enable' parameter
|
|
||||||
*/
|
|
||||||
class Regression4595 extends BaseTestCase {
|
|
||||||
|
|
||||||
public function testDisableLogging()
|
|
||||||
{
|
|
||||||
$cfg = new Zend_Config(
|
|
||||||
array(
|
|
||||||
'enable' => '0',
|
|
||||||
'type' => 'mock',
|
|
||||||
'target' => 'target2'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$logger = new Logger($cfg);
|
|
||||||
$writers = $logger->getWriters();
|
|
||||||
$this->assertEquals(0, count($writers), 'Assert that loggers aren\'t registered when "enable" is set to false');
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user