From c15b56526561f860a48b97c2918e5651e9e0c8aa Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 11 Jun 2019 07:46:11 -0400 Subject: [PATCH] Update contact_sub_type to ignore null values for consistency 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 | 2 +- .../CRM/Contact/BAO/ContactType/ContactTest.php | 2 +- tests/phpunit/api/v3/ContactTest.php | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 13a040636e..59d08db1d4 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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 ) diff --git a/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTest.php b/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTest.php index 73a15ab843..2e8bb603d3 100644 --- a/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTest.php +++ b/tests/phpunit/CRM/Contact/BAO/ContactType/ContactTest.php @@ -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, ]; diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 24dc8dbe85..78293ed7b4 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -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'])); } /** -- 2.25.1