Merge pull request #17163 from jitendrapurohit/core-1731
[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 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace api\v4\Action;
23
24use api\v4\UnitTestCase;
91edcf66 25use Civi\Api4\Address;
19b53e5b
C
26use Civi\Api4\Contact;
27
28/**
29 * @group headless
30 */
31class GetExtraFieldsTest extends UnitTestCase {
32
f5c0f096
CW
33 public function testGetFieldsByContactType() {
34 $getFields = Contact::getFields()->setCheckPermissions(FALSE)->addSelect('name')->setIncludeCustom(FALSE);
19b53e5b 35
f5c0f096
CW
36 $baseFields = array_column(\CRM_Contact_BAO_Contact::fields(), 'name');
37 $returnedFields = $getFields->execute()->column('name');
38 $notReturned = array_diff($baseFields, $returnedFields);
19b53e5b 39
f5c0f096 40 // With no contact_type specified, all fields should be returned
19b53e5b 41 $this->assertEmpty($notReturned);
f5c0f096
CW
42
43 $individualFields = $getFields->setValues(['contact_type' => 'Individual'])->execute()->column('name');
44 $this->assertNotContains('sic_code', $individualFields);
45 $this->assertNotContains('contact_type', $individualFields);
46 $this->assertContains('first_name', $individualFields);
47
48 $organizationFields = $getFields->setValues(['contact_type' => 'Organization'])->execute()->column('name');
49 $this->assertContains('sic_code', $organizationFields);
50 $this->assertNotContains('contact_type', $organizationFields);
51 $this->assertNotContains('first_name', $organizationFields);
52 $this->assertNotContains('household_name', $organizationFields);
19b53e5b
C
53 }
54
91edcf66
CW
55 public function testGetOptionsAddress() {
56 $getFields = Address::getFields()->setCheckPermissions(FALSE)->addWhere('name', '=', 'state_province_id')->setLoadOptions(TRUE);
57
58 $usOptions = $getFields->setValues(['country_id' => 1228])->execute()->first();
59
60 $this->assertContains('Alabama', $usOptions['options']);
61 $this->assertNotContains('Alberta', $usOptions['options']);
62
63 $caOptions = $getFields->setValues(['country_id' => 1039])->execute()->first();
64
65 $this->assertNotContains('Alabama', $caOptions['options']);
66 $this->assertContains('Alberta', $caOptions['options']);
67 }
68
19b53e5b 69}