FunctionBuilderTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @author Robin Appelman <robin@icewind.nl>
  4. *
  5. * @license AGPL-3.0
  6. *
  7. * This code is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License, version 3,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License, version 3,
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>
  18. *
  19. */
  20. namespace Test\DB\QueryBuilder;
  21. use OC\DB\QueryBuilder\Literal;
  22. use Test\TestCase;
  23. /**
  24. * Class FunctionBuilderTest
  25. *
  26. * @group DB
  27. *
  28. * @package Test\DB\QueryBuilder
  29. */
  30. class FunctionBuilderTest extends TestCase {
  31. /** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */
  32. protected $connection;
  33. protected function setUp() {
  34. parent::setUp();
  35. $this->connection = \OC::$server->getDatabaseConnection();
  36. }
  37. public function testConcat() {
  38. $query = $this->connection->getQueryBuilder();
  39. $query->select($query->func()->concat($query->createNamedParameter('foo'), new Literal("'bar'")));
  40. $this->assertEquals('foobar', $query->execute()->fetchColumn());
  41. }
  42. public function testMd5() {
  43. $query = $this->connection->getQueryBuilder();
  44. $query->select($query->func()->md5($query->createNamedParameter('foobar')));
  45. $this->assertEquals(md5('foobar'), $query->execute()->fetchColumn());
  46. }
  47. public function testSubstring() {
  48. $query = $this->connection->getQueryBuilder();
  49. $query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2), $query->createNamedParameter(2)));
  50. $this->assertEquals('oo', $query->execute()->fetchColumn());
  51. }
  52. public function testSubstringNoLength() {
  53. $query = $this->connection->getQueryBuilder();
  54. $query->select($query->func()->substring($query->createNamedParameter('foobar'), new Literal(2)));
  55. $this->assertEquals('oobar', $query->execute()->fetchColumn());
  56. }
  57. }