Merge pull request #17920 from eileenmcnaughton/dupe
[civicrm-core.git] / tests / phpunit / api / v4 / Action / UpdateCustomValueTest.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 */
18
19
19b53e5b
C
20namespace api\v4\Action;
21
22use Civi\Api4\Contact;
23use Civi\Api4\CustomField;
24use Civi\Api4\CustomGroup;
25use CRM_Core_BAO_CustomValueTable as CustomValueTable;
26
27/**
28 * @group headless
29 */
30class UpdateCustomValueTest extends BaseCustomValueTest {
31
32 public function testGetWithCustomData() {
33
fe806431 34 $customGroup = CustomGroup::create(FALSE)
19b53e5b
C
35 ->addValue('name', 'MyContactFields')
36 ->addValue('extends', 'Contact')
37 ->execute()
38 ->first();
39
fe806431 40 CustomField::create(FALSE)
19b53e5b
C
41 ->addValue('label', 'FavColor')
42 ->addValue('custom_group_id', $customGroup['id'])
43 ->addValue('html_type', 'Text')
44 ->addValue('data_type', 'String')
45 ->execute();
46
fe806431 47 $contactId = Contact::create(FALSE)
19b53e5b
C
48 ->addValue('first_name', 'Red')
49 ->addValue('last_name', 'Tester')
50 ->addValue('contact_type', 'Individual')
51 ->addValue('MyContactFields.FavColor', 'Red')
52 ->execute()
53 ->first()['id'];
54
fe806431 55 Contact::update(FALSE)
19b53e5b
C
56 ->addWhere('id', '=', $contactId)
57 ->addValue('first_name', 'Red')
58 ->addValue('last_name', 'Tester')
59 ->addValue('contact_type', 'Individual')
60 ->addValue('MyContactFields.FavColor', 'Blue')
61 ->execute();
62
63 $result = CustomValueTable::getEntityValues($contactId, 'Contact');
64
65 $this->assertEquals(1, count($result));
66 $this->assertContains('Blue', $result);
67 }
68
69}