2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DebuggerTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:54:34 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2009-05-01 21:05:46 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
App::import('Core', 'Debugger');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DebugggerTestCaseDebuggger class
|
2008-12-07 20:44:00 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-12-07 20:44:00 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
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
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class DebuggerTest extends CakeTestCase {
|
2009-03-18 17:55:58 +00:00
|
|
|
// !!!
|
|
|
|
// !!! Be careful with changing code below as it may
|
|
|
|
// !!! change line numbers which are used in the tests
|
|
|
|
// !!!
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
2010-06-22 02:39:17 +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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
2010-06-22 02:39:17 +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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDocRef() {
|
2008-06-20 20:17:23 +00:00
|
|
|
ini_set('docref_root', '');
|
|
|
|
$this->assertEqual(ini_get('docref_root'), '');
|
|
|
|
$debugger = new Debugger();
|
|
|
|
$this->assertEqual(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
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @access public
|
2008-10-18 01:23:33 +00:00
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2008-10-18 01:23:33 +00:00
|
|
|
function testExcerpt() {
|
2009-05-01 21:05:46 +00:00
|
|
|
$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);
|
|
|
|
|
2009-07-25 17:27:17 +00:00
|
|
|
$expected = '<code><span style="color: #000000"><?php';
|
|
|
|
$expected .= '</span></code>';
|
2009-05-01 21:05:46 +00:00
|
|
|
$this->assertEqual($result[0], $expected);
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
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);
|
|
|
|
$this->assertEqual($result, '');
|
|
|
|
$out .= '';
|
|
|
|
$result = Debugger::output(true);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result[0]['error'], 'Notice');
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/Undefined variable\:\s+out/', $result[0]['description']);
|
|
|
|
$this->assertPattern('/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
|
|
|
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/Undefined variable:\s+other/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/Context:/', $result);
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/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();
|
|
|
|
$this->assertPattern('/<pre class="cake-debug">.+<\/pre>/', $result);
|
|
|
|
$this->assertPattern('/<b>Notice<\/b>/', $result);
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/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(
|
2009-07-25 17:27:17 +00:00
|
|
|
'pre' => array('class' => 'cake-debug'),
|
2009-05-01 21:05:46 +00:00
|
|
|
'a' => array(
|
|
|
|
'href' => "javascript:void(0);",
|
2010-11-15 01:19:15 +00:00
|
|
|
'onclick' => "document.getElementById('cakeErr9-trace').style.display = " .
|
|
|
|
"(document.getElementById('cakeErr9-trace').style.display == 'none'" .
|
2009-05-01 21:05:46 +00:00
|
|
|
" ? '' : 'none');"
|
|
|
|
),
|
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
|
|
|
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/Undefined variable:\s+buzz/', $result[1]);
|
2009-05-01 21:05:46 +00:00
|
|
|
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
|
|
|
|
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that changes in output formats using Debugger::output() change the templates used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
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}' .
|
|
|
|
'&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 .= '';
|
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',
|
2010-06-07 04:40:35 +00:00
|
|
|
'line' => array(), '' . (intval(__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
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testTrimPath() {
|
2008-06-19 14:23:29 +00:00
|
|
|
$this->assertEqual(Debugger::trimPath(APP), 'APP' . DS);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual(Debugger::trimPath(CAKE_CORE_INCLUDE_PATH), 'CORE');
|
|
|
|
}
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testExportVar() {
|
|
|
|
App::import('Controller');
|
|
|
|
$Controller = new Controller();
|
|
|
|
$Controller->helpers = array('Html', 'Form');
|
|
|
|
$View = new View($Controller);
|
|
|
|
$result = Debugger::exportVar($View);
|
2010-09-10 02:58:34 +00:00
|
|
|
$expected = 'View
|
|
|
|
View::$Helpers = HelperCollection object
|
2008-05-30 11:40:08 +00:00
|
|
|
View::$plugin = NULL
|
|
|
|
View::$name = ""
|
|
|
|
View::$passedArgs = array
|
|
|
|
View::$helpers = array
|
|
|
|
View::$viewPath = ""
|
|
|
|
View::$viewVars = array
|
|
|
|
View::$layout = "default"
|
|
|
|
View::$layoutPath = NULL
|
|
|
|
View::$autoLayout = true
|
|
|
|
View::$ext = ".ctp"
|
|
|
|
View::$subDir = NULL
|
2009-11-25 07:51:25 +00:00
|
|
|
View::$theme = NULL
|
2008-05-30 11:40:08 +00:00
|
|
|
View::$cacheAction = false
|
|
|
|
View::$validationErrors = array
|
|
|
|
View::$hasRendered = false
|
|
|
|
View::$modelScope = false
|
|
|
|
View::$model = NULL
|
|
|
|
View::$association = NULL
|
|
|
|
View::$field = NULL
|
|
|
|
View::$fieldSuffix = NULL
|
|
|
|
View::$modelId = NULL
|
|
|
|
View::$uuids = array
|
2008-06-11 08:54:27 +00:00
|
|
|
View::$output = false
|
2010-11-16 03:53:49 +00:00
|
|
|
View::$request = NULL
|
|
|
|
View::$elementCache = "default"';
|
2010-12-24 17:54:04 +00:00
|
|
|
|
|
|
|
$result = str_replace(array("\t", "\r\n", "\n"), "", $result);
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testLog() {
|
|
|
|
if (file_exists(LOGS . 'debug.log')) {
|
|
|
|
unlink(LOGS . 'debug.log');
|
|
|
|
}
|
|
|
|
|
|
|
|
Debugger::log('cool');
|
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/"cool"/', $result);
|
|
|
|
|
|
|
|
unlink(TMP . 'logs' . DS . 'debug.log');
|
|
|
|
|
|
|
|
Debugger::log(array('whatever', 'here'));
|
|
|
|
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log');
|
2010-01-15 04:06:48 +00:00
|
|
|
$this->assertPattern('/DebuggerTest\:\:testLog/i', $result);
|
2009-10-29 23:47:29 +00:00
|
|
|
$this->assertPattern('/\[main\]/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertPattern('/array/', $result);
|
|
|
|
$this->assertPattern('/"whatever",/', $result);
|
|
|
|
$this->assertPattern('/"here"/', $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testDump() {
|
|
|
|
$var = array('People' => array(
|
|
|
|
array(
|
|
|
|
'name' => 'joeseph',
|
|
|
|
'coat' => 'technicolor',
|
|
|
|
'hair_color' => 'brown'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shaft',
|
|
|
|
'coat' => 'black',
|
|
|
|
'hair' => 'black'
|
2008-06-05 15:20:45 +00:00
|
|
|
)
|
2008-05-30 11:40:08 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
ob_start();
|
|
|
|
Debugger::dump($var);
|
|
|
|
$result = ob_get_clean();
|
|
|
|
$expected = "<pre>array(\n\t\"People\" => array()\n)</pre>";
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-07 20:44:00 +00:00
|
|
|
/**
|
|
|
|
* test getInstance.
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* @access public
|
2008-12-07 20:44:00 +00:00
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2008-12-07 20:44:00 +00:00
|
|
|
function testGetInstance() {
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2008-12-07 20:44:00 +00:00
|
|
|
$this->assertIsA($result, 'Debugger');
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('DebuggerTestCaseDebugger');
|
2008-12-07 20:44:00 +00:00
|
|
|
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2008-12-07 20:44:00 +00:00
|
|
|
$this->assertIsA($result, 'DebuggerTestCaseDebugger');
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('Debugger');
|
2008-12-07 20:44:00 +00:00
|
|
|
$this->assertIsA($result, 'Debugger');
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|