API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class SS_LogTest extends SapphireTest {
|
|
|
|
|
|
|
|
protected $testEmailWriter;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setUp() {
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
parent::setUp();
|
2012-02-06 17:52:19 +01:00
|
|
|
|
|
|
|
SS_Log::clear_writers();
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function tearDown() {
|
2012-02-06 17:52:19 +01:00
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
SS_Log::clear_writers();
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testExistingWriter() {
|
2012-02-06 17:52:19 +01:00
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
$testFileWriter = new SS_LogFileWriter('../test.log');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::ERR);
|
|
|
|
SS_Log::add_writer($testFileWriter, SS_Log::WARN);
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$writers = SS_Log::get_writers();
|
|
|
|
$this->assertEquals(2, count($writers));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testRemoveWriter() {
|
2012-02-06 17:52:19 +01:00
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
$testFileWriter = new SS_LogFileWriter('../test.log');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::ERR);
|
|
|
|
SS_Log::add_writer($testFileWriter, SS_Log::WARN);
|
|
|
|
|
|
|
|
SS_Log::remove_writer($testEmailWriter);
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$writers = SS_Log::get_writers();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$this->assertEquals(1, count($writers));
|
2012-02-06 17:52:19 +01:00
|
|
|
|
|
|
|
SS_Log::remove_writer($testFileWriter);
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$writers = SS_Log::get_writers();
|
|
|
|
$this->assertEquals(0, count($writers));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEmailWriter() {
|
2012-02-06 17:52:19 +01:00
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::ERR);
|
|
|
|
|
2014-06-20 05:27:42 +02:00
|
|
|
SS_Log::log('Email test', SS_Log::ERR, array('my-string' => 'test', 'my-array' => array('one' => 1)));
|
2012-02-06 17:52:19 +01:00
|
|
|
$this->assertEmailSent('test@test.com');
|
|
|
|
$email = $this->findEmail('test@test.com');
|
2014-06-20 05:27:42 +02:00
|
|
|
$this->assertContains('[Error] Email test', $email['htmlContent']);
|
2012-02-06 17:52:19 +01:00
|
|
|
$parser = new CSSContentParser($email['htmlContent']);
|
|
|
|
$extras = $parser->getBySelector('table.extras');
|
|
|
|
$extraRows = $extras[0]->tr;
|
|
|
|
$this->assertContains('my-string', $extraRows[count($extraRows)-2]->td[0]->asXML(), 'Contains extra data key');
|
|
|
|
$this->assertContains('test', $extraRows[count($extraRows)-2]->td[1]->asXML(), 'Contains extra data value');
|
|
|
|
$this->assertContains('my-array', $extraRows[count($extraRows)-1]->td[0]->asXML(), 'Contains extra data key');
|
|
|
|
$this->assertContains(
|
2014-08-15 08:53:05 +02:00
|
|
|
"array('one'=>1,)",
|
|
|
|
str_replace(array("\r", "\n", " "), '', $extraRows[count($extraRows)-1]->td[1]->asXML()),
|
2012-02-06 17:52:19 +01:00
|
|
|
'Serializes arrays correctly'
|
|
|
|
);
|
|
|
|
}
|
2014-06-20 05:27:42 +02:00
|
|
|
|
|
|
|
public function testEmailWriterDebugPriority() {
|
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::DEBUG);
|
|
|
|
SS_Log::log('Test something', SS_Log::DEBUG, array('my-string' => 'test', 'my-array' => array('one' => 1)));
|
|
|
|
$this->assertEmailSent('test@test.com');
|
|
|
|
$email = $this->findEmail('test@test.com');
|
|
|
|
$this->assertContains('[DEBUG] Test something', $email['htmlContent']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmailWriterInfoPriority() {
|
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::INFO);
|
|
|
|
SS_Log::log('Test something', SS_Log::INFO, array('my-string' => 'test', 'my-array' => array('one' => 1)));
|
|
|
|
$this->assertEmailSent('test@test.com');
|
|
|
|
$email = $this->findEmail('test@test.com');
|
|
|
|
$this->assertContains('[INFO] Test something', $email['htmlContent']);
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
protected function exceptionGeneratorThrower() {
|
|
|
|
throw new Exception("thrown from SS_LogTest::testExceptionGeneratorTop");
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
protected function exceptionGenerator() {
|
|
|
|
$this->exceptionGeneratorThrower();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
public function testEmailException() {
|
|
|
|
$testEmailWriter = new SS_LogEmailWriter('test@test.com');
|
|
|
|
SS_Log::add_writer($testEmailWriter, SS_Log::ERR);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
// Trigger exception handling mechanism
|
|
|
|
try {
|
|
|
|
$this->exceptionGenerator();
|
|
|
|
} catch(Exception $exception) {
|
|
|
|
// Mimics exceptionHandler, but without the exit(1)
|
|
|
|
SS_Log::log(
|
|
|
|
array(
|
|
|
|
'errno' => E_USER_ERROR,
|
|
|
|
'errstr' => ("Uncaught " . get_class($exception) . ": " . $exception->getMessage()),
|
|
|
|
'errfile' => $exception->getFile(),
|
|
|
|
'errline' => $exception->getLine(),
|
|
|
|
'errcontext' => $exception->getTrace()
|
|
|
|
),
|
|
|
|
SS_Log::ERR
|
|
|
|
);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
// Ensure email is sent
|
|
|
|
$this->assertEmailSent('test@test.com');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
// Begin parsing of email body
|
|
|
|
$email = $this->findEmail('test@test.com');
|
|
|
|
$parser = new CSSContentParser($email['htmlContent']);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-01-24 01:28:58 +01:00
|
|
|
// Check that the first three lines of the stacktrace are correct
|
|
|
|
$stacktrace = $parser->getByXpath('//body/div[1]/ul[1]');
|
|
|
|
$this->assertContains('<b>SS_LogTest->exceptionGeneratorThrower()</b>', $stacktrace[0]->li[0]->asXML());
|
|
|
|
$this->assertContains('<b>SS_LogTest->exceptionGenerator()</b>', $stacktrace[0]->li[1]->asXML());
|
|
|
|
$this->assertContains('<b>SS_LogTest->testEmailException()</b>', $stacktrace[0]->li[2]->asXML());
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-10-04 06:40:03 +02:00
|
|
|
public function testSubclassedLogger() {
|
|
|
|
$this->assertTrue(SS_Log::get_logger() !== SS_LogTest_NewLogger::get_logger());
|
|
|
|
}
|
2012-02-06 17:52:19 +01:00
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|
2012-10-04 06:40:03 +02:00
|
|
|
|
|
|
|
class SS_LogTest_NewLogger extends SS_Log {
|
|
|
|
protected static $logger;
|
2014-06-20 05:27:42 +02:00
|
|
|
}
|