2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CakeLogTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2009-09-08 03:59:31 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2009-09-08 03:59:31 +00:00
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Core', 'Log');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CakeLogTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class CakeLogTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLogFileWriting method
|
2008-11-08 02:58:37 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLogFileWriting() {
|
|
|
|
@unlink(LOGS . 'error.log');
|
|
|
|
CakeLog::write(LOG_WARNING, 'Test warning');
|
|
|
|
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
|
|
|
unlink(LOGS . 'error.log');
|
|
|
|
|
|
|
|
CakeLog::write(LOG_WARNING, 'Test warning 1');
|
|
|
|
CakeLog::write(LOG_WARNING, 'Test warning 2');
|
|
|
|
$result = file_get_contents(LOGS . 'error.log');
|
|
|
|
$this->assertPattern('/^2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 1/', $result);
|
|
|
|
$this->assertPattern('/2[0-9]{3}-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+ Warning: Test warning 2$/', $result);
|
|
|
|
unlink(LOGS . 'error.log');
|
|
|
|
}
|
2009-09-08 03:59:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test logging with the error handler.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
**/
|
|
|
|
function testLoggingWithErrorHandling() {
|
|
|
|
@unlink(LOGS . 'debug.log');
|
|
|
|
Configure::write('log', E_ALL & ~E_DEPRECATED);
|
|
|
|
Configure::write('debug', 0);
|
|
|
|
|
2009-09-10 15:32:21 +00:00
|
|
|
set_error_handler(array('CakeLog', 'handleError'));
|
2009-09-08 03:59:31 +00:00
|
|
|
$out .= '';
|
|
|
|
|
|
|
|
$result = file(LOGS . 'debug.log');
|
|
|
|
$this->assertEqual(count($result), 1);
|
|
|
|
$this->assertPattern(
|
2009-09-20 22:31:49 +00:00
|
|
|
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Notice: Notice \(8\): Undefined variable: out in \[.+ line \d{2}\]$/',
|
2009-09-08 03:59:31 +00:00
|
|
|
$result[0]
|
|
|
|
);
|
|
|
|
@unlink(LOGS . 'debug.log');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|