*/
function _civicrm_api3_activity_create_spec(&$params) {
- // Default for source_contact_id = currently logged in user.
- $params['source_contact_id']['api.default'] = 'user_contact_id';
-
$params['status_id']['api.aliases'] = array('activity_status');
$params['assignee_contact_id'] = array(
'FKClassName' => 'CRM_Contact_DAO_Contact',
'api.default' => 'user_contact_id',
'FKApiName' => 'Contact',
+ 'api.required' => TRUE,
);
$params['case_id'] = array(
elseif (is_numeric($realContactId)) {
$fieldValue = $realContactId;
}
+ elseif (is_null($realContactId) && empty($fieldInfo['api.required'])) {
+ // If not mandatory this will be OK. If mandatory it should fail.
+ $fieldValue = NULL;
+ }
}
if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
_civicrm_api3_api_match_pseudoconstant($fieldValue, $entity, $fieldName, $fieldInfo, $op);
// After swapping options, ensure we have an integer(s)
foreach ((array) ($fieldValue) as $value) {
- if ($value && !is_numeric($value) && $value !== 'null' && !is_array($value)) {
+ if ($value && !is_numeric($value) && $value !== 'null' && $value !== NULL && !is_array($value)) {
throw new API_Exception("$fieldName is not a valid integer", 2001, array('error_field' => $fieldName, "type" => "integer"));
}
}
$this->callAPISuccess('activity', 'create', $params);
}
+ /**
+ * CRM-20316 this should fail based on validation with no logged in user.
+ *
+ * Since the field is required the validation should reject the default.
+ */
+ public function testActivityCreateWithMissingContactIdNoLoggedInUser() {
+ CRM_Core_Session::singleton()->set('userID', NULL);
+ $params = array(
+ 'subject' => 'Make-it-Happen Meeting',
+ 'activity_date_time' => date('Ymd'),
+ 'duration' => 120,
+ 'location' => 'Pennsylvania',
+ 'details' => 'a test activity',
+ 'status_id' => 1,
+ 'activity_name' => 'Test activity type',
+ );
+
+ $this->callAPIFailure('activity', 'create', $params, 'source_contact_id is not a valid integer');
+ }
+
/**
* Test civicrm_activity_id() with non-numeric source_contact_id.
*/
$this->getAndCheck($this->_params, $result['id'], 'mailing');
}
+ /**
+ * Per CRM-20316 the mailing should still create without created_id (not mandatory).
+ */
+ public function testMailerCreateSuccessNoCreatedID() {
+ unset($this->_params['created_id']);
+ $result = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__);
+ $this->getAndCheck($this->_params, $result['id'], 'mailing');
+ }
+
/**
*
*/