From 44134d5c2d5e0256cdcc67c60278c96efdf252f0 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 25 Jul 2019 11:24:46 +1200 Subject: [PATCH] Add test to cover handling of 'gender_id' on import, remove unused code. I'm just venturing into import to fix a bug & wrote this test to step through the code. Committing as it's passing. In the process I found that it's impossible to set 'gender' as an import field & only 'gender_id' is available as a field so removing 'gender' --- CRM/Contact/Import/Parser.php | 4 ---- CRM/Contact/Import/Parser/Contact.php | 1 - .../CRM/Contact/Import/Parser/ContactTest.php | 23 ++++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index 40569f9d58..ba20561715 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -819,10 +819,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { elseif ($key == 'is_deceased' && $val) { $params[$key] = CRM_Utils_String::strtoboolstr($val); } - elseif ($key == 'gender') { - //CRM-4360 - $params[$key] = $this->checkGender($val); - } } //now format custom data. diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 542a65ba55..5981a5fab5 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1436,7 +1436,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { } break; - case 'gender': case 'gender_id': if (!self::checkGender($value)) { self::addToErrorMsg(ts('Gender'), $errorMessage); diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index d9f4c18c29..835f393f27 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -282,6 +282,8 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { /** * Test that address custom fields can be imported * FIXME: Api4 + * + * @throws \CRM_Core_Exception */ public function testAddressWithCustomData() { $ids = $this->entityCustomGroupWithSingleFieldCreate('Address', 'AddressTest.php'); @@ -295,6 +297,25 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals('Update', $address['custom_' . $ids['custom_field_id']]); } + /** + * Test gender works when you specify the label. + * + * There is an expectation that you can import by label here. + * + * @throws \CRM_Core_Exception + */ + public function testGenderLabel() { + $contactValues = [ + 'first_name' => 'Bill', + 'last_name' => 'Gates', + 'email' => 'bill.gates@microsoft.com', + 'nick_name' => 'Billy-boy', + 'gender_id' => 'Female', + ]; + $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, NULL, 'Primary', NULL, NULL]); + $this->callAPISuccessGetSingle('Contact', $contactValues); + } + /** * Test that the import parser adds the address to the primary location. * @@ -631,7 +652,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * Optional extra parameters to set. * * @return array - * @throws \Exception + * @throws \CRM_Core_Exception */ protected function setUpBaseContact($params = []) { $originalValues = array_merge([ -- 2.25.1