diff options
author | Joas Schilling <coding@schilljs.com> | 2021-07-07 14:19:01 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-07-07 14:19:24 +0200 |
commit | 11d21e5f5c9e449a75ba24be9c018980496339e8 (patch) | |
tree | dd7be509aadce858d2e429de9fc2c1593e1ab04c | |
parent | 5d7d70538b559677e4779dca56c6ff047d4523f9 (diff) | |
download | nextcloud-server-11d21e5f5c9e449a75ba24be9c018980496339e8.tar.gz nextcloud-server-11d21e5f5c9e449a75ba24be9c018980496339e8.zip |
Add a unit test to check for casting a IQueryFunction
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php index d7f6b4ac115..6a568d7e01b 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php @@ -22,6 +22,7 @@ namespace Test\DB\QueryBuilder; use OC\DB\QueryBuilder\Literal; +use OCP\DB\QueryBuilder\IQueryBuilder; use Test\TestCase; /** @@ -109,4 +110,37 @@ class ExpressionBuilderDBTest extends TestCase { $result->closeCursor(); $this->assertEquals($match, $column); } + + public function testCastColumn(): void { + $appId = $this->getUniqueID('testing'); + $this->createConfig($appId, '1', '4'); + + $query = $this->connection->getQueryBuilder(); + $query->update('appconfig') + ->set('configvalue', + $query->expr()->castColumn( + $query->createFunction( + '(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT) + . ' + 1)' + ) + , IQueryBuilder::PARAM_STR + ) + ) + ->where($query->expr()->eq('appid', $query->createNamedParameter($appId))) + ->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('1'))); + + $result = $query->executeStatement(); + $this->assertEquals(1, $result); + } + + protected function createConfig($appId, $key, $value) { + $query = $this->connection->getQueryBuilder(); + $query->insert('appconfig') + ->values([ + 'appid' => $query->createNamedParameter($appId), + 'configkey' => $query->createNamedParameter((string) $key), + 'configvalue' => $query->createNamedParameter((string) $value), + ]) + ->execute(); + } } |