1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?php
namespace Civi\Test\Api4\Action;
use Civi\Api4\Contact;
use Civi\Api4\CustomField;
use Civi\Api4\CustomGroup;
/**
* @group headless
*/
class ExtendFromIndividualTest extends BaseCustomValueTest {
public function testGetWithNonStandardExtends() {
$customGroup = CustomGroup::create()
->setCheckPermissions(FALSE)
->addValue('name', 'MyContactFields')
->addValue('extends', 'Individual') // not Contact
->execute()
->first();
CustomField::create()
->setCheckPermissions(FALSE)
->addValue('label', 'FavColor')
->addValue('custom_group_id', $customGroup['id'])
->addValue('html_type', 'Text')
->addValue('data_type', 'String')
->execute();
$contactId = Contact::create()
->setCheckPermissions(FALSE)
->addValue('first_name', 'Johann')
->addValue('last_name', 'Tester')
->addValue('contact_type', 'Individual')
->addValue('MyContactFields.FavColor', 'Red')
->execute()
->first()['id'];
$contact = Contact::get()
->setCheckPermissions(FALSE)
->addSelect('display_name')
->addSelect('MyContactFields.FavColor')
->addWhere('id', '=', $contactId)
->execute()
->first();
$this->assertArrayHasKey('MyContactFields', $contact);
$contactFields = $contact['MyContactFields'];
$favColor = $contactFields['FavColor'];
$this->assertEquals('Red', $favColor);
}
}
|