-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
debugger.test.php
337 lines (307 loc) · 8.72 KB
/
debugger.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
/**
* DebuggerTest file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP Project
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Debugger');
/**
* DebugggerTestCaseDebuggger class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class DebuggerTestCaseDebugger extends Debugger {
}
/**
* DebuggerTest class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class DebuggerTest extends CakeTestCase {
// !!!
// !!! Be careful with changing code below as it may
// !!! change line numbers which are used in the tests
// !!!
/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
Configure::write('log', false);
if (!defined('SIMPLETESTVENDORPATH')) {
if (file_exists(APP . DS . 'vendors' . DS . 'simpletest' . DS . 'reporter.php')) {
define('SIMPLETESTVENDORPATH', 'APP' . DS . 'vendors');
} else {
define('SIMPLETESTVENDORPATH', 'CORE' . DS . 'vendors');
}
}
}
/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
Configure::write('log', true);
}
/**
* testDocRef method
*
* @access public
* @return void
*/
function testDocRef() {
ini_set('docref_root', '');
$this->assertEqual(ini_get('docref_root'), '');
$debugger = new Debugger();
$this->assertEqual(ini_get('docref_root'), 'http://php.net/');
}
/**
* test Excerpt writing
*
* @access public
* @return void
*/
function testExcerpt() {
$result = Debugger::excerpt(__FILE__, __LINE__, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 5);
$this->assertPattern('/function(.+)testExcerpt/', $result[1]);
$result = Debugger::excerpt(__FILE__, 2, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 4);
$expected = '<code><span style="color: #000000"><?php';
$expected .= '</span></code>';
$this->assertEqual($result[0], $expected);
$return = Debugger::excerpt('[internal]', 2, 2);
$this->assertTrue(empty($return));
}
/**
* testOutput method
*
* @access public
* @return void
*/
function testOutput() {
Debugger::invoke(Debugger::getInstance());
$result = Debugger::output(false);
$this->assertEqual($result, '');
$out .= '';
$result = Debugger::output(true);
$this->assertEqual($result[0]['error'], 'Notice');
$this->assertPattern('/Undefined variable\:\s+out/', $result[0]['description']);
$this->assertPattern('/DebuggerTest::testOutput/i', $result[0]['trace']);
$this->assertPattern('/SimpleInvoker::invoke/i', $result[0]['trace']);
ob_start();
Debugger::output('txt');
$other .= '';
$result = ob_get_clean();
$this->assertPattern('/Undefined variable:\s+other/', $result);
$this->assertPattern('/Context:/', $result);
$this->assertPattern('/DebuggerTest::testOutput/i', $result);
$this->assertPattern('/SimpleInvoker::invoke/i', $result);
ob_start();
Debugger::output('html');
$wrong .= '';
$result = ob_get_clean();
$this->assertPattern('/<pre class="cake-debug">.+<\/pre>/', $result);
$this->assertPattern('/<b>Notice<\/b>/', $result);
$this->assertPattern('/variable:\s+wrong/', $result);
ob_start();
Debugger::output('js');
$buzz .= '';
$result = explode('</a>', ob_get_clean());
$this->assertTags($result[0], array(
'pre' => array('class' => 'cake-debug'),
'a' => array(
'href' => "javascript:void(0);",
'onclick' => "document.getElementById('cakeErr4-trace').style.display = " .
"(document.getElementById('cakeErr4-trace').style.display == 'none'" .
" ? '' : 'none');"
),
'b' => array(), 'Notice', '/b', ' (8)',
));
$this->assertPattern('/Undefined variable:\s+buzz/', $result[1]);
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
set_error_handler('simpleTestErrorHandler');
}
/**
* Tests that changes in output formats using Debugger::output() change the templates used.
*
* @return void
*/
function testChangeOutputFormats() {
Debugger::invoke(Debugger::getInstance());
Debugger::output('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
'&line={:line}">{:path}</a>, line {:line}'
));
$result = Debugger::trace();
$this->assertPattern('/' . preg_quote('txmt://open?url=file:///', '/') . '/', $result);
Debugger::output('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
'{:description}</error>',
'context' => "<context>{:context}</context>",
'trace' => "<stack>{:trace}</stack>",
));
Debugger::output('xml');
ob_start();
$foo .= '';
$result = ob_get_clean();
set_error_handler('SimpleTestErrorHandler');
$data = array(
'error' => array(),
'code' => array(), '8', '/code',
'file' => array(), 'preg:/[^<]+/', '/file',
'line' => array(), '' . (intval(__LINE__) + -8), '/line',
'preg:/Undefined variable:\s+foo/',
'/error'
);
$this->assertTags($result, $data, true);
}
/**
* testTrimPath method
*
* @access public
* @return void
*/
function testTrimPath() {
$this->assertEqual(Debugger::trimPath(APP), 'APP' . DS);
$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
}
/**
* testExportVar method
*
* @access public
* @return void
*/
function testExportVar() {
App::import('Controller');
$Controller = new Controller();
$Controller->helpers = array('Html', 'Form');
$View = new View($Controller);
$result = Debugger::exportVar($View);
$expected = 'ViewView::$base = NULL
View::$here = NULL
View::$plugin = NULL
View::$name = ""
View::$action = NULL
View::$params = array
View::$passedArgs = array
View::$data = array
View::$helpers = array
View::$viewPath = ""
View::$viewVars = array
View::$layout = "default"
View::$layoutPath = NULL
View::$autoRender = true
View::$autoLayout = true
View::$ext = ".ctp"
View::$subDir = NULL
View::$theme = NULL
View::$cacheAction = false
View::$validationErrors = array
View::$hasRendered = false
View::$loaded = array
View::$modelScope = false
View::$model = NULL
View::$association = NULL
View::$field = NULL
View::$fieldSuffix = NULL
View::$modelId = NULL
View::$uuids = array
View::$output = false
View::$__passedVars = array
View::$__scripts = array
View::$__paths = array
View::$webroot = NULL';
$result = str_replace(array("\t", "\r\n", "\n"), "", strtolower($result));
$expected = str_replace(array("\t", "\r\n", "\n"), "", strtolower($expected));
$this->assertEqual($result, $expected);
}
/**
* testLog method
*
* @access public
* @return void
*/
function testLog() {
if (file_exists(LOGS . 'debug.log')) {
unlink(LOGS . 'debug.log');
}
Debugger::log('cool');
$result = file_get_contents(LOGS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/"cool"/', $result);
unlink(TMP . 'logs' . DS . 'debug.log');
Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
$this->assertPattern('/\[main\]/', $result);
$this->assertPattern('/array/', $result);
$this->assertPattern('/"whatever",/', $result);
$this->assertPattern('/"here"/', $result);
}
/**
* testDump method
*
* @access public
* @return void
*/
function testDump() {
$var = array('People' => array(
array(
'name' => 'joeseph',
'coat' => 'technicolor',
'hair_color' => 'brown'
),
array(
'name' => 'Shaft',
'coat' => 'black',
'hair' => 'black'
)
)
);
ob_start();
Debugger::dump($var);
$result = ob_get_clean();
$expected = "<pre>array(\n\t\"People\" => array()\n)</pre>";
$this->assertEqual($expected, $result);
}
/**
* test getInstance.
*
* @access public
* @return void
*/
function testGetInstance() {
$result =& Debugger::getInstance();
$this->assertIsA($result, 'Debugger');
$result =& Debugger::getInstance('DebuggerTestCaseDebugger');
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result =& Debugger::getInstance();
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
$result =& Debugger::getInstance('Debugger');
$this->assertIsA($result, 'Debugger');
}
}
?>