From fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 3 Jan 2022 11:04:05 -0300 Subject: Add unit test Signed-off-by: Vitor Mattos --- tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 40 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index b824b86fecf..938ab6d2b05 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -54,12 +54,38 @@ class FunctionBuilderTest extends TestCase { $this->assertEquals('foobar', $column); } - public function testGroupConcatWithoutSeparatorAndOrder() { + protected function clearDummyData() { + $delete = $this->connection->getQueryBuilder(); + + $delete->delete('appconfig') + ->where($delete->expr()->eq('appid', $delete->createNamedParameter('group_concat', IQueryBuilder::PARAM_STR))); + $delete->executeStatement(); + } + + protected function addDummyData() { + $this->clearDummyData(); + $insert = $this->connection->getQueryBuilder(); + + $insert->insert('appconfig') + ->setValue('appid', $insert->createNamedParameter('group_concat', IQueryBuilder::PARAM_STR)) + ->setValue('configvalue', $insert->createNamedParameter('unittest', IQueryBuilder::PARAM_STR)) + ->setValue('configkey', $insert->createParameter('value', IQueryBuilder::PARAM_STR)); + + $insert->setParameter('value', '1'); + $insert->executeStatement(); + $insert->setParameter('value', '3'); + $insert->executeStatement(); + $insert->setParameter('value', '2'); + $insert->executeStatement(); + } + + public function testGroupConcatWithoutSeparator() { + $this->addDummyData(); $query = $this->connection->getQueryBuilder(); - $query->select($query->func()->groupConcat('appid')); - $query->from('appconfig') - ->setMaxResults(1); + $query->select($query->func()->groupConcat('configkey')) + ->from('appconfig') + ->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); $result = $query->execute(); $column = $result->fetchOne(); @@ -70,9 +96,9 @@ class FunctionBuilderTest extends TestCase { public function testGroupConcatWithSeparatorAndOrder() { $query = $this->connection->getQueryBuilder(); - $query->select($query->func()->groupConcat('appid', '#', 'appid')); - $query->from('appconfig') - ->setMaxResults(1); + $query->select($query->func()->groupConcat('configkey', '#')) + ->from('appconfig') + ->where($query->expr()->eq('appid', $query->createNamedParameter('group_concat'))); $result = $query->execute(); $column = $result->fetchOne(); -- cgit v1.2.3