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