aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVitor Mattos <vitor@php.rio>2022-01-03 11:04:05 -0300
committerVitor Mattos <vitor@php.rio>2022-01-03 21:41:38 -0300
commitfb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f (patch)
tree15fe65abdae05c775dd4c484319c2f7319a88ac0 /tests
parent7b9fea85b6e893aca874b7a0a07866443822005a (diff)
downloadnextcloud-server-fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f.tar.gz
nextcloud-server-fb6a9f308d01148a35f8aa7c8cb6b4a5fa5b220f.zip
Add unit test
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/DB/QueryBuilder/FunctionBuilderTest.php40
1 files changed, 33 insertions, 7 deletions
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();