Merge pull request #15843 from totten/master-simplehead
[civicrm-core.git] / tests / phpunit / api / v4 / Action / UpdateContactTest.php
CommitLineData
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
22namespace api\v4\Action;
23
24use Civi\Api4\Contact;
25use api\v4\UnitTestCase;
26
27/**
28 * Class UpdateContactTest
29 * @package api\v4\Action
30 * @group headless
31 */
32class UpdateContactTest extends UnitTestCase {
33
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')
40 ->execute()
41 ->first()['id'];
42
43 $contact = Contact::update()
44 ->setCheckPermissions(FALSE)
45 ->addWhere('id', '=', $contactId)
46 ->addValue('first_name', 'Testy')
47 ->execute()
48 ->first();
49 $this->assertEquals('Testy', $contact['first_name']);
50 $this->assertEquals('Tester', $contact['last_name']);
51 }
52
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')
59 ->execute()
60 ->first()['id'];
61
62 $contact = Contact::update()
63 ->setCheckPermissions(FALSE)
64 ->addValue('id', $contactId)
65 ->addValue('first_name', 'Billy')
66 ->execute();
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']);
71 }
72
73}