Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-16 17:31:04 +0300
committerRobin Appelman <robin@icewind.nl>2017-03-30 12:09:26 +0300
commit4279b13270630ec1d49e91f0d4a4cbefb915a32d (patch)
tree88fa25707e44ce4cafb56f342bd6d15bd20b4053 /tests/lib
parenta65652fc1efe158bd097d573f012167cfcd26a62 (diff)
Add function builder to the query builder
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/DB/QueryBuilder/FunctionBuilderTest.php74
1 files changed, 74 insertions, 0 deletions
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 @@
+<?php
+/**
+ * @author Robin Appelman <robin@icewind.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+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());
+ }
+}