*
* (PHP 5)
*
- * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
- * @copyright Copyright CiviCRM LLC (C) 2009
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
+ * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
+ * @copyright Copyright CiviCRM LLC (C) 2009
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
* GNU Affero General Public License version 3
- * @version $Id: ActivityTest.php 31254 2010-12-15 10:09:29Z eileen $
- * @package CiviCRM
+ * @version $Id: ActivityTest.php 31254 2010-12-15 10:09:29Z eileen $
+ * @package CiviCRM
*
* This file is part of CiviCRM
*
/**
* Test APIv3 civicrm_activity_* functions
*
- * @package CiviCRM_APIv3
- * @subpackage API_Activity
+ * @package CiviCRM_APIv3
+ * @subpackage API_Activity
*/
-
class api_v3_ActivityTest extends CiviUnitTestCase {
protected $_params;
protected $_params2;
'option_group_id' => 2,
'name' => 'Test activity type',
'label' => 'Test activity type',
- 'sequential' => 1
+ 'sequential' => 1,
));
$this->test_activity_type_value = $activityTypes['values'][0]['value'];
$this->test_activity_type_id = $activityTypes['id'];
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
- *
- * @access protected
*/
- function tearDown() {
+ public function tearDown() {
$tablesToTruncate = array(
'civicrm_contact',
'civicrm_activity',
}
/**
- * check with empty array
+ * Check with empty array
*/
- function testActivityCreateEmpty() {
+ public function testActivityCreateEmpty() {
$result = $this->callAPIFailure('activity', 'create', array());
}
/**
- * check if required fields are not passed
+ * Check if required fields are not passed
*/
- function testActivityCreateWithoutRequired() {
+ public function testActivityCreateWithoutRequired() {
$params = array(
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
* Test civicrm_activity_create() with mismatched activity_type_id
* and activity_name
*/
- function testActivityCreateMismatchNameType() {
+ public function testActivityCreateMismatchNameType() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Test activity',
/**
* Test civicrm_activity_id() with missing source_contact_id is put with the current user.
*/
- function testActivityCreateWithMissingContactId() {
+ public function testActivityCreateWithMissingContactId() {
$params = array(
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => date('Ymd'),
/**
* Test civicrm_activity_id() with non-numeric source_contact_id
*/
- function testActivityCreateWithNonNumericContactId() {
+ public function testActivityCreateWithNonNumericContactId() {
$params = array(
'source_contact_id' => 'fubar',
'subject' => 'Make-it-Happen Meeting',
* 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() {
+ public function testActivityCreateWithNonNumericActivityTypeId() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
}
/**
- * check with incorrect required fields
+ * Check with incorrect required fields
*/
- function testActivityCreateWithUnknownActivityTypeId() {
+ public function testActivityCreateWithUnknownActivityTypeId() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
$result = $this->callAPIFailure('activity', 'create', $params);
}
- function testActivityCreateWithInvalidPriority() {
+ public function testActivityCreateWithInvalidPriority() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
}
-
- function testActivityCreateWithValidStringPriority() {
+ public function testActivityCreateWithValidStringPriority() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
$this->assertEquals(1, $result['values'][$result['id']]['priority_id']);
}
- function testActivityCreateWithInValidStringPriority() {
+ public function testActivityCreateWithInValidStringPriority() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
/**
* Test civicrm_activity_create() with valid parameters
*/
- function testActivityCreate() {
+ public function testActivityCreate() {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$result = $this->callAPISuccess('activity', 'get', $this->_params);
/**
* Test civicrm_activity_create() with valid parameters - use type_id
*/
- function testActivityCreateCampaignTypeID() {
+ public function testActivityCreateCampaignTypeID() {
$this->enableCiviCampaign();
$defaults = array();
$this->assertEquals($result['values'][$result['id']]['status_id'], 1, 'in line ' . __LINE__);
}
- function testActivityReturnTargetAssignee() {
+ public function testActivityReturnTargetAssignee() {
$description = "Example demonstrates setting & retrieving the target & source";
- $subfile = "GetTargetandAssignee";
- $params = array(
+ $subfile = "GetTargetandAssignee";
+ $params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
'activity_date_time' => '20110316',
);
$result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
- $result = $this->callAPISuccess('activity', 'get', array('id' => $result['id'], 'version' => $this->_apiversion, 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1));
+ $result = $this->callAPISuccess('activity', 'get', array(
+ 'id' => $result['id'],
+ 'version' => $this->_apiversion,
+ 'return.assignee_contact_id' => 1,
+ 'return.target_contact_id' => 1
+ ));
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['assignee_contact_id'][0], 'in line ' . __LINE__);
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['target_contact_id'][0], 'in line ' . __LINE__);
}
- function testActivityCreateExample() {
+ public function testActivityCreateExample() {
/**
* Test civicrm_activity_create() using example code
*/
- require_once 'api/v3/examples/ActivityCreate.php';
+ require_once 'api/v3/examples/Activity/Create.php';
$result = activity_create_example();
$expectedResult = activity_create_expectedresult();
$this->assertEquals($result, $expectedResult);
* Test civicrm_activity_create() with valid parameters
* and some custom data
*/
- function testActivityCreateCustom() {
+ public function testActivityCreateCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$params['custom_' . $ids['custom_field_id']] = "custom string";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
- $result = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id']));
+ $result = $this->callAPISuccess($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->customFieldDelete($ids['custom_field_id']);
* Test civicrm_activity_create() with valid parameters
* and some custom data
*/
- function testActivityCreateCustomContactRefField() {
+ public function testActivityCreateCustomContactRefField() {
$this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test'));
- $subfile = 'ContactRefCustomField';
+ $subfile = 'ContactRefCustomField';
$description = "demonstrates create with Contact Reference Custom Field";
- $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
- $params = array(
+ $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+ $params = array(
'custom_group_id' => $ids['custom_group_id'],
'name' => 'Worker_Lookup',
'label' => 'Worker Lookup',
$params['custom_' . $customField['id']] = "$this->_contactID";
$result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile, 'Create');
- $result = $this->callAPIAndDocument($this->_entity, 'get', array('return.custom_' . $customField['id'] => 1, 'id' => $result['id']), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet', 'get');
+ $result = $this->callAPIAndDocument($this->_entity, 'get', array(
+ 'return.custom_' . $customField['id'] => 1,
+ 'id' => $result['id']
+ ), __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet', 'get');
$this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id']], ' in line ' . __LINE__);
$this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__);
/**
* Test civicrm_activity_create() with an invalid text status_id
*/
- function testActivityCreateBadTextStatus() {
+ public function testActivityCreateBadTextStatus() {
$params = array(
'source_contact_id' => $this->_contactID,
/**
* Test civicrm_activity_create() with an invalid text status_id
*/
- function testActivityCreateSupportActivityStatus() {
+ public function testActivityCreateSupportActivityStatus() {
$params = array(
'source_contact_id' => $this->_contactID,
* Test civicrm_activity_create() with valid parameters,
* using a text status_id
*/
- function testActivityCreateTextStatus() {
-
+ public function testActivityCreateTextStatus() {
$params = array(
'source_contact_id' => $this->_contactID,
/**
* Test civicrm_activity_get() with no params
*/
- function testActivityGetEmpty() {
+ public function testActivityGetEmpty() {
$result = $this->callAPISuccess('activity', 'get', array());
}
/**
* Test civicrm_activity_get() with a good activity ID
*/
- function testActivityGetGoodID1() {
+ public function testActivityGetGoodID1() {
// Insert rows in civicrm_activity creating activities 4 and
// 13
$description = "Function demonstrates getting asignee_contact_id & using it to get the contact";
- $subfile = 'ReturnAssigneeContact';
- $activity = $this->callAPISuccess('activity', 'create', $this->_params);
+ $subfile = 'ReturnAssigneeContact';
+ $activity = $this->callAPISuccess('activity', 'create', $this->_params);
$contact = $this->callAPISuccess('Contact', 'Create', array(
- 'first_name' => "The Rock",
- 'last_name' =>'roccky',
- 'contact_type' => 'Individual',
- 'version' => 3,
- 'api.activity.create' => array(
- 'id' => $activity['id'], 'assignee_contact_id' => '$value.id',
- ),
- ));
+ 'first_name' => "The Rock",
+ 'last_name' => 'roccky',
+ 'contact_type' => 'Individual',
+ 'version' => 3,
+ 'api.activity.create' => array(
+ 'id' => $activity['id'],
+ 'assignee_contact_id' => '$value.id',
+ ),
+ ));
$params = array(
'activity_id' => $activity['id'],
/*
* test that get functioning does filtering
*/
- function testGetFilter() {
+ public function testGetFilter() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
/**
* Test civicrm_activity_get() with filter target_contact_id
*/
- function testActivityGetTargetFilter() {
+ public function testActivityGetTargetFilter() {
$params = $this->_params;
$contact1Params = array(
'first_name' => 'John',
$params['target_contact_id'] = array($contact2 => $contact2);
$activity = $this->callAPISuccess('Activity', 'Create', $params);
- $activityget = $this->callAPISuccess('Activity', 'get', array('id' => $activity['id'], 'target_contact_id' => $contact2,'return.target_contact_id' => 1));
+ $activityget = $this->callAPISuccess('Activity', 'get', array(
+ 'id' => $activity['id'],
+ 'target_contact_id' => $contact2,
+ 'return.target_contact_id' => 1
+ ));
$this->assertEquals($activity['id'], $activityget['id'], 'In line ' . __LINE__);
$this->assertEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0], 'In line ' . __LINE__);
- $activityget = $this->callAPISuccess('activity', 'get', array('target_contact_id' => $this->_contactID,'return.target_contact_id' => 1,'id' => $activity['id']));
+ $activityget = $this->callAPISuccess('activity', 'get', array(
+ 'target_contact_id' => $this->_contactID,
+ 'return.target_contact_id' => 1,
+ 'id' => $activity['id']
+ ));
if ($activityget['count'] > 0) {
$this->assertNotEquals($contact2, $activityget['values'][$activityget['id']]['target_contact_id'][0], 'In line ' . __LINE__);
}
/*
* test that get functioning does filtering
*/
- function testGetStatusID() {
+ public function testGetStatusID() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
$result = $this->callAPISuccess('Activity', 'Get', array('activity_status_id' => '2'));
$this->assertEquals(0, $result['count'], 'No activities of status 1 should exist');
$result = $this->callAPISuccess('Activity', 'Get', array(
- 'version' => $this->_apiversion,
- 'status_id' => '2'));
+ 'version' => $this->_apiversion,
+ 'status_id' => '2'
+ ));
$this->assertEquals(0, $result['count'], 'No activities of status 1 should exist');
-
}
/*
* test that get functioning does filtering
*/
- function testGetFilterMaxDate() {
+ public function testGetFilterMaxDate() {
$params = array(
'source_contact_id' => $this->_contactID,
'subject' => 'Make-it-Happen Meeting',
$params['activity_date_time'] = 20120216;
$activityTwo = $this->callAPISuccess('Activity', 'Create', $params);
$result = $this->callAPISuccess('Activity', 'Get', array(
- 'version' => 3,
- ));
+ 'version' => 3,
+ ));
$description = "demonstrates _low filter (at time of writing doesn't work if contact_id is set";
$subfile = "DateTimeLow";
$this->assertEquals(2, $result['count']);
* Test civicrm_activity_get() with a good activity ID which
* has associated custom data
*/
- function testActivityGetGoodIDCustom() {
+ public function testActivityGetGoodIDCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
* Test civicrm_activity_get() with a good activity ID which
* has associated custom data
*/
- function testActivityGetContact_idCustom() {
+ public function testActivityGetContact_idCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
}
/**
- * check activity deletion with empty params
+ * Check activity deletion with empty params
*/
- function testDeleteActivityForEmptyParams() {
+ public function testDeleteActivityForEmptyParams() {
$params = array('version' => $this->_apiversion);
$result = $this->callAPIFailure('activity', 'delete', $params);
}
/**
- * check activity deletion without activity id
+ * Check activity deletion without activity id
*/
- function testDeleteActivityWithoutId() {
+ public function testDeleteActivityWithoutId() {
$params = array(
'activity_name' => 'Meeting',
'version' => $this->_apiversion,
}
/**
- * check activity deletion without activity type
+ * Check activity deletion without activity type
*/
- function testDeleteActivityWithoutActivityType() {
+ public function testDeleteActivityWithoutActivityType() {
$params = array('id' => 1);
$result = $this->callAPIFailure('activity', 'delete', $params);
}
/**
- * check activity deletion with incorrect data
+ * Check activity deletion with incorrect data
*/
- function testDeleteActivityWithIncorrectActivityType() {
+ public function testDeleteActivityWithIncorrectActivityType() {
$params = array(
'id' => 1,
'activity_name' => 'Test Activity',
}
/**
- * check activity deletion with correct data
+ * Check activity deletion with correct data
*/
- function testDeleteActivity() {
+ public function testDeleteActivity() {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$params = array(
'id' => $result['id'],
}
/**
- * check if required fields are not passed
+ * Check if required fields are not passed
*/
- function testActivityUpdateWithoutRequired() {
+ public function testActivityUpdateWithoutRequired() {
$params = array(
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
/**
* Test civicrm_activity_update() with non-numeric id
*/
- function testActivityUpdateWithNonNumericId() {
+ public function testActivityUpdateWithNonNumericId() {
$params = array(
'id' => 'lets break it',
'activity_name' => 'Meeting',
}
/**
- * check with incorrect required fields
+ * Check with incorrect required fields
*/
- function testActivityUpdateWithIncorrectContactActivityType() {
+ public function testActivityUpdateWithIncorrectContactActivityType() {
$params = array(
'id' => 1,
'activity_name' => 'Test Activity',
/**
* Test civicrm_activity_update() to update an existing activity
*/
- function testActivityUpdate() {
+ public function testActivityUpdate() {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$params = array(
* Test civicrm_activity_update() with valid parameters
* and some custom data
*/
- function testActivityUpdateCustom() {
+ public function testActivityUpdateCustom() {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params = $this->_params;
$result = $this->callAPISuccess('activity', 'create', $params);
$activityId = $result['id'];
- $result = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id']));
+ $result = $this->callAPISuccess($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__);
$fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion));
);
$result = $this->callAPISuccess('Activity', 'Create', $params);
- $result = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => 3, 'id' => $result['id']));
+ $result = $this->callAPISuccess($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__);
}
* Test civicrm_activity_update() for core activity fields
* and some custom data
*/
- function testActivityUpdateCheckCoreFields() {
+ public function testActivityUpdateCheckCoreFields() {
$params = $this->_params;
$contact1Params = array(
'first_name' => 'John',
'version' => $this->_apiversion,
'id' => $activityId,
);
- $result = $this->callAPISuccess($this->_entity, 'get',$getParams );
+ $result = $this->callAPISuccess($this->_entity, 'get', $getParams);
$assignee = $result['values'][$result['id']]['assignee_contact_id'];
$target = $result['values'][$result['id']]['target_contact_id'];
$this->assertEquals(2, count($assignee), ' in line ' . __LINE__);
'return.assignee_contact_id' => 1,
'return.target_contact_id' => 1,
'return.source_contact_id' => 1,
- 'id' => $result['id']
+ 'id' => $result['id'],
)
);
* Test civicrm_activity_update() where the DB has a date_time
* value and there is none in the update params.
*/
- function testActivityUpdateNotDate() {
+ public function testActivityUpdateNotDate() {
$result = $this->callAPISuccess('activity', 'create', $this->_params);
$params = array(
}
/**
- * check activity update with status
+ * Check activity update with status
*/
- function testActivityUpdateWithStatus() {
+ public function testActivityUpdateWithStatus() {
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
$params = array(
'id' => $activity['id'],
* Test civicrm_activity_update() where the source_contact_id
* is not in the update params.
*/
- function testActivityUpdateKeepSource() {
+ public function testActivityUpdateKeepSource() {
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
// Updating the activity but not providing anything for the source contact
// (It was set as $this->_contactID earlier.)
/**
* Test civicrm_activities_contact_get()
*/
- function testActivitiesContactGet() {
+ public function testActivitiesContactGet() {
$activity = $this->callAPISuccess('activity', 'create', $this->_params);
$activity2 = $this->callAPISuccess('activity', 'create', $this->_params2);
// Get activities associated with contact $this->_contactID
$this->assertEquals('Test activity type', $result['values'][$activity['id']]['activity_name'], 'In line ' . __LINE__);
$this->assertEquals('Test activity type', $result['values'][$activity2['id']]['activity_name'], 'In line ' . __LINE__);
}
+
/*
* test chained Activity format
*/
- function testchainedActivityGet() {
+ public function testchainedActivityGet() {
$activity = $this->callAPISuccess('Contact', 'Create', array(
- 'display_name' => "bob brown",
- 'contact_type' => 'Individual',
- 'api.activity_type.create' => array(
- 'weight' => '2',
- 'label' => 'send out letters',
- 'filter' => 0,
- 'is_active' => 1,
- 'is_optgroup' => 1,
- 'is_default' => 0,
- ), 'api.activity.create' => array('subject' => 'send letter', 'activity_type_id' => '$value.api.activity_type.create.values.0.value'),
- ));
+ 'display_name' => "bob brown",
+ 'contact_type' => 'Individual',
+ 'api.activity_type.create' => array(
+ 'weight' => '2',
+ 'label' => 'send out letters',
+ 'filter' => 0,
+ 'is_active' => 1,
+ 'is_optgroup' => 1,
+ 'is_default' => 0,
+ ),
+ 'api.activity.create' => array(
+ 'subject' => 'send letter',
+ 'activity_type_id' => '$value.api.activity_type.create.values.0.value'
+ ),
+ ));
$result = $this->callAPISuccess('Activity', 'Get', array(
- 'id' => $activity['id'],
- 'return.assignee_contact_id' => 1,
- 'api.contact.get' => array('api.pledge.get' => 1),
- ));
+ 'id' => $activity['id'],
+ 'return.assignee_contact_id' => 1,
+ 'api.contact.get' => array('api.pledge.get' => 1),
+ ));
}
/**
* Test civicrm_activity_contact_get() with invalid Contact Id
*/
- function testActivitiesContactGetWithInvalidContactId() {
+ public function testActivitiesContactGetWithInvalidContactId() {
$params = array('contact_id' => 'contact');
$result = $this->callAPIFailure('activity', 'get', $params);
}
/**
* Test civicrm_activity_contact_get() with contact having no Activity
*/
- function testActivitiesContactGetHavingNoActivity() {
+ public function testActivitiesContactGetHavingNoActivity() {
$params = array(
'first_name' => 'dan',
'last_name' => 'conberg',
$this->assertEquals($result['count'], 0, 'in line ' . __LINE__);
}
- function testGetFields() {
+ public function testGetFields() {
$params = array('action' => 'create');
$result = $this->callAPIAndDocument('activity', 'getfields', $params, __FUNCTION__, __FILE__, NULL, NULL, 'getfields');
$this->assertTrue(is_array($result['values']), 'get fields doesnt return values array in line ' . __LINE__);