4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 namespace api\v
4\Action
;
23 use api\v
4\UnitTestCase
;
24 use Civi\Api4\Contact
;
29 class SqlExpressionTest
extends UnitTestCase
{
31 public function testSelectNull() {
32 Contact
::create()->addValue('first_name', 'bob')->setCheckPermissions(FALSE)->execute();
33 $result = Contact
::get()
34 ->addSelect('NULL AS nothing', 'NULL', 'NULL AS b*d char', 'first_name AS firsty')
35 ->addWhere('first_name', '=', 'bob')
39 $this->assertNull($result['nothing']);
40 $this->assertNull($result['NULL']);
41 $this->assertNull($result['b_d_char']);
42 $this->assertEquals('bob', $result['firsty']);
43 $this->assertArrayNotHasKey('b*d char', $result);
46 public function testSelectNumbers() {
47 Contact
::create()->addValue('first_name', 'bob')->setCheckPermissions(FALSE)->execute();
48 $result = Contact
::get()
49 ->addSelect('first_name', 123, 45.678, '-55 AS neg')
50 ->addWhere('first_name', '=', 'bob')
54 $this->assertEquals('bob', $result['first_name']);
55 $this->assertEquals('123', $result['123']);
56 $this->assertEquals('-55', $result['neg']);
57 $this->assertEquals('45.678', $result['45_678']);
60 public function testSelectStrings() {
61 Contact
::create()->addValue('first_name', 'bob')->setCheckPermissions(FALSE)->execute();
62 $result = Contact
::get()
63 ->addSelect('first_name AS bob')
64 ->addSelect('"hello world" AS hi')
65 ->addSelect('"can\'t \"quote\"" AS quot')
66 ->addWhere('first_name', '=', 'bob')
70 $this->assertEquals('bob', $result['bob']);
71 $this->assertEquals('hello world', $result['hi']);
72 $this->assertEquals('can\'t "quote"', $result['quot']);