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
22 namespace api\v
4\Action
;
24 use Civi\Api4\Contact
;
25 use api\v
4\UnitTestCase
;
30 class NullValueTest
extends UnitTestCase
{
32 public function setUpHeadless() {
33 $format = '{contact.first_name}{ }{contact.last_name}';
34 \Civi
::settings()->set('display_name_format', $format);
35 return parent
::setUpHeadless();
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')
47 $this->assertSame('Null', $contact['last_name']);
48 $this->assertSame('Joseph Null', $contact['display_name']);
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')
60 $this->assertSame('ILoveMy LastName', $contact['display_name']);
61 $contactId = $contact['id'];
63 $contact = Contact
::update()
64 ->setCheckPermissions(FALSE)
65 ->addWhere('id', '=', $contactId)
66 ->addValue('last_name', NULL)
70 $this->assertSame(NULL, $contact['last_name']);
71 $this->assertSame('ILoveMy', $contact['display_name']);