From 4279b13270630ec1d49e91f0d4a4cbefb915a32d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 16 Jan 2017 15:31:04 +0100 Subject: Add function builder to the query builder Signed-off-by: Robin Appelman --- tests/lib/DB/QueryBuilder/FunctionBuilderTest.php | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/lib/DB/QueryBuilder/FunctionBuilderTest.php (limited to 'tests/lib/DB/QueryBuilder/FunctionBuilderTest.php') diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php new file mode 100644 index 00000000000..b1ef3d7bb75 --- /dev/null +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -0,0 +1,74 @@ + + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace Test\DB\QueryBuilder; + +use OC\DB\QueryBuilder\Literal; +use Test\TestCase; + +/** + * Class FunctionBuilderTest + * + * @group DB + * + * @package Test\DB\QueryBuilder + */ +class FunctionBuilderTest extends TestCase { + /** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */ + protected $connection; + + protected function setUp() { + parent::setUp(); + + $this->connection = \OC::$server->getDatabaseConnection(); + } + + public function testConcat() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->fun()->concat($query->createNamedParameter('foo'), new Literal("'bar'"))); + + $this->assertEquals('foobar', $query->execute()->fetchColumn()); + } + + public function testMd5() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->fun()->md5($query->createNamedParameter('foobar'))); + + $this->assertEquals(md5('foobar'), $query->execute()->fetchColumn()); + } + + public function testSubstring() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->fun()->substring($query->createNamedParameter('foobar'), new Literal(2), $query->createNamedParameter(2))); + + $this->assertEquals('oo', $query->execute()->fetchColumn()); + } + + public function testSubstringNoLength() { + $query = $this->connection->getQueryBuilder(); + + $query->select($query->fun()->substring($query->createNamedParameter('foobar'), new Literal(2))); + + $this->assertEquals('oobar', $query->execute()->fetchColumn()); + } +} -- cgit v1.2.3