Merge pull request #15307 from seamuslee001/dev_core_1249
[civicrm-core.git] / tests / phpunit / api / v4 / Action / NullValueTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace api\v4\Action;
23
24 use Civi\Api4\Contact;
25 use api\v4\UnitTestCase;
26
27 /**
28 * @group headless
29 */
30 class NullValueTest extends UnitTestCase {
31
32 public function setUpHeadless() {
33 $format = '{contact.first_name}{ }{contact.last_name}';
34 \Civi::settings()->set('display_name_format', $format);
35 return parent::setUpHeadless();
36 }
37
38 public function testStringNull() {
39 $contact = Contact::create()
40 ->setCheckPermissions(FALSE)
41 ->addValue('first_name', 'Joseph')
42 ->addValue('last_name', 'null')
43 ->addValue('contact_type', 'Individual')
44 ->execute()
45 ->first();
46
47 $this->assertSame('Null', $contact['last_name']);
48 $this->assertSame('Joseph Null', $contact['display_name']);
49 }
50
51 public function testSettingToNull() {
52 $contact = Contact::create()
53 ->setCheckPermissions(FALSE)
54 ->addValue('first_name', 'ILoveMy')
55 ->addValue('last_name', 'LastName')
56 ->addValue('contact_type', 'Individual')
57 ->execute()
58 ->first();
59
60 $this->assertSame('ILoveMy LastName', $contact['display_name']);
61 $contactId = $contact['id'];
62
63 $contact = Contact::update()
64 ->setCheckPermissions(FALSE)
65 ->addWhere('id', '=', $contactId)
66 ->addValue('last_name', NULL)
67 ->execute()
68 ->first();
69
70 $this->assertSame(NULL, $contact['last_name']);
71 $this->assertSame('ILoveMy', $contact['display_name']);
72 }
73
74 }