From 95cd4ae9b2e4fc09d34b2db65df411035a829ba0 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 24 Aug 2016 10:02:03 +1000 Subject: [PATCH] backport unit test to 4.6 --- CRM/Core/Error.php | 2 +- tests/phpunit/CRM/Core/ErrorTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index cca09a832c..3100455826 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -634,7 +634,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { * Generate a hash for the logfile. * CRM-13640. */ - protected static function generateLogFileHash($config) { + public static function generateLogFileHash($config) { // Use multiple (but stable) inputs for hash information. TMI? $md5inputs = array( defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : 'NO_SITE_KEY', diff --git a/tests/phpunit/CRM/Core/ErrorTest.php b/tests/phpunit/CRM/Core/ErrorTest.php index 536ac1f271..a9a25fd2e5 100644 --- a/tests/phpunit/CRM/Core/ErrorTest.php +++ b/tests/phpunit/CRM/Core/ErrorTest.php @@ -94,4 +94,22 @@ class CRM_Core_ErrorTest extends CiviUnitTestCase { } } + /** + * Check that a debugger is created and there is no error when passing in a prefix. + * + * Do some basic content checks. + */ + public function testDebugLoggerFormat() { + $log = CRM_Core_Error::createDebugLogger('my-test'); + $log->log('Mary had a little lamb'); + $log->log('Little lamb'); + $config = CRM_Core_Config::singleton(); + $fileContents = file_get_contents($log->_filename); + $this->assertEquals($config->configAndLogDir . 'CiviCRM.' . 'my-test.' . CRM_Core_Error::generateLogFileHash($config) . '.log', $log->_filename); + // The 5 here is a bit arbitrary - on my local the date part is 15 chars (Mar 29 05:29:16) - but we are just checking that + // there are chars for the date at the start. + $this->assertTrue(strpos($fileContents, '[info] Mary had a little lamb') > 10); + $this->assertContains('[info] Little lamb', $fileContents); + } + } -- 2.25.1