Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Action; |
23 | ||
a4c7afc0 | 24 | use Civi\Api4\Activity; |
19b53e5b C |
25 | use Civi\Api4\Contact; |
26 | use api\v4\UnitTestCase; | |
27 | ||
28 | /** | |
29 | * @group headless | |
30 | */ | |
31 | class NullValueTest extends UnitTestCase { | |
32 | ||
33 | public function setUpHeadless() { | |
34 | $format = '{contact.first_name}{ }{contact.last_name}'; | |
35 | \Civi::settings()->set('display_name_format', $format); | |
36 | return parent::setUpHeadless(); | |
37 | } | |
38 | ||
39 | public function testStringNull() { | |
40 | $contact = Contact::create() | |
41 | ->setCheckPermissions(FALSE) | |
42 | ->addValue('first_name', 'Joseph') | |
43 | ->addValue('last_name', 'null') | |
44 | ->addValue('contact_type', 'Individual') | |
45 | ->execute() | |
46 | ->first(); | |
47 | ||
48 | $this->assertSame('Null', $contact['last_name']); | |
49 | $this->assertSame('Joseph Null', $contact['display_name']); | |
50 | } | |
51 | ||
52 | public function testSettingToNull() { | |
53 | $contact = Contact::create() | |
54 | ->setCheckPermissions(FALSE) | |
55 | ->addValue('first_name', 'ILoveMy') | |
56 | ->addValue('last_name', 'LastName') | |
57 | ->addValue('contact_type', 'Individual') | |
58 | ->execute() | |
59 | ->first(); | |
60 | ||
61 | $this->assertSame('ILoveMy LastName', $contact['display_name']); | |
62 | $contactId = $contact['id']; | |
63 | ||
64 | $contact = Contact::update() | |
65 | ->setCheckPermissions(FALSE) | |
66 | ->addWhere('id', '=', $contactId) | |
67 | ->addValue('last_name', NULL) | |
68 | ->execute() | |
69 | ->first(); | |
70 | ||
71 | $this->assertSame(NULL, $contact['last_name']); | |
72 | $this->assertSame('ILoveMy', $contact['display_name']); | |
73 | } | |
74 | ||
a4c7afc0 CW |
75 | public function testSaveWithReload() { |
76 | $contact = Contact::create() | |
77 | ->setCheckPermissions(FALSE) | |
78 | ->addValue('first_name', 'Firsty') | |
79 | ->addValue('last_name', 'Lasty') | |
80 | ->execute() | |
81 | ->first(); | |
82 | ||
83 | $activity = Activity::create() | |
84 | ->setCheckPermissions(FALSE) | |
85 | ->addValue('source_contact_id', $contact['id']) | |
86 | ->addValue('activity_type_id', 1) | |
87 | ->addValue('subject', 'hello') | |
88 | ->execute() | |
89 | ->first(); | |
90 | ||
91 | $this->assertEquals('hello', $activity['subject']); | |
92 | ||
93 | $saved = Activity::save() | |
94 | ->setCheckPermissions(FALSE) | |
95 | ->addRecord(['id' => $activity['id'], 'subject' => NULL]) | |
96 | ->execute() | |
97 | ->first(); | |
98 | ||
99 | $this->assertNull($saved['subject']); | |
100 | $this->assertArrayNotHasKey('activity_date_time', $saved); | |
101 | ||
102 | $saved = Activity::save() | |
103 | ->setCheckPermissions(FALSE) | |
104 | ->addRecord(['id' => $activity['id'], 'subject' => NULL]) | |
105 | ->setReload(TRUE) | |
106 | ->execute() | |
107 | ->first(); | |
108 | ||
109 | $this->assertNull($saved['subject']); | |
110 | $this->assertArrayHasKey('activity_date_time', $saved); | |
111 | ||
112 | } | |
113 | ||
19b53e5b | 114 | } |