diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-03-24 16:17:37 +0100 |
---|---|---|
committer | Vincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com> | 2022-03-24 20:35:02 +0000 |
commit | efebbacca4d5a5045271eeecd209c8a0b4253598 (patch) | |
tree | e9e7d33b8ca9ec8f9fb5c287e31f317d2c94435e /tests | |
parent | 7dc3eb1e9e9a2cf6b52dc17986b4bbca395f0998 (diff) | |
download | nextcloud-server-efebbacca4d5a5045271eeecd209c8a0b4253598.tar.gz nextcloud-server-efebbacca4d5a5045271eeecd209c8a0b4253598.zip |
Add octetLength and charLength to function builder, and tests
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 3f4b8bb7524..6b13051c2c1 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -336,6 +336,52 @@ class FunctionBuilderTest extends TestCase { $this->assertGreaterThan(1, $column); } + public function octetLengthProvider() { + return [ + ['', 0], + ['foobar', 6], + ['fé', 3], + ['šđčćž', 10], + ]; + } + + /** + * @dataProvider octetLengthProvider + */ + public function testOctetLength(string $str, int $bytes) { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->octetLength($query->createNamedParameter($str, IQueryBuilder::PARAM_STR))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertEquals($bytes, $column); + } + + public function charLengthProvider() { + return [ + ['', 0], + ['foobar', 6], + ['fé', 2], + ['šđčćž', 5], + ]; + } + + /** + * @dataProvider charLengthProvider + */ + public function testCharLength(string $str, int $bytes) { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->func()->charLength($query->createNamedParameter($str, IQueryBuilder::PARAM_STR))); + + $result = $query->execute(); + $column = $result->fetchOne(); + $result->closeCursor(); + $this->assertEquals($bytes, $column); + } + private function setUpMinMax($value) { $query = $this->connection->getQueryBuilder(); |