*/
function activity_getfields_example(){
-$params = array(
+$params = array(
'version' => 3,
'action' => 'create',
);
*/
function activity_getfields_expectedresult(){
- $expectedResult = array(
+ $expectedResult = array(
'is_error' => 0,
'version' => 3,
- 'count' => 28,
- 'values' => array(
- 'source_record_id' => array(
+ 'count' => 27,
+ 'values' => array(
+ 'source_record_id' => array(
'name' => 'source_record_id',
'type' => 1,
'title' => 'Source Record',
),
- 'activity_type_id' => array(
+ 'activity_type_id' => array(
'name' => 'activity_type_id',
'type' => 1,
'title' => 'Activity Type ID',
'import' => true,
'where' => 'civicrm_activity.activity_type_id',
'headerPattern' => '/(activity.)?type(.id$)/i',
- 'pseudoconstant' => array(
+ 'pseudoconstant' => array(
'optionGroupName' => 'activity_type',
),
- 'api.aliases' => array(
+ 'api.aliases' => array(
'0' => 'activity_type',
),
),
- 'activity_date_time' => array(
+ 'activity_date_time' => array(
'name' => 'activity_date_time',
'type' => 12,
'title' => 'Activity Date',
'headerPattern' => '/(activity.)?date(.time$)?/i',
'export' => true,
),
- 'phone_id' => array(
+ 'phone_id' => array(
'name' => 'phone_id',
'type' => 1,
'title' => 'Phone (called) ID',
'FKClassName' => 'CRM_Core_DAO_Phone',
),
- 'phone_number' => array(
+ 'phone_number' => array(
'name' => 'phone_number',
'type' => 2,
'title' => 'Phone (called) Number',
'maxlength' => 64,
'size' => 30,
),
- 'priority_id' => array(
+ 'priority_id' => array(
'name' => 'priority_id',
'type' => 1,
'title' => 'Priority',
- 'pseudoconstant' => array(
+ 'pseudoconstant' => array(
'optionGroupName' => 'priority',
),
- 'api.aliases' => array(
+ 'api.aliases' => array(
'0' => 'priority',
),
),
- 'parent_id' => array(
+ 'parent_id' => array(
'name' => 'parent_id',
'type' => 1,
'title' => 'Parent Activity Id',
'FKClassName' => 'CRM_Activity_DAO_Activity',
),
- 'is_auto' => array(
+ 'is_auto' => array(
'name' => 'is_auto',
'type' => 16,
'title' => 'Auto',
),
- 'relationship_id' => array(
+ 'relationship_id' => array(
'name' => 'relationship_id',
'type' => 1,
'title' => 'Relationship Id',
'default' => 'UL',
'FKClassName' => 'CRM_Contact_DAO_Relationship',
),
- 'is_current_revision' => array(
+ 'is_current_revision' => array(
'name' => 'is_current_revision',
'type' => 16,
'title' => 'Is this activity a current revision in versioning chain?',
'headerPattern' => '/(is.)?(current.)?(revision|version(ing)?)/i',
'export' => true,
),
- 'original_id' => array(
+ 'original_id' => array(
'name' => 'original_id',
'type' => 1,
'title' => 'Original Activity ID ',
'FKClassName' => 'CRM_Activity_DAO_Activity',
),
- 'weight' => array(
+ 'weight' => array(
'name' => 'weight',
'type' => 1,
'title' => 'Weight',
),
- 'id' => array(
+ 'id' => array(
'name' => 'id',
'type' => 1,
'title' => 'Activity ID',
'where' => 'civicrm_activity.id',
'export' => true,
'uniqueName' => 'activity_id',
- 'api.aliases' => array(
+ 'api.aliases' => array(
'0' => 'activity_id',
),
),
- 'subject' => array(
+ 'subject' => array(
'name' => 'subject',
'type' => 2,
'title' => 'Subject',
'export' => true,
'uniqueName' => 'activity_subject',
),
- 'duration' => array(
+ 'duration' => array(
'name' => 'duration',
'type' => 1,
'title' => 'Duration',
'export' => true,
'uniqueName' => 'activity_duration',
),
- 'location' => array(
+ 'location' => array(
'name' => 'location',
'type' => 2,
'title' => 'Location',
'export' => true,
'uniqueName' => 'activity_location',
),
- 'details' => array(
+ 'details' => array(
'name' => 'details',
'type' => 32,
'title' => 'Details',
'export' => true,
'uniqueName' => 'activity_details',
),
- 'status_id' => array(
+ 'status_id' => array(
'name' => 'status_id',
'type' => 1,
'title' => 'Activity Status Id',
'import' => true,
'where' => 'civicrm_activity.status_id',
'headerPattern' => '/(activity.)?status(.label$)?/i',
- 'pseudoconstant' => array(
+ 'pseudoconstant' => array(
'optionGroupName' => 'activity_status',
),
'uniqueName' => 'activity_status_id',
- 'api.aliases' => array(
+ 'api.aliases' => array(
'0' => 'status',
),
),
- 'is_test' => array(
+ 'is_test' => array(
'name' => 'is_test',
'type' => 16,
'title' => 'Test',
'export' => true,
'uniqueName' => 'activity_is_test',
),
- 'medium_id' => array(
+ 'medium_id' => array(
'name' => 'medium_id',
'type' => 1,
'title' => 'Activity Medium',
'default' => 'UL',
- 'pseudoconstant' => array(
+ 'pseudoconstant' => array(
'optionGroupName' => 'encounter_medium',
),
'uniqueName' => 'activity_medium_id',
- 'api.aliases' => array(
+ 'api.aliases' => array(
'0' => 'medium',
),
),
- 'result' => array(
+ 'result' => array(
'name' => 'result',
'type' => 2,
'title' => 'Result',
'size' => 45,
'uniqueName' => 'activity_result',
),
- 'is_deleted' => array(
+ 'is_deleted' => array(
'name' => 'is_deleted',
'type' => 16,
'title' => 'Activity is in the Trash',
'export' => true,
'uniqueName' => 'activity_is_deleted',
),
- 'campaign_id' => array(
+ 'campaign_id' => array(
'name' => 'campaign_id',
'type' => 1,
'title' => 'Campaign ID',
'FKClassName' => 'CRM_Campaign_DAO_Campaign',
'uniqueName' => 'activity_campaign_id',
),
- 'engagement_level' => array(
+ 'engagement_level' => array(
'name' => 'engagement_level',
'type' => 1,
'title' => 'Engagement Index',
'import' => true,
'where' => 'civicrm_activity.engagement_level',
'export' => true,
- 'pseudoconstant' => array(
+ 'pseudoconstant' => array(
'optionGroupName' => 'engagement_index',
),
'uniqueName' => 'activity_engagement_level',
),
- 'source_contact_id' => array(
+ 'source_contact_id' => array(
'name' => 'source_contact_id',
'title' => 'Activity Source Contact',
'type' => 1,
'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
'api.default' => 'user_contact_id',
),
- 'assignee_contact_id' => array(
+ 'assignee_contact_id' => array(
'name' => 'assignee_id',
'title' => 'assigned to',
'type' => 1,
'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
),
- 'target_contact_id' => array(
+ 'target_contact_id' => array(
'name' => 'target_id',
'title' => 'Activity Target',
'type' => 1,
'FKClassName' => 'CRM_Activity_DAO_ActivityContact',
),
- 'activity_status_id' => array(
- 'name' => 'status_id',
- 'title' => 'Status Id',
- 'type' => 1,
- ),
),
);
function testActivityCreateEmpty() {
$params = array('version' => $this->_apiversion);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);;
}
/**
//}
/**
- * check with incorrect required fields
+ * Ensure that an invalid activity type causes failure
+ * oddly enough this test was failing because the creation of the invalid type
+ * got added to the set up routine. Probably a mis-fix on a test
*/
function testActivityCreateWithNonNumericActivityTypeId() {
$params = array(
'location' => 'Pensulvania',
'details' => 'a test activity',
'status_id' => 1,
- 'activity_type_id' => 'Test activity type',
+ 'activity_type_id' => 'Invalid Test activity type',
'version' => $this->_apiversion,
);
$result = civicrm_api('activity', 'create', $params);
-
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
-
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
function testActivityCreateWithInvalidPriority() {
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1, "In line " . __LINE__);
+ $this->assertAPIFailure($result);
$this->assertEquals("'44' is not a valid option for field priority_id", $result['error_message']);
$this->assertEquals(2001, $result['error_code']);
$this->assertEquals('priority_id', $result['error_field']);
}
+
+
function testActivityCreateWithValidStringPriority() {
$params = array(
'source_contact_id' => 17,
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 0, "In line " . __LINE__);
+ $this->assertAPISuccess($result);
$this->assertEquals(1, $result['values'][$result['id']]['priority_id']);
}
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1, "In line " . __LINE__);
+ $this->assertAPIFailure($result);
$this->assertEquals("'ergUrgent' is not a valid option for field priority_id", $result['error_message']);
}
$result = civicrm_api('activity', 'create', $params);
//todo test target & assignee are set
- $this->assertEquals($result['is_error'], 0,
- "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
- );
+ $this->assertAPISuccess($result);
//$this->assertEquals($result['values'][$result['id']]['source_contact_id'], 17, 'in line ' . __LINE__);
$result = civicrm_api('activity', 'get', array('id' => $result['id'], 'version' => $this->_apiversion));
$result = civicrm_api('activity', 'create', $params);
//todo test target & assignee are set
- $this->assertEquals($result['is_error'], 0,
- "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
- );
+ $this->assertAPISuccess($result);
$this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
$result = civicrm_api('activity', 'get', array('id' => $result['id'], 'version' => $this->_apiversion, 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1));
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
+ $this->assertAPIFailure($result);
+ }
+
+ /**
+ * Test civicrm_activity_create() with an invalid text status_id
+ */
+ function testActivityCreateSupportActivityStatus() {
+
+ $params = array(
+ 'source_contact_id' => 17,
+ 'subject' => 'Discussion on Apis for v3',
+ 'activity_date_time' => date('Ymd'),
+ 'duration' => 120,
+ 'location' => 'Pensulvania',
+ 'details' => 'a test activity',
+ 'activity_status_id' => 'Invalid',
+ 'activity_name' => 'Test activity type',
+ 'version' => $this->_apiversion,
);
+
+ $result = civicrm_api('activity', 'create', $params);
+
+ $this->assertAPIFailure($result);
+ $this->assertEquals("'Invalid' is not a valid option for field status_id", $result['error_message']);
}
+
/**
* Test civicrm_activity_create() with valid parameters,
* using a text status_id
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 0,
- "Error message: " . CRM_Utils_Array::value('error_message', $result) . ' in line ' . __LINE__
- );
+ $this->assertAPISuccess($result);
$this->assertEquals($result['values'][$result['id']]['duration'], 120, 'in line ' . __LINE__);
$this->assertEquals($result['values'][$result['id']]['subject'], 'Make-it-Happen Meeting', 'in line ' . __LINE__);
$this->assertEquals($result['values'][$result['id']]['activity_date_time'], date('Ymd') . '000000', 'in line ' . __LINE__);
$this->assertEquals($result['values'][$result['id']]['location'], 'Pensulvania', 'in line ' . __LINE__);
$this->assertEquals($result['values'][$result['id']]['details'], 'a test activity', 'in line ' . __LINE__);
- $this->assertEquals($result['values'][$result['id']]['status_id'], 'Scheduled', 'in line ' . __LINE__);
}
/**
function testActivityGetEmpty() {
$params = array('version' => $this->_apiversion);
$result = civicrm_api('activity', 'get', $params);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $this->assertAPISuccess($result);
}
/**
$result = civicrm_api('activity', 'get', $params, TRUE);
$this->assertAPISuccess($result, 'in line ' . __LINE__);
$this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], "Error message: " . CRM_Utils_Array::value('error_message', $result));
+ $this->assertAPISuccess($result);
$this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id'], 'In line ' . __LINE__);
function testDeleteActivityForEmptyParams() {
$params = array('version' => $this->_apiversion);
$result = civicrm_api('activity', 'delete', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
'version' => $this->_apiversion,
);
$result = civicrm_api('activity', 'delete', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
function testDeleteActivityWithoutActivityType() {
$params = array('id' => 1);
$result = civicrm_api('activity', 'delete', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'delete', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
$this->assertAPISuccess($result);
}
- /**
- * check with empty array
- */
- function testActivityUpdateEmpty() {
- $params = array();
- $result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
- }
-
/**
* check if required fields are not passed
*/
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals($result['is_error'], 1, "In line " . __LINE__);
+ $this->assertAPIFailure($result);
$this->assertEquals($result['error_message'], 'Invalid Activity Id', "In line " . __LINE__);
}
$result = civicrm_api('activity', 'create', $params);
$activityId = $result['id'];
- $this->assertEquals(0, $result['is_error'],
- "Error message: " . CRM_Utils_Array::value('error_message', $result)
- );
+ $this->assertAPISuccess($result);
$result = civicrm_api($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id']));
$this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$this->assertEquals("2009-10-18 00:00:00", $result['values'][$result['id']]['activity_date_time'], ' in line ' . __LINE__);
'version' => $this->_apiversion,
);
$result = civicrm_api('Activity', 'Create', $params);
- $this->assertEquals(0, $result['is_error'],
- "Error message: " . CRM_Utils_Array::value('error_message', $result)
- );
+ $this->assertAPISuccess($result);
$result = civicrm_api($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id']));
$this->assertEquals("Updated my test data", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
$params['target_contact_id'] = array($contact4 => $contact4);
$result = civicrm_api('activity', 'create', $params);
- $this->assertEquals(0, $result['is_error'],
- "Error message: " . CRM_Utils_Array::value('error_message', $result)
- );
+ $this->assertAPISuccess($result);
$this->assertEquals($activityId, $result['id'], ' in line ' . __LINE__);
));
}
- /**
- * check civicrm_activities_contact_get() with empty array
- */
- function testActivityContactGetEmpty() {
- $params = array();
- $result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 1, "In line " . __LINE__);
- }
-
- /**
- * Test civicrm_activity_contact_get() with missing source_contact_id
- */
- function testActivitiesContactGetWithInvalidParameter() {
- $params = NULL;
- $result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
- }
-
/**
* Test civicrm_activity_contact_get() with invalid Contact Id
*/
function testActivitiesContactGetWithInvalidContactId() {
$params = array('contact_id' => NULL);
$result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
$params = array('contact_id' => 'contact');
$result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
$params = array('contact_id' => 2.4);
$result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 1,
- "In line " . __LINE__
- );
+ $this->assertAPIFailure($result);
}
/**
'version' => $this->_apiversion,
);
$result = civicrm_api('activity', 'get', $params);
- $this->assertEquals($result['is_error'], 0, 'in line ' . __LINE__);
+ $this->assertAPISuccess($result);
$this->assertEquals($result['count'], 0, 'in line ' . __LINE__);
}