APIv4 - Reorganize test classes, don't use transactions for custom value tests
[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\Api4TestBase;
24 use Civi\Test\TransactionalInterface;
25
26 /**
27 * Class UpdateContactTest
28 * @package api\v4\Action
29 * @group headless
30 */
31 class UpdateContactTest extends Api4TestBase implements TransactionalInterface {
32
33 public function testUpdateWithIdInWhere() {
34 $contactId = Contact::create(FALSE)
35 ->addValue('first_name', 'Johann')
36 ->addValue('last_name', 'Tester')
37 ->addValue('contact_type', 'Individual')
38 ->execute()
39 ->first()['id'];
40
41 $contact = Contact::update(FALSE)
42 ->addWhere('id', '=', $contactId)
43 ->addValue('first_name', 'Testy')
44 ->execute()
45 ->first();
46 $this->assertEquals('Testy', $contact['first_name']);
47 $this->assertEquals('Tester', $contact['last_name']);
48 }
49
50 public function testUpdateWithIdInValues() {
51 $contactId = Contact::create(FALSE)
52 ->addValue('first_name', 'Bobby')
53 ->addValue('last_name', 'Tester')
54 ->addValue('contact_type', 'Individual')
55 ->execute()
56 ->first()['id'];
57
58 $contact = Contact::update(FALSE)
59 ->addValue('id', $contactId)
60 ->addValue('first_name', 'Billy')
61 ->execute();
62 $this->assertCount(1, $contact);
63 $this->assertEquals($contactId, $contact[0]['id']);
64 $this->assertEquals('Billy', $contact[0]['first_name']);
65 $this->assertEquals('Tester', $contact[0]['last_name']);
66 }
67
68 }