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
;
28 * Class UpdateContactTest
29 * @package api\v4\Action
32 class UpdateContactTest
extends UnitTestCase
{
34 public function testUpdateWithIdInWhere() {
35 $contactId = Contact
::create()
36 ->setCheckPermissions(FALSE)
37 ->addValue('first_name', 'Johann')
38 ->addValue('last_name', 'Tester')
39 ->addValue('contact_type', 'Individual')
43 $contact = Contact
::update()
44 ->setCheckPermissions(FALSE)
45 ->addWhere('id', '=', $contactId)
46 ->addValue('first_name', 'Testy')
49 $this->assertEquals('Testy', $contact['first_name']);
50 $this->assertEquals('Tester', $contact['last_name']);
53 public function testUpdateWithIdInValues() {
54 $contactId = Contact
::create()
55 ->setCheckPermissions(FALSE)
56 ->addValue('first_name', 'Bobby')
57 ->addValue('last_name', 'Tester')
58 ->addValue('contact_type', 'Individual')
62 $contact = Contact
::update()
63 ->setCheckPermissions(FALSE)
64 ->addValue('id', $contactId)
65 ->addValue('first_name', 'Billy')
67 $this->assertCount(1, $contact);
68 $this->assertEquals($contactId, $contact[0]['id']);
69 $this->assertEquals('Billy', $contact[0]['first_name']);
70 $this->assertEquals('Tester', $contact[0]['last_name']);