From 70177e4dbd525d1ed626aed689278fc1f70ebd34 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Wed, 9 May 2012 15:55:56 +0700 Subject: [PATCH] updating tests for CakeLog - ObjectCollection operations - Selective logging --- lib/Cake/Test/Case/Log/CakeLogTest.php | 113 ++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Log/CakeLogTest.php b/lib/Cake/Test/Case/Log/CakeLogTest.php index a24731a018b..51ff63dbd81 100644 --- a/lib/Cake/Test/Case/Log/CakeLogTest.php +++ b/lib/Cake/Test/Case/Log/CakeLogTest.php @@ -78,6 +78,28 @@ public function testImportingLoggerFailure() { CakeLog::config('fail', array()); } +/** + * test config() with valid key name + * + * @return void + */ + public function testValidKeyName() { + CakeLog::config('valid', array('engine' => 'FileLog')); + $stream = CakeLog::stream('valid'); + $this->assertInstanceOf('FileLog', $stream); + CakeLog::drop('valid'); + } + +/** + * test config() with invalid key name + * + * @expectedException CakeLogException + * @return void + */ + public function testInvalidKeyName() { + CakeLog::config('1nv', array('engine' => 'FileLog')); + } + /** * test that loggers have to implement the correct interface. * @@ -102,7 +124,7 @@ public function testAutoConfig() { $this->assertTrue(file_exists(LOGS . 'error.log')); $result = CakeLog::configured(); - $this->assertEquals(array('default'), $result); + $this->assertEquals(array('error'), $result); unlink(LOGS . 'error.log'); } @@ -170,4 +192,93 @@ public function testLogFileWriting() { unlink(LOGS . 'error.log'); } +/** + * test selective logging + */ + public function testSelectiveLogging() { + if (file_exists(LOGS . 'spam.log')) { + unlink(LOGS . 'spam.log'); + } + if (file_exists(LOGS . 'eggs.log')) { + unlink(LOGS . 'eggs.log'); + } + CakeLog::config('spam', array( + 'engine' => 'FileLog', + 'types' => 'info', + 'file' => 'spam', + )); + CakeLog::config('eggs', array( + 'engine' => 'FileLog', + 'types' => array('eggs', 'info', 'error', 'warning'), + 'file' => 'eggs', + )); + + $testMessage = 'selective logging'; + CakeLog::write(LOG_WARNING, $testMessage); + + $this->assertTrue(file_exists(LOGS . 'eggs.log')); + $this->assertFalse(file_exists(LOGS . 'spam.log')); + + CakeLog::write(LOG_INFO, $testMessage); + $this->assertTrue(file_exists(LOGS . 'spam.log')); + + $contents = file_get_contents(LOGS . 'spam.log'); + $this->assertContains('Info: ' . $testMessage, $contents); + $contents = file_get_contents(LOGS . 'eggs.log'); + $this->assertContains('Info: ' . $testMessage, $contents); + + if (file_exists(LOGS . 'spam.log')) { + unlink(LOGS . 'spam.log'); + } + if (file_exists(LOGS . 'eggs.log')) { + unlink(LOGS . 'eggs.log'); + } + } + +/** + * test enable + * @expectedException CakeLogException + */ + public function testStreamEnable() { + CakeLog::config('spam', array( + 'engine' => 'FileLog', + 'file' => 'spam', + )); + $this->assertTrue(CakeLog::enabled('spam')); + CakeLog::drop('spam'); + CakeLog::enable('bogus_stream'); + } + +/** + * test disable + * @expectedException CakeLogException + */ + public function testStreamDisable() { + CakeLog::config('spam', array( + 'engine' => 'FileLog', + 'file' => 'spam', + )); + $this->assertTrue(CakeLog::enabled('spam')); + CakeLog::disable('spam'); + $this->assertFalse(CakeLog::enabled('spam')); + CakeLog::drop('spam'); + CakeLog::enable('bogus_stream'); + } + +/** + * test enabled() invalid stream + * @expectedException CakeLogException + */ + public function testStreamEnabledInvalid() { + CakeLog::enabled('bogus_stream'); + } + +/** + * test disable invalid stream + * @expectedException CakeLogException + */ + public function testStreamDisableInvalid() { + CakeLog::disable('bogus_stream'); + } + }