- md5
- 20be25493fdda559e5795c74ff0e5ffa
- sha1
- 96b04b319d3c0505e6d8270d951e5361810745b3
- sha256
- a78d9202a4ead827e5fce37e8e687c9dc635896201342f90be1037eaba9ecf97
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
<?php
namespace DebugBar\Tests;
use DebugBar\DataCollector\PDO\TracedStatement;
/**
* Class TracedStatementTest
* @package DebugBar\Tests
*/
class TracedStatementTest extends DebugBarTestCase
{
/**
* Check if query parameters are being replaced in the correct way
* @bugFix Before fix it : select *
* from geral.exame_part ep
* where ep.id_exame = <1> and
* ep.id_exame_situacao = <2>'
* ep.id_exame_situacao = <1>_situacao
* @return void
*/
public function testReplacementParamsQuery()
{
$sql = 'select *
from geral.exame_part ep
where ep.id_exame = :id_exame and
ep.id_exame_situacao = :id_exame_situacao';
$params = array(
':id_exame' => 1,
':id_exame_situacao' => 2
);
$traced = new TracedStatement($sql, $params);
$expected = 'select *
from geral.exame_part ep
where ep.id_exame = <1> and
ep.id_exame_situacao = <2>';
$result = $traced->getSqlWithParams();
$this->assertEquals($expected, $result);
}
public function testReplacementParamsContainingBackReferenceSyntaxGeneratesCorrectString()
{
$hashedPassword = '$2y$10$S3Y/kSsx8Z5BPtdd9.k3LOkbQ0egtsUHBT9EGQ.spxsmaEWbrxBW2';
$sql = "UPDATE user SET password = :password";
$params = array(
':password' => $hashedPassword,
);
$traced = new TracedStatement($sql, $params);
$result = $traced->getSqlWithParams();
$expected = "UPDATE user SET password = <$hashedPassword>";
$this->assertEquals($expected, $result);
}
public function testReplacementParamsContainingPotentialAdditionalQuestionMarkPlaceholderGeneratesCorrectString()
{
$hasQuestionMark = "Asking a question?";
$string = "Asking for a friend";
$sql = "INSERT INTO questions SET question = ?, detail = ?";
$params = array($hasQuestionMark, $string);
$traced = new TracedStatement($sql, $params);
$result = $traced->getSqlWithParams();
$expected = "INSERT INTO questions SET question = <$hasQuestionMark>, detail = <$string>";
$this->assertEquals($expected, $result);
$result = $traced->getSqlWithParams("'");
$expected = "INSERT INTO questions SET question = '$hasQuestionMark', detail = '$string'";
$this->assertEquals($expected, $result);
$result = $traced->getSqlWithParams('"');
$expected = "INSERT INTO questions SET question = \"$hasQuestionMark\", detail = \"$string\"";
$this->assertEquals($expected, $result);
}
public function testReplacementParamsContainingPotentialAdditionalNamedPlaceholderGeneratesCorrectString()
{
$hasQuestionMark = "Asking a question with a :string inside";
$string = "Asking for a friend";
$sql = "INSERT INTO questions SET question = :question, detail = :string";
$params = array(
':question' => $hasQuestionMark,
':string' => $string,
);
$traced = new TracedStatement($sql, $params);
$result = $traced->getSqlWithParams();
$expected = "INSERT INTO questions SET question = <$hasQuestionMark>, detail = <$string>";
$this->assertEquals($expected, $result);
$result = $traced->getSqlWithParams("'");
$expected = "INSERT INTO questions SET question = '$hasQuestionMark', detail = '$string'";
$this->assertEquals($expected, $result);
$result = $traced->getSqlWithParams('"');
$expected = "INSERT INTO questions SET question = \"$hasQuestionMark\", detail = \"$string\"";
$this->assertEquals($expected, $result);
}
/**
* Check if query parameters are being replaced in the correct way
* @bugFix Before fix it : select *
* from geral.person p
* left join geral.contract c
* on c.id_person = p.id_person
* where c.status = <1> and
* p.status <> :status;
* @return void
*/
public function testRepeadParamsQuery()
{
$sql = 'select *
from geral.person p
left join geral.contract c
on c.id_person = p.id_person
where c.status = :status and
p.status <> :status';
$params = array(
':status' => 1
);
$traced = new TracedStatement($sql, $params);
$expected = 'select *
from geral.person p
left join geral.contract c
on c.id_person = p.id_person
where c.status = <1> and
p.status <> <1>';
$result = $traced->getSqlWithParams();
$this->assertEquals($expected, $result);
}
}
The same content is in 3 releases, Joomla 4.1.3-rc1 to 4.1.4-rc1. See them all, or every version of this file.