From 3adc374c3d926db906409cf9f0a4e8423d73fbe6 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 13 Oct 2026 12:06:20 +0300 Subject: [PATCH] Add expression + Add and implement it in --- tests/QueryBuilderTest.php | 25 +++++++++++++++++++++++++ tests/QueryTest.php | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index cd68738a6..45d4c3644 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -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; @@ -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; @@ -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))); + } } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index cb7d4162b..529e819c4 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -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"']; + } }