debug() may output path that is incorrectly truncated

This happens when debug is called in core source files that resides in
a different directory to the app.
This commit is contained in:
Rachman Chavik 2012-05-28 10:19:44 +07:00
parent fb0cc50700
commit 483d7124dd
2 changed files with 13 additions and 12 deletions

View file

@ -691,7 +691,8 @@ class BasicsTest extends CakeTestCase {
'this-is-a-test' 'this-is-a-test'
########################### ###########################
EXPECTED; EXPECTED;
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -705,7 +706,7 @@ EXPECTED;
</pre> </pre>
</div> </div>
EXPECTED; EXPECTED;
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -719,7 +720,7 @@ EXPECTED;
</pre> </pre>
</div> </div>
EXPECTED; EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -733,7 +734,7 @@ EXPECTED;
</pre> </pre>
</div> </div>
EXPECTED; EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10); $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -754,9 +755,9 @@ EXPECTED;
########################### ###########################
EXPECTED; EXPECTED;
if (php_sapi_name() == 'cli') { if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17); $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else { } else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19); $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
} }
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -778,9 +779,9 @@ EXPECTED;
########################### ###########################
EXPECTED; EXPECTED;
if (php_sapi_name() == 'cli') { if (php_sapi_name() == 'cli') {
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17); $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
} else { } else {
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19); $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
} }
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -793,7 +794,7 @@ EXPECTED;
'<div>this-is-a-test</div>' '<div>this-is-a-test</div>'
########################### ###########################
EXPECTED; EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -805,7 +806,7 @@ EXPECTED;
'<div>this-is-a-test</div>' '<div>this-is-a-test</div>'
########################### ###########################
EXPECTED; EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
ob_start(); ob_start();
@ -817,7 +818,7 @@ EXPECTED;
'<div>this-is-a-test</div>' '<div>this-is-a-test</div>'
########################### ###########################
EXPECTED; EXPECTED;
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8); $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }

View file

@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
$lineInfo = ''; $lineInfo = '';
if ($showFrom) { if ($showFrom) {
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array')); $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
$file = substr($trace[0]['file'], strlen(ROOT)); $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
$line = $trace[0]['line']; $line = $trace[0]['line'];
} }
$html = <<<HTML $html = <<<HTML