Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Tests for linking to resource files | |
32 | */ | |
33 | class CRM_Core_ErrorTest extends CiviUnitTestCase { | |
7aa78225 | 34 | //@todo make BAO enotice compliant & remove the line below |
35 | // WARNING - NEVER COPY & PASTE $_eNoticeCompliant = FALSE | |
36 | // new test classes should be compliant. | |
37 | public $_eNoticeCompliant = FALSE; | |
6a488035 TO |
38 | function get_info() { |
39 | return array( | |
40 | 'name' => 'Errors', | |
41 | 'description' => 'Tests for error handling', | |
42 | 'group' => 'Core', | |
43 | ); | |
44 | } | |
45 | ||
46 | function setUp() { | |
47 | parent::setUp(); | |
48 | $config = CRM_Core_Config::singleton(); | |
49 | $this->oldConfigAndLogDir = $config->configAndLogDir; | |
50 | $config->configAndLogDir = $this->createTempDir('test-log-'); | |
51 | } | |
52 | ||
53 | function tearDown() { | |
54 | $config = CRM_Core_Config::singleton(); | |
55 | $config->configAndLogDir= $this->oldConfigAndLogDir; | |
56 | parent::tearDown(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Make sure that formatBacktrace() accepts values from debug_backtrace() | |
61 | */ | |
62 | function testFormatBacktrace_debug() { | |
63 | $bt = debug_backtrace(); | |
64 | $msg = CRM_Core_Error::formatBacktrace($bt); | |
65 | $this->assertRegexp('/CRM_Core_ErrorTest->testFormatBacktrace_debug/', $msg); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Make sure that formatBacktrace() accepts values from Exception::getTrace() | |
70 | */ | |
71 | function testFormatBacktrace_exception() { | |
72 | $e = new Exception('foo'); | |
73 | $msg = CRM_Core_Error::formatBacktrace($e->getTrace()); | |
74 | $this->assertRegexp('/CRM_Core_ErrorTest->testFormatBacktrace_exception/', $msg); | |
75 | } | |
76 | ||
77 | /** | |
78 | * We have two coding conventions for writing to log. Make sure that they work together. | |
79 | * | |
80 | * This tests a theory about what caused CRM-10766. | |
81 | */ | |
82 | function testMixLog() { | |
83 | CRM_Core_Error::debug_log_message("static-1"); | |
84 | $logger = CRM_Core_Error::createDebugLogger(); | |
85 | CRM_Core_Error::debug_log_message("static-2"); | |
86 | $logger->info('obj-1'); | |
87 | CRM_Core_Error::debug_log_message("static-3"); | |
88 | $logger->info('obj-2'); | |
89 | CRM_Core_Error::debug_log_message("static-4"); | |
90 | $logger2 = CRM_Core_Error::createDebugLogger(); | |
91 | $logger2->info('obj-3'); | |
92 | CRM_Core_Error::debug_log_message("static-5"); | |
93 | $this->assertLogRegexp('/static-1.*static-2.*obj-1.*static-3.*obj-2.*static-4.*obj-3.*static-5/s'); | |
94 | } | |
95 | ||
96 | function assertLogRegexp($pattern) { | |
97 | $config = CRM_Core_Config::singleton(); | |
98 | $logFiles = glob($config->configAndLogDir.'/CiviCRM*log*/'); | |
99 | $this->assertEquals(1, count($logFiles)); | |
100 | foreach ($logFiles as $logFile) { | |
101 | $this->assertRegexp($pattern, file_get_contents($logFile)); | |
102 | } | |
103 | } | |
104 | } |