2008-05-05 22:15:32 +01:00
|
|
|
<?php
|
|
|
|
|
2019-06-18 19:02:40 +01:00
|
|
|
/**
|
|
|
|
* XMPPHP: The PHP XMPP Library
|
|
|
|
* Copyright (C) 2008 Nathanael C. Fritz
|
|
|
|
* This file is part of SleekXMPP.
|
|
|
|
*
|
|
|
|
* XMPPHP 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.
|
|
|
|
*
|
|
|
|
* XMPPHP 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 XMPPHP; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* @category xmpphp
|
|
|
|
* @package XMPPHP
|
|
|
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
|
|
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
|
|
|
* @author Michael Garvin <JID: gar@netflint.net>
|
|
|
|
* @copyright 2008 Nathanael C. Fritz
|
|
|
|
*/
|
2008-05-05 22:15:32 +01:00
|
|
|
|
2019-06-18 19:02:40 +01:00
|
|
|
/** XMPPHP_Log */
|
|
|
|
require_once CLASS_DIR . 'XMPPHP' . DIRECTORY_SEPARATOR . 'Log.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* XMPPHP LogTest
|
|
|
|
*
|
|
|
|
* @package XMPPHP
|
|
|
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
|
|
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
|
|
|
* @author Michael Garvin <JID: gar@netflint.net>
|
|
|
|
* @copyright 2008 Nathanael C. Fritz
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2008-05-05 22:15:32 +01:00
|
|
|
class XMPPHP_LogTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testPrintoutNoOutput()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log();
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log('test');
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertEquals('', $result);
|
|
|
|
}
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
public function testPrintoutOutput()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(true);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertContains($msg, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrintoutNoOutputWithDefaultLevel()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_ERROR);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrintoutOutputWithDefaultLevel()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertContains($msg, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrintoutNoOutputWithCustomLevel()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg, XMPPHP_Log::LEVEL_DEBUG);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
public function testPrintoutOutputWithCustomLevel()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(true, XMPPHP_Log::LEVEL_INFO);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg, XMPPHP_Log::LEVEL_INFO);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertContains($msg, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExplicitPrintout()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(false);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExplicitPrintoutResult()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(false);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->printout();
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertContains($msg, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExplicitPrintoutClear()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(false);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->printout();
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertContains($msg, $result);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$log->printout();
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
public function testExplicitPrintoutLevel()
|
|
|
|
{
|
|
|
|
$log = new XMPPHP_Log(false, XMPPHP_Log::LEVEL_ERROR);
|
|
|
|
$msg = 'I am a test log message';
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->log($msg);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
ob_start();
|
|
|
|
$log->printout(true, XMPPHP_Log::LEVEL_INFO);
|
|
|
|
$result = ob_get_clean();
|
2019-06-18 19:02:40 +01:00
|
|
|
|
2008-05-05 22:15:32 +01:00
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
|
|
|
}
|