Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Pgsql\Tests;

use Closure;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use PHPUnit\Framework\Attributes\TestWith;
use Throwable;
Expand All @@ -17,6 +18,7 @@
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Expression\Function\ArrayMerge;
use Yiisoft\Db\Expression\Value\Param;
use Yiisoft\Db\Expression\Value\Identifier;
use Yiisoft\Db\Pgsql\Column\ArrayColumn;
use Yiisoft\Db\Pgsql\Column\IntegerColumn;
use Yiisoft\Db\Pgsql\Tests\Provider\QueryBuilderProvider;
Expand Down Expand Up @@ -676,4 +678,27 @@ public function testUpsertWithMultiOperandFunctions(
): void {
parent::testUpsertWithMultiOperandFunctions($initValues, $insertValues, $updateValues, $expectedSql, $expectedResult, $expectedParams);
}

public static function dataBuildIdentifier(): iterable
{
yield ['name', '"name"'];
yield ['t.name', '"t"."name"'];
yield ['s.t.name', '"s"."t"."name"'];
yield [['t', 'na.me'], '"t"."na.me"'];
yield ['LOWER(name)', '"LOWER(name)"'];
yield ['[[name]]', '"[[name]]"'];
yield ['{{%t}}.name', '"{{%t}}"."name"'];
yield ['*', '"*"'];
yield ['arr[1]', '"arr[1]"'];
yield ['a"b', '"a""b"'];
yield ['"a" DESC; DROP TABLE t; --', '"""a"" DESC; DROP TABLE t; --"'];
}

#[DataProvider('dataBuildIdentifier')]
public function testBuildIdentifier(string|array $name, string $expected): void
{
$qb = $this->getSharedConnection()->getQueryBuilder();

$this->assertSame($expected, $qb->buildExpression(new Identifier($name)));
}
}
7 changes: 7 additions & 0 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ public function testBooleanValues(): void
(new Query($db))->from('bool_values')->where('bool_col = :bool_col', ['bool_col' => false])->count(),
);
}

public static function dataIdentifierColumnName(): iterable
{
yield from parent::dataIdentifierColumnName();
yield 'quote: a"b' => ['a"b'];
yield 'quote: "a"' => ['"a"'];
}
}
Loading