Merge pull request #17900 from aydun/wiki_changes
[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 */
18
19
20 namespace api\v4\Action;
21
22 use Civi\Api4\Contact;
23 use Civi\Api4\CustomField;
24 use Civi\Api4\CustomGroup;
25
26 /**
27 * @group headless
28 */
29 class ExtendFromIndividualTest extends BaseCustomValueTest {
30
31 public function testGetWithNonStandardExtends() {
32
33 $customGroup = CustomGroup::create(FALSE)
34 ->addValue('name', 'MyContactFields')
35 // not Contact
36 ->addValue('extends', 'Individual')
37 ->execute()
38 ->first();
39
40 CustomField::create(FALSE)
41 ->addValue('label', 'FavColor')
42 ->addValue('custom_group_id', $customGroup['id'])
43 ->addValue('html_type', 'Text')
44 ->addValue('data_type', 'String')
45 ->execute();
46
47 $contactId = Contact::create(FALSE)
48 ->addValue('first_name', 'Johann')
49 ->addValue('last_name', 'Tester')
50 ->addValue('contact_type', 'Individual')
51 ->addValue('MyContactFields.FavColor', 'Red')
52 ->execute()
53 ->first()['id'];
54
55 $contact = Contact::get(FALSE)
56 ->addSelect('display_name')
57 ->addSelect('MyContactFields.FavColor')
58 ->addWhere('id', '=', $contactId)
59 ->execute()
60 ->first();
61
62 $this->assertEquals('Red', $contact['MyContactFields.FavColor']);
63 }
64
65 }