Merge pull request #17480 from tunbola/email-template-perms
[civicrm-core.git] / tests / phpunit / api / v4 / Action / ExtendFromIndividualTest.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
28 /**
29 * @group headless
30 */
31 class ExtendFromIndividualTest extends BaseCustomValueTest {
32
33 public function testGetWithNonStandardExtends() {
34
35 $customGroup = CustomGroup::create(FALSE)
36 ->addValue('name', 'MyContactFields')
37 // not Contact
38 ->addValue('extends', 'Individual')
39 ->execute()
40 ->first();
41
42 CustomField::create(FALSE)
43 ->addValue('label', 'FavColor')
44 ->addValue('custom_group_id', $customGroup['id'])
45 ->addValue('html_type', 'Text')
46 ->addValue('data_type', 'String')
47 ->execute();
48
49 $contactId = Contact::create(FALSE)
50 ->addValue('first_name', 'Johann')
51 ->addValue('last_name', 'Tester')
52 ->addValue('contact_type', 'Individual')
53 ->addValue('MyContactFields.FavColor', 'Red')
54 ->execute()
55 ->first()['id'];
56
57 $contact = Contact::get(FALSE)
58 ->addSelect('display_name')
59 ->addSelect('MyContactFields.FavColor')
60 ->addWhere('id', '=', $contactId)
61 ->execute()
62 ->first();
63
64 $this->assertEquals('Red', $contact['MyContactFields.FavColor']);
65 }
66
67 }