Permalink
Browse files

updating tests for CakeLog

- ObjectCollection operations
- Selective logging
  • Loading branch information...
1 parent 68b4995 commit 70177e4dbd525d1ed626aed689278fc1f70ebd34 @rchavik rchavik committed May 9, 2012
Showing with 112 additions and 1 deletion.
  1. +112 −1 lib/Cake/Test/Case/Log/CakeLogTest.php
@@ -79,6 +79,28 @@ public function testImportingLoggerFailure() {
}
/**
+ * 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.
*
* @expectedException CakeLogException
@@ -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');
+ }
+
}

0 comments on commit 70177e4

Please sign in to comment.