diff options
author | Joas Schilling <coding@schilljs.com> | 2022-01-04 10:50:10 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-01-04 11:15:17 +0300 |
commit | 46ad6fa3c7ff8a2c6ab0d7ff583cab19ba04b146 (patch) | |
tree | daea2f7b774846d187bd8f255851c7dcec96f1cb /tests | |
parent | e3e73a12ef42b45f773da7e18090938ed3ff1ef3 (diff) |
Add a test with integer
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 94 |
1 files changed, 90 insertions, 4 deletions
diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index a0ae05d0149..7ff26f7e144 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -54,7 +54,7 @@ class FunctionBuilderTest extends TestCase { $this->assertEquals('foobar', $column); } - protected function clearDummyData() { + protected function clearDummyData(): void { $delete = $this->connection->getQueryBuilder(); $delete->delete('appconfig') @@ -62,7 +62,7 @@ class FunctionBuilderTest extends TestCase { $delete->executeStatement(); } - protected function addDummyData() { + protected function addDummyData(): void { $this->clearDummyData(); $insert = $this->connection->getQueryBuilder(); @@ -79,7 +79,7 @@ class FunctionBuilderTest extends TestCase { $insert->executeStatement(); } - public function testGroupConcatWithoutSeparator() { + public function testGroupConcatWithoutSeparator(): void { $this->addDummyData(); $query = $this->connection->getQueryBuilder(); @@ -90,12 +90,13 @@ class FunctionBuilderTest extends TestCase { $result = $query->execute(); $column = $result->fetchOne(); $result->closeCursor(); + $this->assertEquals('1,2,3', $column); $this->assertStringContainsString(',', $column); $actual = explode(',', $column); $this->assertEqualsCanonicalizing([1,2,3], $actual); } - public function testGroupConcatWithSeparator() { + public function testGroupConcatWithSeparator(): void { $this->addDummyData(); $query = $this->connection->getQueryBuilder(); @@ -111,6 +112,91 @@ class FunctionBuilderTest extends TestCase { $this->assertEqualsCanonicalizing([1,2,3], $actual); } + public function testGroupConcatWithSingleQuoteSeparator(): void { + $this->addDummyData(); + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->groupConcat('configkey', '\'')) + ->from('appconfig') + ->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertEquals('1\'2\'3', $column); + } + + public function testGroupConcatWithDoubleQuoteSeparator(): void { + $this->addDummyData(); + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->groupConcat('configkey', '"')) + ->from('appconfig') + ->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertEquals('1"2"3', $column); + } + + protected function clearIntDummyData(): void { + $delete = $this->connection->getQueryBuilder(); + + $delete->delete('systemtag') + ->where($delete->expr()->eq('name', $delete->createNamedParameter('group_concat'))); + $delete->executeStatement(); + } + + protected function addIntDummyData(): void { + $this->clearIntDummyData(); + $insert = $this->connection->getQueryBuilder(); + + $insert->insert('systemtag') + ->setValue('name', $insert->createNamedParameter('group_concat')) + ->setValue('visibility', $insert->createNamedParameter(1)) + ->setValue('editable', $insert->createParameter('value')); + + $insert->setParameter('value', 1); + $insert->executeStatement(); + $insert->setParameter('value', 2); + $insert->executeStatement(); + $insert->setParameter('value', 3); + $insert->executeStatement(); + } + + public function testIntGroupConcatWithoutSeparator(): void { + $this->addIntDummyData(); + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->groupConcat('editable')) + ->from('systemtag') + ->where($query->expr()->eq('name', $query->createNamedParameter('group_concat'))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertStringContainsString(',', $column); + $actual = explode(',', $column); + $this->assertEqualsCanonicalizing([1,2,3], $actual); + } + + public function testIntGroupConcatWithSeparator(): void { + $this->addIntDummyData(); + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->groupConcat('editable', '#')) + ->from('systemtag') + ->where($query->expr()->eq('name', $query->createNamedParameter('group_concat'))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertStringContainsString('#', $column); + $actual = explode('#', $column); + $this->assertEqualsCanonicalizing([1,2,3], $actual); + } + public function testMd5() { $query = $this->connection->getQueryBuilder(); |