APIv4 - Fix saving NULL as custom field value
[civicrm-core.git] / tests / phpunit / api / v4 / Action / UpdateContactTest.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 */
18
19
20 namespace api\v4\Action;
21
22 use Civi\Api4\Contact;
23 use api\v4\UnitTestCase;
24
25 /**
26 * Class UpdateContactTest
27 * @package api\v4\Action
28 * @group headless
29 */
30 class UpdateContactTest extends UnitTestCase {
31
32 public function testUpdateWithIdInWhere() {
33 $contactId = Contact::create(FALSE)
34 ->addValue('first_name', 'Johann')
35 ->addValue('last_name', 'Tester')
36 ->addValue('contact_type', 'Individual')
37 ->execute()
38 ->first()['id'];
39
40 $contact = Contact::update(FALSE)
41 ->addWhere('id', '=', $contactId)
42 ->addValue('first_name', 'Testy')
43 ->execute()
44 ->first();
45 $this->assertEquals('Testy', $contact['first_name']);
46 $this->assertEquals('Tester', $contact['last_name']);
47 }
48
49 public function testUpdateWithIdInValues() {
50 $contactId = Contact::create(FALSE)
51 ->addValue('first_name', 'Bobby')
52 ->addValue('last_name', 'Tester')
53 ->addValue('contact_type', 'Individual')
54 ->execute()
55 ->first()['id'];
56
57 $contact = Contact::update(FALSE)
58 ->addValue('id', $contactId)
59 ->addValue('first_name', 'Billy')
60 ->execute();
61 $this->assertCount(1, $contact);
62 $this->assertEquals($contactId, $contact[0]['id']);
63 $this->assertEquals('Billy', $contact[0]['first_name']);
64 $this->assertEquals('Tester', $contact[0]['last_name']);
65 }
66
67 }