From 2890c0f91eca7f45ad32c43823483efdd6e05264 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Mon, 10 Jun 2019 13:38:53 +0100 Subject: [PATCH] Set a default location in Email.create API call. Add test for this. Default location used to create the email is the default LocationType --- api/v3/Email.php | 4 ++++ tests/phpunit/api/v3/EmailTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/api/v3/Email.php b/api/v3/Email.php index 095e082e73..d1dd4ab669 100644 --- a/api/v3/Email.php +++ b/api/v3/Email.php @@ -57,6 +57,10 @@ function _civicrm_api3_email_create_spec(&$params) { $params['is_primary']['api.default'] = 0; $params['email']['api.required'] = 1; $params['contact_id']['api.required'] = 1; + $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); + if ($defaultLocation) { + $params['location_type_id']['api.default'] = $defaultLocation->id; + } } /** diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index 2a69106350..4299e87d33 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -78,6 +78,20 @@ class api_v3_EmailTest extends CiviUnitTestCase { $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); } + /** + * If no location is specified when creating a new email, it should default to + * the LocationType default + * + * Only API v3 + */ + public function testCreateEmailDefaultLocation() { + $params = $this->_params; + unset($params['location_type_id']); + $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__); + $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']); + $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); + } + /** * If a new email is set to is_primary the prev should no longer be. * -- 2.25.1