Merge pull request #15338 from totten/master-poc-postcommit
[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()
36 ->setCheckPermissions(FALSE)
37 ->addValue('name', 'MyContactFields')
38 // not Contact
39 ->addValue('extends', 'Individual')
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', 'Johann')
54 ->addValue('last_name', 'Tester')
55 ->addValue('contact_type', 'Individual')
56 ->addValue('MyContactFields.FavColor', 'Red')
57 ->execute()
58 ->first()['id'];
59
60 $contact = Contact::get()
61 ->setCheckPermissions(FALSE)
62 ->addSelect('display_name')
63 ->addSelect('MyContactFields.FavColor')
64 ->addWhere('id', '=', $contactId)
65 ->execute()
66 ->first();
67
68 $this->assertEquals('Red', $contact['MyContactFields.FavColor']);
69 }
70
71 }