2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-05-01 21:05:46 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP Project
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Debugger', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2013-05-30 22:11:14 +00:00
|
|
|
* DebuggerTestCaseDebugger class
|
2008-12-07 20:44:00 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-12-07 20:44:00 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class DebuggerTestCaseDebugger extends Debugger {
|
2008-12-07 20:44:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-07 20:44:00 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DebuggerTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-14 02:59:20 +00:00
|
|
|
* !!! Be careful with changing code below as it may
|
|
|
|
* !!! change line numbers which are used in the tests
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class DebuggerTest extends CakeTestCase {
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2010-11-15 01:19:15 +00:00
|
|
|
protected $_restoreError = false;
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::setUp();
|
2010-11-14 05:59:45 +00:00
|
|
|
Configure::write('debug', 2);
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('log', false);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
Configure::write('log', true);
|
2010-11-15 01:19:15 +00:00
|
|
|
if ($this->_restoreError) {
|
|
|
|
restore_error_handler();
|
|
|
|
}
|
2009-03-18 17:55:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testDocRef method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDocRef() {
|
2008-06-20 20:17:23 +00:00
|
|
|
ini_set('docref_root', '');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(ini_get('docref_root'), '');
|
2013-01-23 12:45:50 +00:00
|
|
|
new Debugger();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(ini_get('docref_root'), 'http://php.net/');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-18 01:23:33 +00:00
|
|
|
/**
|
|
|
|
* test Excerpt writing
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExcerpt() {
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = Debugger::excerpt(__FILE__, __LINE__, 2);
|
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(5, count($result));
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/function(.+)testExcerpt/', $result[1]);
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
$result = Debugger::excerpt(__FILE__, 2, 2);
|
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(4, count($result));
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2012-12-09 01:48:13 +00:00
|
|
|
$pattern = '/<code>.*?<span style\="color\: \#\d+">.*?<\?php/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result[0]);
|
2012-12-09 01:48:13 +00:00
|
|
|
|
2013-02-08 13:34:41 +00:00
|
|
|
$result = Debugger::excerpt(__FILE__, 11, 2);
|
2012-12-09 01:48:13 +00:00
|
|
|
$this->assertEquals(5, count($result));
|
|
|
|
|
|
|
|
$pattern = '/<span style\="color\: \#\d{6}">\*<\/span>/';
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression($pattern, $result[0]);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2008-10-18 01:23:33 +00:00
|
|
|
$return = Debugger::excerpt('[internal]', 2, 2);
|
|
|
|
$this->assertTrue(empty($return));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOutput method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOutput() {
|
2010-11-15 01:19:15 +00:00
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Debugger::output(false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out .= '';
|
|
|
|
$result = Debugger::output(true);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Notice', $result[0]['error']);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Undefined variable\:\s+out/', $result[0]['description']);
|
|
|
|
$this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result[0]['trace']);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('txt');
|
|
|
|
$other .= '';
|
|
|
|
$result = ob_get_clean();
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Undefined variable:\s+other/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/Context:/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/DebuggerTest::testOutput/i', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('html');
|
|
|
|
$wrong .= '';
|
|
|
|
$result = ob_get_clean();
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/<pre class="cake-error">.+<\/pre>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/<b>Notice<\/b>/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/variable:\s+wrong/', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('js');
|
|
|
|
$buzz .= '';
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = explode('</a>', ob_get_clean());
|
|
|
|
$this->assertTags($result[0], array(
|
2011-09-02 13:18:33 +00:00
|
|
|
'pre' => array('class' => 'cake-error'),
|
2009-05-01 21:05:46 +00:00
|
|
|
'a' => array(
|
|
|
|
'href' => "javascript:void(0);",
|
2011-05-05 03:30:24 +00:00
|
|
|
'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
|
2012-11-21 14:39:03 +00:00
|
|
|
"\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
|
|
|
|
" \? '' \: 'none'\);/"
|
2009-05-01 21:05:46 +00:00
|
|
|
),
|
2009-07-25 17:27:17 +00:00
|
|
|
'b' => array(), 'Notice', '/b', ' (8)',
|
2009-05-01 21:05:46 +00:00
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Undefined variable:\s+buzz/', $result[1]);
|
|
|
|
$this->assertMatchesRegularExpression('/<a[^>]+>Code/', $result[1]);
|
|
|
|
$this->assertMatchesRegularExpression('/<a[^>]+>Context/', $result[2]);
|
2012-05-17 01:07:45 +00:00
|
|
|
$this->assertContains('$wrong = ''', $result[3], 'Context should be HTML escaped.');
|
2009-05-01 21:05:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-10 13:47:13 +00:00
|
|
|
/**
|
|
|
|
* test encodes error messages
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputEncodeDescription() {
|
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
|
|
|
ob_start();
|
2016-12-13 05:46:13 +00:00
|
|
|
$a = array();
|
2016-12-10 13:47:13 +00:00
|
|
|
$b = $a['<script>alert(1)</script>'];
|
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$this->assertNotContains('<script>alert(1)', $result);
|
|
|
|
$this->assertContains('<script>alert(1)', $result);
|
|
|
|
}
|
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
/**
|
|
|
|
* Tests that changes in output formats using Debugger::output() change the templates used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChangeOutputFormats() {
|
2010-11-15 01:19:15 +00:00
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
Debugger::output('js', array(
|
|
|
|
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
|
2012-05-17 01:07:45 +00:00
|
|
|
'&line={:line}">{:path}</a>, line {:line}'
|
2009-05-01 21:05:46 +00:00
|
|
|
));
|
|
|
|
$result = Debugger::trace();
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
Debugger::output('xml', array(
|
|
|
|
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'{:description}</error>',
|
2009-05-01 21:05:46 +00:00
|
|
|
'context' => "<context>{:context}</context>",
|
|
|
|
'trace' => "<stack>{:trace}</stack>",
|
|
|
|
));
|
|
|
|
Debugger::output('xml');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'error' => array(),
|
|
|
|
'code' => array(), '8', '/code',
|
|
|
|
'file' => array(), 'preg:/[^<]+/', '/file',
|
2014-09-10 13:52:57 +00:00
|
|
|
'line' => array(), '' . ((int)__LINE__ - 7), '/line',
|
2010-01-15 04:06:48 +00:00
|
|
|
'preg:/Undefined variable:\s+foo/',
|
2009-05-01 21:05:46 +00:00
|
|
|
'/error'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $data, true);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-08-21 14:19:43 +00:00
|
|
|
/**
|
|
|
|
* Test that outputAs works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputAs() {
|
|
|
|
Debugger::outputAs('html');
|
|
|
|
$this->assertEquals('html', Debugger::outputAs());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Test that choosing a non-existent format causes an exception
|
2011-08-21 14:19:43 +00:00
|
|
|
*
|
|
|
|
* @expectedException CakeException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputAsException() {
|
|
|
|
Debugger::outputAs('Invalid junk');
|
|
|
|
}
|
|
|
|
|
2011-08-21 14:30:10 +00:00
|
|
|
/**
|
|
|
|
* Tests that changes in output formats using Debugger::output() change the templates used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAddFormat() {
|
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
|
|
|
Debugger::addFormat('js', array(
|
|
|
|
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'&line={:line}">{:path}</a>, line {:line}'
|
2011-08-21 14:30:10 +00:00
|
|
|
));
|
|
|
|
Debugger::outputAs('js');
|
|
|
|
|
|
|
|
$result = Debugger::trace();
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
|
2011-08-21 14:30:10 +00:00
|
|
|
|
|
|
|
Debugger::addFormat('xml', array(
|
|
|
|
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'{:description}</error>',
|
2011-08-21 14:30:10 +00:00
|
|
|
));
|
|
|
|
Debugger::outputAs('xml');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'<error',
|
|
|
|
'<code', '8', '/code',
|
|
|
|
'<file', 'preg:/[^<]+/', '/file',
|
2014-09-10 13:52:57 +00:00
|
|
|
'<line', '' . ((int)__LINE__ - 7), '/line',
|
2011-08-21 14:30:10 +00:00
|
|
|
'preg:/Undefined variable:\s+foo/',
|
|
|
|
'/error'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $data, true);
|
|
|
|
}
|
|
|
|
|
2011-09-02 13:18:33 +00:00
|
|
|
/**
|
|
|
|
* Test adding a format that is handled by a callback.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-08-21 14:47:52 +00:00
|
|
|
public function testAddFormatCallback() {
|
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
|
|
|
Debugger::addFormat('callback', array('callback' => array($this, 'customFormat')));
|
|
|
|
Debugger::outputAs('callback');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
|
|
|
$result = ob_get_clean();
|
2011-10-01 02:44:04 +00:00
|
|
|
$this->assertContains('Notice: I eated an error', $result);
|
|
|
|
$this->assertContains('DebuggerTest.php', $result);
|
2011-08-21 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method for testing addFormat with callbacks.
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2011-08-21 14:47:52 +00:00
|
|
|
*/
|
|
|
|
public function customFormat($error, $strings) {
|
2012-09-10 01:08:21 +00:00
|
|
|
return $error['error'] . ': I eated an error ' . $error['file'];
|
2011-08-21 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testTrimPath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTrimPath() {
|
2012-09-05 22:52:17 +00:00
|
|
|
$this->assertEquals('APP' . DS, Debugger::trimPath(APP));
|
|
|
|
$this->assertEquals('CORE', Debugger::trimPath(CAKE_CORE_INCLUDE_PATH));
|
|
|
|
$this->assertEquals('ROOT', Debugger::trimPath(ROOT));
|
|
|
|
$this->assertEquals('CORE' . DS . 'Cake' . DS, Debugger::trimPath(CAKE));
|
|
|
|
$this->assertEquals('Some/Other/Path', Debugger::trimPath('Some/Other/Path'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExportVar method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExportVar() {
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller = new Controller();
|
|
|
|
$Controller->helpers = array('Html', 'Form');
|
|
|
|
$View = new View($Controller);
|
2011-10-15 15:42:09 +00:00
|
|
|
$View->int = 2;
|
|
|
|
$View->float = 1.333;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Debugger::exportVar($View);
|
2011-10-15 15:42:09 +00:00
|
|
|
$expected = <<<TEXT
|
|
|
|
object(View) {
|
|
|
|
Helpers => object(HelperCollection) {}
|
2011-12-18 03:53:21 +00:00
|
|
|
Blocks => object(ViewBlock) {}
|
2011-10-15 15:42:09 +00:00
|
|
|
plugin => null
|
|
|
|
name => ''
|
|
|
|
passedArgs => array()
|
|
|
|
helpers => array(
|
|
|
|
(int) 0 => 'Html',
|
|
|
|
(int) 1 => 'Form'
|
|
|
|
)
|
|
|
|
viewPath => ''
|
|
|
|
viewVars => array()
|
|
|
|
view => null
|
|
|
|
layout => 'default'
|
|
|
|
layoutPath => null
|
|
|
|
autoLayout => true
|
|
|
|
ext => '.ctp'
|
|
|
|
subDir => null
|
|
|
|
theme => null
|
|
|
|
cacheAction => false
|
|
|
|
validationErrors => array()
|
|
|
|
hasRendered => false
|
|
|
|
uuids => array()
|
2012-06-04 13:29:28 +00:00
|
|
|
request => object(CakeRequest) {}
|
2012-02-06 15:15:00 +00:00
|
|
|
response => object(CakeResponse) {}
|
2011-10-15 15:42:09 +00:00
|
|
|
elementCache => 'default'
|
2012-07-07 05:08:39 +00:00
|
|
|
elementCacheSettings => array()
|
2013-08-27 02:43:28 +00:00
|
|
|
Html => object(HtmlHelper) {}
|
|
|
|
Form => object(FormHelper) {}
|
2011-10-15 15:42:09 +00:00
|
|
|
int => (int) 2
|
|
|
|
float => (float) 1.333
|
2012-08-06 17:31:35 +00:00
|
|
|
|
|
|
|
TEXT;
|
|
|
|
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
|
|
|
$expected .= <<<TEXT
|
|
|
|
[protected] _passedVars => array(
|
|
|
|
(int) 0 => 'viewVars',
|
|
|
|
(int) 1 => 'autoLayout',
|
|
|
|
(int) 2 => 'ext',
|
|
|
|
(int) 3 => 'helpers',
|
|
|
|
(int) 4 => 'view',
|
|
|
|
(int) 5 => 'layout',
|
|
|
|
(int) 6 => 'name',
|
|
|
|
(int) 7 => 'theme',
|
|
|
|
(int) 8 => 'layoutPath',
|
|
|
|
(int) 9 => 'viewPath',
|
|
|
|
(int) 10 => 'request',
|
|
|
|
(int) 11 => 'plugin',
|
|
|
|
(int) 12 => 'passedArgs',
|
|
|
|
(int) 13 => 'cacheAction'
|
|
|
|
)
|
|
|
|
[protected] _scripts => array()
|
|
|
|
[protected] _paths => array()
|
2014-04-19 20:21:30 +00:00
|
|
|
[protected] _pathsForPlugin => array()
|
2012-08-06 17:31:35 +00:00
|
|
|
[protected] _parents => array()
|
|
|
|
[protected] _current => null
|
|
|
|
[protected] _currentType => ''
|
|
|
|
[protected] _stack => array()
|
|
|
|
[protected] _eventManager => object(CakeEventManager) {}
|
|
|
|
[protected] _eventManagerConfigured => false
|
|
|
|
|
|
|
|
TEXT;
|
|
|
|
}
|
|
|
|
$expected .= <<<TEXT
|
2011-10-15 15:42:09 +00:00
|
|
|
}
|
|
|
|
TEXT;
|
2012-08-06 17:31:35 +00:00
|
|
|
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2012-01-25 01:52:43 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
1 => 'Index one',
|
|
|
|
5 => 'Index five'
|
|
|
|
);
|
|
|
|
$result = Debugger::exportVar($data);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
array(
|
|
|
|
(int) 1 => 'Index one',
|
|
|
|
(int) 5 => 'Index five'
|
|
|
|
)
|
2012-06-11 00:00:34 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'key' => array(
|
|
|
|
'value'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = Debugger::exportVar($data, 1);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
array(
|
|
|
|
'key' => array(
|
|
|
|
[maximum depth reached]
|
|
|
|
)
|
|
|
|
)
|
2012-10-12 14:03:05 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
|
|
|
|
$data = false;
|
|
|
|
$result = Debugger::exportVar($data);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
false
|
2012-01-25 01:52:43 +00:00
|
|
|
TEXT;
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2013-08-06 21:14:41 +00:00
|
|
|
|
|
|
|
$file = fopen('php://output', 'w');
|
|
|
|
fclose($file);
|
|
|
|
$result = Debugger::exportVar($file);
|
|
|
|
$this->assertTextEquals('unknown', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-01-10 04:04:58 +00:00
|
|
|
/**
|
|
|
|
* Test exporting various kinds of false.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExportVarZero() {
|
|
|
|
$data = array(
|
|
|
|
'nothing' => '',
|
|
|
|
'null' => null,
|
|
|
|
'false' => false,
|
|
|
|
'szero' => '0',
|
|
|
|
'zero' => 0
|
2013-01-11 10:15:15 +00:00
|
|
|
);
|
2013-01-10 04:04:58 +00:00
|
|
|
$result = Debugger::exportVar($data);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
array(
|
|
|
|
'nothing' => '',
|
|
|
|
'null' => null,
|
|
|
|
'false' => false,
|
|
|
|
'szero' => '0',
|
|
|
|
'zero' => (int) 0
|
|
|
|
)
|
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLog method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLog() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (file_exists(LOGS . 'debug.log')) {
|
|
|
|
unlink(LOGS . 'debug.log');
|
|
|
|
}
|
2013-10-14 21:59:14 +00:00
|
|
|
CakeLog::config('file', array('engine' => 'File', 'path' => TMP . 'logs' . DS));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Debugger::log('cool');
|
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
2014-02-16 19:37:29 +00:00
|
|
|
$this->assertContains('DebuggerTest::testLog', $result);
|
|
|
|
$this->assertContains("'cool'", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-11 01:32:00 +00:00
|
|
|
unlink(LOGS . 'debug.log');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Debugger::log(array('whatever', 'here'));
|
2012-05-11 01:32:00 +00:00
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
2014-02-16 19:37:29 +00:00
|
|
|
$this->assertContains('DebuggerTest::testLog', $result);
|
|
|
|
$this->assertContains('[main]', $result);
|
|
|
|
$this->assertContains('array', $result);
|
|
|
|
$this->assertContains("'whatever',", $result);
|
|
|
|
$this->assertContains("'here'", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2014-02-16 19:35:00 +00:00
|
|
|
/**
|
|
|
|
* test log() depth
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLogDepth() {
|
|
|
|
if (file_exists(LOGS . 'debug.log')) {
|
|
|
|
unlink(LOGS . 'debug.log');
|
|
|
|
}
|
|
|
|
CakeLog::config('file', array('engine' => 'File', 'path' => TMP . 'logs' . DS));
|
|
|
|
|
2014-02-17 02:37:28 +00:00
|
|
|
$val = array(
|
|
|
|
'test' => array('key' => 'val')
|
|
|
|
);
|
2014-02-16 19:35:00 +00:00
|
|
|
Debugger::log($val, LOG_DEBUG, 0);
|
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
|
|
|
$this->assertContains('DebuggerTest::testLog', $result);
|
|
|
|
$this->assertNotContains("/'val'/", $result);
|
|
|
|
|
|
|
|
unlink(LOGS . 'debug.log');
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testDump method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDump() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$var = array('People' => array(
|
2011-10-15 15:42:09 +00:00
|
|
|
array(
|
|
|
|
'name' => 'joeseph',
|
|
|
|
'coat' => 'technicolor',
|
|
|
|
'hair_color' => 'brown'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shaft',
|
|
|
|
'coat' => 'black',
|
|
|
|
'hair' => 'black'
|
|
|
|
)
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::dump($var);
|
|
|
|
$result = ob_get_clean();
|
2013-03-01 02:31:09 +00:00
|
|
|
|
2015-07-26 13:35:03 +00:00
|
|
|
$open = PHP_SAPI === 'cli' ? "\n" : '<pre>';
|
|
|
|
$close = PHP_SAPI === 'cli' ? "\n" : '</pre>';
|
2011-10-15 19:38:45 +00:00
|
|
|
$expected = <<<TEXT
|
2013-03-01 02:31:09 +00:00
|
|
|
{$open}array(
|
2011-10-15 19:38:45 +00:00
|
|
|
'People' => array(
|
|
|
|
(int) 0 => array(
|
2012-06-11 00:00:34 +00:00
|
|
|
'name' => 'joeseph',
|
|
|
|
'coat' => 'technicolor',
|
|
|
|
'hair_color' => 'brown'
|
2011-10-15 19:38:45 +00:00
|
|
|
),
|
|
|
|
(int) 1 => array(
|
2012-06-11 00:00:34 +00:00
|
|
|
'name' => 'Shaft',
|
|
|
|
'coat' => 'black',
|
|
|
|
'hair' => 'black'
|
2011-10-15 19:38:45 +00:00
|
|
|
)
|
|
|
|
)
|
2013-03-01 02:31:09 +00:00
|
|
|
){$close}
|
2013-10-30 17:31:48 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
Debugger::dump($var, 1);
|
|
|
|
$result = ob_get_clean();
|
|
|
|
|
2015-07-26 13:35:03 +00:00
|
|
|
$open = PHP_SAPI === 'cli' ? "\n" : '<pre>';
|
|
|
|
$close = PHP_SAPI === 'cli' ? "\n" : '</pre>';
|
2013-10-30 17:31:48 +00:00
|
|
|
$expected = <<<TEXT
|
|
|
|
{$open}array(
|
|
|
|
'People' => array(
|
|
|
|
[maximum depth reached]
|
|
|
|
)
|
|
|
|
){$close}
|
2011-10-15 19:38:45 +00:00
|
|
|
TEXT;
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-07 20:44:00 +00:00
|
|
|
/**
|
|
|
|
* test getInstance.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetInstance() {
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('Debugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('DebuggerTestCaseDebugger');
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('Debugger');
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('Debugger', $result);
|
2008-12-07 20:44:00 +00:00
|
|
|
}
|
2011-06-24 08:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testNoDbCredentials
|
|
|
|
*
|
|
|
|
* If a connection error occurs, the config variable is passed through exportVar
|
|
|
|
* *** our database login credentials such that they are never visible
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-27 14:01:36 +00:00
|
|
|
public function testNoDbCredentials() {
|
2011-06-24 08:12:08 +00:00
|
|
|
$config = array(
|
2011-11-04 22:07:31 +00:00
|
|
|
'datasource' => 'mysql',
|
2011-06-24 08:12:08 +00:00
|
|
|
'persistent' => false,
|
|
|
|
'host' => 'void.cakephp.org',
|
|
|
|
'login' => 'cakephp-user',
|
|
|
|
'password' => 'cakephp-password',
|
|
|
|
'database' => 'cakephp-database',
|
|
|
|
'prefix' => ''
|
|
|
|
);
|
|
|
|
|
|
|
|
$output = Debugger::exportVar($config);
|
|
|
|
|
|
|
|
$expectedArray = array(
|
2011-11-04 22:07:31 +00:00
|
|
|
'datasource' => 'mysql',
|
2011-06-24 08:12:08 +00:00
|
|
|
'persistent' => false,
|
|
|
|
'host' => '*****',
|
|
|
|
'login' => '*****',
|
|
|
|
'password' => '*****',
|
|
|
|
'database' => '*****',
|
|
|
|
'prefix' => ''
|
|
|
|
);
|
|
|
|
$expected = Debugger::exportVar($expectedArray);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $output);
|
2011-06-24 08:12:08 +00:00
|
|
|
}
|
2011-10-27 14:01:36 +00:00
|
|
|
|
2012-08-09 02:30:27 +00:00
|
|
|
/**
|
|
|
|
* Test that exportVar() doesn't loop through recursive structures.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExportVarRecursion() {
|
|
|
|
$output = Debugger::exportVar($GLOBALS);
|
|
|
|
$this->assertContains("'GLOBALS' => [recursion]", $output);
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:01:36 +00:00
|
|
|
/**
|
|
|
|
* test trace exclude
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTraceExclude() {
|
|
|
|
$result = Debugger::trace();
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/^DebuggerTest::testTraceExclude/', $result);
|
2011-10-27 14:01:36 +00:00
|
|
|
|
|
|
|
$result = Debugger::trace(array(
|
|
|
|
'exclude' => array('DebuggerTest::testTraceExclude')
|
|
|
|
));
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/^DebuggerTest::testTraceExclude/', $result);
|
2011-10-27 14:01:36 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|