Update contact_sub_type to ignore null values for consistency
authorColeman Watts <coleman@civicrm.org>
Tue, 11 Jun 2019 11:46:11 +0000 (07:46 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 12 Jun 2019 23:32:41 +0000 (19:32 -0400)
For better or worse, every other field gets ignored by bao::add functions when passed as null,
so this test had an incorrect assumption about how it was supposed to work.

CRM/Contact/BAO/Contact.php
tests/phpunit/CRM/Contact/BAO/ContactType/ContactTest.php
tests/phpunit/api/v3/ContactTest.php

index 13a040636e1cc7926d19ca1ff1bcf4f2230f10c0..59d08db1d48426524dad1b5f4d5933c802b7e560 100644 (file)
@@ -128,7 +128,7 @@ class CRM_Contact_BAO_Contact extends CRM_Contact_DAO_Contact {
       if (empty($params['contact_sub_type'])) {
         $params['contact_sub_type'] = 'null';
       }
-      else {
+      elseif ($params['contact_sub_type'] !== 'null') {
         if (!CRM_Contact_BAO_ContactType::isExtendsContactType($params['contact_sub_type'],
           $params['contact_type'], TRUE
         )
index 73a15ab8433e592f920e8a48562e522005a3feba..2e8bb603d3c4bb4f34a02edada55275ebc4b2085 100644 (file)
@@ -270,7 +270,7 @@ DELETE FROM civicrm_contact_type
     }
 
     $updateParams = [
-      'contact_sub_type' => NULL,
+      'contact_sub_type' => 'null',
       'contact_type' => 'Individual',
       'contact_id' => $contact->id,
     ];
index 24dc8dbe850033cb74ff2cd02e7ec0434384154d..78293ed7b4974ac98a44a5e2aacac565b12e367f 100644 (file)
@@ -245,11 +245,18 @@ class api_v3_ContactTest extends CiviUnitTestCase {
       'middle_name' => 'foo',
     );
     $this->callAPISuccess('contact', 'create', $params);
-    unset($params['middle_name']);
 
-    $contact = $this->callAPISuccess('contact', 'get', $params);
+    $contact = $this->callAPISuccess('contact', 'get', ['id' => $cid]);
 
     $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type']);
+
+    $this->callAPISuccess('Contact', 'create', [
+      'id' => $cid,
+      'contact_sub_type' => [],
+    ]);
+
+    $contact = $this->callAPISuccess('contact', 'get', ['id' => $cid]);
+    $this->assertTrue(empty($contact['values'][$cid]['contact_sub_type']));
   }
 
   /**