CRM-20953 Importing contacts with deceased_date not setting is_deceased
authoreileen <emcnaughton@wikimedia.org>
Mon, 24 Jul 2017 13:25:01 +0000 (01:25 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 24 Jul 2017 13:26:51 +0000 (01:26 +1200)
CRM/Contact/Import/Parser/Contact.php
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index 9f9733b74ac5e152de2ba3204e4c873e7727fb18..d236d87bc4b6d212fa24d599a03b6ab15364949d 100644 (file)
@@ -1920,6 +1920,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser {
       }
       elseif ($key == 'deceased_date' && $val) {
         CRM_Utils_Date::convertToDefaultDate($params, $dateType, $key);
+        $params['is_deceased'] = 1;
       }
       elseif ($key == 'is_deceased' && $val) {
         $params[$key] = CRM_Utils_String::strtoboolstr($val);
index c0636236890a52050384f6fb838f842d09e025d5..0fd4347b8c27e06b954bac3fc0e84cb412db9b34 100644 (file)
@@ -183,6 +183,25 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase {
     $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
   }
 
+  /**
+   * Test that the import parser adds the address to the primary location.
+   *
+   * @throws \Exception
+   */
+  public function testImportDeceased() {
+    list($contactValues) = $this->setUpBaseContact();
+    CRM_Core_Session::singleton()->set("dateTypes", 1);
+    $contactValues['birth_date'] = '1910-12-17';
+    $contactValues['deceased_date'] = '2010-12-17';
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
+    $contact = $this->callAPISuccessGetSingle('Contact', $contactValues);
+    $this->assertEquals('1910-12-17', $contact['birth_date']);
+    $this->assertEquals('2010-12-17', $contact['deceased_date']);
+    $this->assertEquals(1, $contact['is_deceased']);
+    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+  }
+
+
   /**
    * Test that the import parser adds the address to the primary location.
    *