APIv4 - Fix fatal error on getFields when passing in contact id
authorColeman Watts <coleman@civicrm.org>
Fri, 6 May 2022 15:37:30 +0000 (11:37 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 6 May 2022 15:37:30 +0000 (11:37 -0400)
Civi/Api4/Service/Spec/RequestSpec.php
tests/phpunit/api/v4/Action/GetExtraFieldsTest.php

index d1686c601094d5f3736d49dc6a1c3f26dda640ea..f51c10985f9c280ec1f756121bc04d1cbaef609c 100644 (file)
@@ -52,7 +52,7 @@ class RequestSpec implements \Iterator {
     $this->entityTableName = CoreUtil::getTableName($entity);
     // Set contact_type from id if possible
     if ($entity === 'Contact' && empty($values['contact_type']) && !empty($values['id'])) {
-      $values['contact_type'] = \CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['id'], 'contact_id');
+      $values['contact_type'] = \CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['id'], 'contact_type');
     }
     $this->values = $values;
   }
index 2c49db46b91c92cc7951ab955836a0925f4b5b9b..4efbc606063bfe26a7ea1fb0d6642244c08737dc 100644 (file)
@@ -45,11 +45,20 @@ class GetExtraFieldsTest extends UnitTestCase {
     $this->assertNotContains('contact_type', $individualFields);
     $this->assertContains('first_name', $individualFields);
 
-    $organizationFields = $getFields->setValues(['contact_type' => 'Organization'])->execute()->column('name');
+    $orgId = Contact::create(FALSE)->addValue('contact_type', 'Organization')->execute()->first()['id'];
+    $organizationFields = $getFields->setValues(['id' => $orgId])->execute()->column('name');
+    $this->assertContains('organization_name', $organizationFields);
     $this->assertContains('sic_code', $organizationFields);
     $this->assertNotContains('contact_type', $organizationFields);
     $this->assertNotContains('first_name', $organizationFields);
     $this->assertNotContains('household_name', $organizationFields);
+
+    $hhId = Contact::create(FALSE)->addValue('contact_type', 'Household')->execute()->first()['id'];
+    $householdFields = $getFields->setValues(['id' => $hhId])->execute()->column('name');
+    $this->assertNotContains('sic_code', $householdFields);
+    $this->assertNotContains('contact_type', $householdFields);
+    $this->assertNotContains('first_name', $householdFields);
+    $this->assertContains('household_name', $householdFields);
   }
 
   public function testGetOptionsAddress() {