Skip to content

Commit

Permalink
Fixing showQuery() when there is $error = false. Tests from 'zackenba…
Browse files Browse the repository at this point in the history
…rsch' added. Fixes #5983

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7978 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Jan 14, 2009
1 parent 628a79a commit 4a636b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/datasources/dbo_source.php
Expand Up @@ -508,7 +508,7 @@ function showQuery($sql) {
if (strlen($sql) > 200 && !$this->fullDebug && Configure::read() > 1) {
$sql = substr($sql, 0, 200) . '[...]';
}
if ($error && Configure::read() > 0) {
if (Configure::read() > 0) {
$out = null;
if ($error) {
trigger_error("<span style = \"color:Red;text-align:left\"><b>SQL Error:</b> {$this->error}</span>", E_USER_WARNING);
Expand Down
31 changes: 25 additions & 6 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Expand Up @@ -3719,12 +3719,6 @@ function testLog() {
$oldDebug = Configure::read('debug');
Configure::write('debug', 2);

$this->testDb->error = false;
ob_start();
$this->testDb->showQuery('Query 3');
$contents = ob_get_clean();
$this->assertNoPattern('/Query 3/s', $contents);

$this->testDb->error = true;
$this->expectError();
ob_start();
Expand All @@ -3736,6 +3730,31 @@ function testLog() {
$this->testDb->error = $oldError;
Configure::write('debug', $oldDebug);
}
/**
* test ShowQuery generation of regular and error messages
*
* @return void
**/
function testShowQuery() {
$this->testDb->error = false;
ob_start();
$this->testDb->showQuery('Some Query');
$contents = ob_get_clean();
$this->assertPattern('/Some Query/s', $contents);
$this->assertPattern('/Aff:/s', $contents);
$this->assertPattern('/Num:/s', $contents);
$this->assertPattern('/Took:/s', $contents);

$this->expectError();
$this->testDb->error = true;
ob_start();
$this->testDb->showQuery('Another Query');
$contents = ob_get_clean();
$this->assertPattern('/Another Query/s', $contents);
$this->assertNoPattern('/Aff:/s', $contents);
$this->assertNoPattern('/Num:/s', $contents);
$this->assertNoPattern('/Took:/s', $contents);
}
}

?>

0 comments on commit 4a636b9

Please sign in to comment.