3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Tests for linking to resource files
33 class CRM_Core_ErrorTest
extends CiviUnitTestCase
{
37 'description' => 'Tests for error handling',
44 $config = CRM_Core_Config
::singleton();
45 $this->oldConfigAndLogDir
= $config->configAndLogDir
;
46 $config->configAndLogDir
= $this->createTempDir('test-log-');
50 $config = CRM_Core_Config
::singleton();
51 $config->configAndLogDir
= $this->oldConfigAndLogDir
;
56 * Make sure that formatBacktrace() accepts values from debug_backtrace()
58 function testFormatBacktrace_debug() {
59 $bt = debug_backtrace();
60 $msg = CRM_Core_Error
::formatBacktrace($bt);
61 $this->assertRegexp('/CRM_Core_ErrorTest->testFormatBacktrace_debug/', $msg);
65 * Make sure that formatBacktrace() accepts values from Exception::getTrace()
67 function testFormatBacktrace_exception() {
68 $e = new Exception('foo');
69 $msg = CRM_Core_Error
::formatBacktrace($e->getTrace());
70 $this->assertRegexp('/CRM_Core_ErrorTest->testFormatBacktrace_exception/', $msg);
74 * We have two coding conventions for writing to log. Make sure that they work together.
76 * This tests a theory about what caused CRM-10766.
78 function testMixLog() {
79 CRM_Core_Error
::debug_log_message("static-1");
80 $logger = CRM_Core_Error
::createDebugLogger();
81 CRM_Core_Error
::debug_log_message("static-2");
82 $logger->info('obj-1');
83 CRM_Core_Error
::debug_log_message("static-3");
84 $logger->info('obj-2');
85 CRM_Core_Error
::debug_log_message("static-4");
86 $logger2 = CRM_Core_Error
::createDebugLogger();
87 $logger2->info('obj-3');
88 CRM_Core_Error
::debug_log_message("static-5");
89 $this->assertLogRegexp('/static-1.*static-2.*obj-1.*static-3.*obj-2.*static-4.*obj-3.*static-5/s');
92 function assertLogRegexp($pattern) {
93 $config = CRM_Core_Config
::singleton();
94 $logFiles = glob($config->configAndLogDir
.'/CiviCRM*log*/');
95 $this->assertEquals(1, count($logFiles));
96 foreach ($logFiles as $logFile) {
97 $this->assertRegexp($pattern, file_get_contents($logFile));