Has tests.
Default location was recently added for APIv3 Email.create
(https://github.com/civicrm/civicrm-core/pull/14489)
and for Address, Email, IM, OpenID and Phone in APIv4
(https://github.com/civicrm/org.civicrm.api4/pull/162)
so this brings consistency of behaviour for these entities between each other
and between APIv3 and APIv4
'name' => 'world_region',
'type' => CRM_Utils_Type::T_TEXT,
];
+ $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
+ if ($defaultLocation) {
+ $params['location_type_id']['api.default'] = $defaultLocation->id;
+ }
}
/**
*/
function _civicrm_api3_im_create_spec(&$params) {
$params['contact_id']['api.required'] = 1;
+ $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
+ if ($defaultLocation) {
+ $params['location_type_id']['api.default'] = $defaultLocation->id;
+ }
}
/**
*/
function _civicrm_api3_open_i_d_create_spec(&$params) {
$params['contact_id']['api.required'] = 1;
+ $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
+ if ($defaultLocation) {
+ $params['location_type_id']['api.default'] = $defaultLocation->id;
+ }
}
/**
$params['phone']['api.required'] = 1;
// hopefully change to use handleprimary
$params['is_primary']['api.default'] = 0;
+ $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
+ if ($defaultLocation) {
+ $params['location_type_id']['api.default'] = $defaultLocation->id;
+ }
}
/**
$this->getAndCheck($this->_params, $result['id'], 'address');
}
+ /**
+ * If no location is specified when creating a new address, it should default to
+ * the LocationType default
+ *
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testCreateAddressDefaultLocation($version) {
+ $this->_apiversion = $version;
+ $params = $this->_params;
+ unset($params['location_type_id']);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
+ }
+
/**
* FIXME: Api4
*/
$this->_apiversion = $version;
$params = $this->_params;
unset($params['location_type_id']);
- $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
- $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
}
/**
$this->assertNotNull($result['values'][$result['id']]['id']);
}
+ /**
+ * If no location is specified when creating a new IM, it should default to
+ * the LocationType default
+ *
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testCreateImDefaultLocation($version) {
+ $this->_apiversion = $version;
+ $params = $this->_params;
+ unset($params['location_type_id']);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
+ }
+
/**
* @param int $version
*
$this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
}
+ /**
+ * If no location is specified when creating a new openid, it should default to
+ * the LocationType default
+ *
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testCreateOpenIDDefaultLocation($version) {
+ $this->_apiversion = $version;
+ $params = $this->_params;
+ unset($params['location_type_id']);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
+ }
+
/**
* @param int $version
* @dataProvider versionThreeAndFour
$this->callAPISuccess('phone', 'delete', ['id' => $result['id']]);
}
+ /**
+ * If no location is specified when creating a new phone, it should default to
+ * the LocationType default
+ *
+ * @param int $version
+ * @dataProvider versionThreeAndFour
+ */
+ public function testCreatePhoneDefaultLocation($version) {
+ $this->_apiversion = $version;
+ $params = $this->_params;
+ unset($params['location_type_id']);
+ $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+ $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']);
+ $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]);
+ }
+
/**
* @param int $version
* @dataProvider versionThreeAndFour