Merge pull request #17911 from agh1/memberdetailreportautorenew
[civicrm-core.git] / tests / phpunit / api / v4 / Action / GetExtraFieldsTest.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
7d61e75f 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
7d61e75f
TO
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 |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 */
18
19
19b53e5b
C
20namespace api\v4\Action;
21
22use api\v4\UnitTestCase;
91edcf66 23use Civi\Api4\Address;
19b53e5b
C
24use Civi\Api4\Contact;
25
26/**
27 * @group headless
28 */
29class GetExtraFieldsTest extends UnitTestCase {
30
f5c0f096 31 public function testGetFieldsByContactType() {
fe806431 32 $getFields = Contact::getFields(FALSE)->addSelect('name')->setIncludeCustom(FALSE);
19b53e5b 33
f5c0f096
CW
34 $baseFields = array_column(\CRM_Contact_BAO_Contact::fields(), 'name');
35 $returnedFields = $getFields->execute()->column('name');
36 $notReturned = array_diff($baseFields, $returnedFields);
19b53e5b 37
f5c0f096 38 // With no contact_type specified, all fields should be returned
19b53e5b 39 $this->assertEmpty($notReturned);
f5c0f096
CW
40
41 $individualFields = $getFields->setValues(['contact_type' => 'Individual'])->execute()->column('name');
42 $this->assertNotContains('sic_code', $individualFields);
43 $this->assertNotContains('contact_type', $individualFields);
44 $this->assertContains('first_name', $individualFields);
45
46 $organizationFields = $getFields->setValues(['contact_type' => 'Organization'])->execute()->column('name');
47 $this->assertContains('sic_code', $organizationFields);
48 $this->assertNotContains('contact_type', $organizationFields);
49 $this->assertNotContains('first_name', $organizationFields);
50 $this->assertNotContains('household_name', $organizationFields);
19b53e5b
C
51 }
52
91edcf66 53 public function testGetOptionsAddress() {
fe806431 54 $getFields = Address::getFields(FALSE)->addWhere('name', '=', 'state_province_id')->setLoadOptions(TRUE);
91edcf66
CW
55
56 $usOptions = $getFields->setValues(['country_id' => 1228])->execute()->first();
57
58 $this->assertContains('Alabama', $usOptions['options']);
59 $this->assertNotContains('Alberta', $usOptions['options']);
60
61 $caOptions = $getFields->setValues(['country_id' => 1039])->execute()->first();
62
63 $this->assertNotContains('Alabama', $caOptions['options']);
64 $this->assertContains('Alberta', $caOptions['options']);
65 }
66
19b53e5b 67}