From b8a3da1856d02058f78b3dd5a6fc022aee4a1526 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 2 Aug 2013 23:56:24 +1200 Subject: [PATCH] partial tidy-up of test class (while waiting for tests to run :-) --- tests/phpunit/api/v3/ActivityTest.php | 363 +++++++++----------------- 1 file changed, 123 insertions(+), 240 deletions(-) diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index d99db97d38..1dff0275ba 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -47,6 +47,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { protected $_entity = 'activity'; protected $_apiversion = 3; protected $test_activity_type_value; + protected $_contactID; public $_eNoticeCompliant = TRUE; /** * Test setup for every test @@ -57,36 +58,19 @@ class api_v3_ActivityTest extends CiviUnitTestCase { public function setUp() { // Connect to the database parent::setUp(); - $tablesToTruncate = array( - 'civicrm_activity', - 'civicrm_contact', - 'civicrm_custom_group', - 'civicrm_custom_field', - ); - - $this->quickCleanup($tablesToTruncate); - - - - // Insert a row in civicrm_contact creating contact 17 - $op = new PHPUnit_Extensions_Database_Operation_Insert(); - $op->execute($this->_dbconn, - new PHPUnit_Extensions_Database_DataSet_XMLDataSet( - dirname(__FILE__) . '/dataset/contact_17.xml' - ) - ); + $this->_contactID = $this->individualCreate(); //create activity types - $activityTypes = civicrm_api('option_value', 'create', array( - 'version' => API_LATEST_VERSION, 'option_group_id' => 2, - 'name' => 'Test activity type', - 'label' => 'Test activity type', - 'sequential' => 1, - )); + $activityTypes = $this->callAPISuccess('option_value', 'create', array( + 'option_group_id' => 2, + 'name' => 'Test activity type', + 'label' => 'Test activity type', + 'sequential' => 1 + )); $this->test_activity_type_value = $activityTypes['values'][0]['value']; $this->test_activity_type_id = $activityTypes['id']; $this->_params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'activity_type_id' => $this->test_activity_type_value, 'subject' => 'test activity type id', 'activity_date_time' => '2011-06-02 14:36:13', @@ -95,10 +79,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'duration' => 120, 'location' => 'Pensulvania', 'details' => 'a test activity', - 'version' => $this->_apiversion, ); $this->_params2 = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Eat & drink', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -106,7 +89,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'discuss & eat', 'status_id' => 1, 'activity_type_id' => $this->test_activity_type_value, - 'version' => $this->_apiversion, ); // create a logged in USER since the code references it for source_contact_id $this->createLoggedInUser(); @@ -125,7 +107,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'civicrm_activity_contact', ); $this->quickCleanup($tablesToTruncate, TRUE); - civicrm_api('option_value', 'delete', array('version' => 3, 'id' => $this->test_activity_type_id)); + $this->callAPISuccess('option_value', 'delete', array('version' => 3, 'id' => $this->test_activity_type_id)); } /** @@ -155,7 +137,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreateMismatchNameType() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Test activity', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -183,12 +165,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - // we should use the session contact ID, CRM-8180 - $this->assertAPISuccess($result); + $result = $this->callAPISuccess('activity', 'create', $params); } /** @@ -204,39 +183,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - - $this->assertAPIFailure($result, - "In line " . __LINE__ - ); + $result = $this->callAPIFailure('activity', 'create', $params); } - /** - * Test civicrm_activity_id() with non-numeric duration - * @todo Come back to this in later stages - */ - /// we don't offer single parameter correctness checking at the moment - //function testActivityCreateWithNonNumericDuration( ) - //{ - // $params = array( - // 'source_contact_id' => 17, - // 'subject' => 'Discussion on Apis for v3', - // 'activity_date_time' => date('Ymd'), - // 'duration' => 'fubar', - // 'location' => 'Pensulvania', - // 'details' => 'a test activity', - // 'status_id' => 1, - // 'activity_name' => 'Test activity type' - // ); - // - // $result = civicrm_activity_create($params); - // - // $this->assertEquals( $result['is_error'], 1, - // "In line " . __LINE__ ); - //} /** * Ensure that an invalid activity type causes failure @@ -245,7 +196,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreateWithNonNumericActivityTypeId() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -264,7 +215,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreateWithUnknownActivityTypeId() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -272,7 +223,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_type_id' => 699, - 'version' => $this->_apiversion, ); $result = $this->callAPIFailure('activity', 'create', $params); @@ -280,7 +230,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { function testActivityCreateWithInvalidPriority() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -289,12 +239,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 44, 'activity_type_id' => 1, - 'version' => $this->_apiversion, ); - $result = $this->callAPIFailure('activity', 'create', $params); - $this->assertEquals("'44' is not a valid option for field priority_id", $result['error_message']); - $this->assertEquals(2001, $result['error_code']); + $result = $this->callAPIFailure('activity', 'create', $params, + "'44' is not a valid option for field priority_id"); $this->assertEquals('priority_id', $result['error_field']); } @@ -302,7 +250,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { function testActivityCreateWithValidStringPriority() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -311,17 +259,15 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 'Urgent', 'activity_type_id' => 1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertEquals(1, $result['values'][$result['id']]['priority_id']); } function testActivityCreateWithInValidStringPriority() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -330,11 +276,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'status_id' => 1, 'priority_id' => 'ergUrgent', 'activity_type_id' => 1, - 'version' => $this->_apiversion, ); - $result = $this->callAPIFailure('activity', 'create', $params); - $this->assertEquals("'ergUrgent' is not a valid option for field priority_id", $result['error_message']); + $result = $this->callAPIFailure('activity', 'create', $params, + "'ergUrgent' is not a valid option for field priority_id"); } /** @@ -342,10 +287,8 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreate() { - $result = civicrm_api('activity', 'create', $this->_params); - $this->assertAPISuccess($result, ' in line ' . __LINE__); - $result = civicrm_api('activity', 'get', $this->_params); - $this->assertAPISuccess($result, ' in line ' . __LINE__); + $result = $this->callAPISuccess('activity', 'create', $this->_params); + $result = $this->callAPISuccess('activity', 'get', $this->_params); $this->assertEquals($result['values'][$result['id']]['duration'], 120, 'in line ' . __LINE__); $this->assertEquals($result['values'][$result['id']]['subject'], 'test activity type id', 'in line ' . __LINE__); $this->assertEquals($result['values'][$result['id']]['activity_date_time'], '2011-06-02 14:36:13', 'in line ' . __LINE__); @@ -369,7 +312,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $defaults = array(); $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', 'duration' => 120, @@ -377,16 +320,14 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_type_id' => 29, - 'version' => $this->_apiversion, 'priority_id' => 1, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); //todo test target & assignee are set - $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)); + //$this->assertEquals($result['values'][$result['id']]['source_contact_id'], $this->_contactID, 'in line ' . __LINE__); + $result = $this->callAPISuccess('activity', 'get', array('id' => $result['id'], 'version' => $this->_apiversion)); $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'], '2011-03-16 00:00:00', 'in line ' . __LINE__); @@ -400,7 +341,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $description = "Example demonstrates setting & retrieving the target & source"; $subfile = "GetTargetandAssignee"; $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', 'duration' => 120, @@ -408,21 +349,19 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 1, 'activity_type_id' => 1, - 'version' => $this->_apiversion, 'priority_id' => 1, - 'target_contact_id' => 17, - 'assignee_contact_id' => 17, + 'target_contact_id' => $this->_contactID, + 'assignee_contact_id' => $this->_contactID, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); //todo test target & assignee are set - $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 = $this->callAPISuccess('activity', 'get', array('id' => $result['id'], 'version' => $this->_apiversion, 'return.assignee_contact_id' => 1, 'return.target_contact_id' => 1)); - $this->assertEquals(17, $result['values'][$result['id']]['assignee_contact_id'][0], 'in line ' . __LINE__); - $this->assertEquals(17, $result['values'][$result['id']]['target_contact_id'][0], 'in line ' . __LINE__); + $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() { @@ -435,46 +374,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->assertEquals($result, $expectedResult); } - /** - * Test civicrm_activity_create() with valid parameters for unique fields - - * set up to see if unique fields work but activity_subject doesn't - - function testActivityCreateUniqueName( ) - { - $this->markTestSkipped('test to see if api will take unique names but it doesn\'t yet'); - /*fields with unique names activity_id, - * activity_subject,activity_duration - * activity_location, activity_status_id - * activity_is_test - * activity_medium_id - - $params = array( - 'source_contact_id' => 17, - 'activity_subject' => 'Make-it-Happen Meeting', - 'activity_date_time' => date('Ymd'), - 'activity_duration' => 120, - 'activity_location' => 'Pensulvania', - 'details' => 'a test activity', - 'activity_status_id' => 1, - 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, - ); - - $result = civicrm_api('activity', 'create' , $params ); - $this->assertEquals( $result['is_error'], 0, - "Error message: " . CRM_Utils_Array::value( 'error_message', $result ) ); - - $this->assertEquals( $result['values'][$result['id']]['duration'], 120 ); - // This field gets lost - $this->assertEquals( $result['values'][$result['id']]['subject'], 'Make-it-Happen Meeting' ); - $this->assertEquals( $result['values'][$result['id']]['activity_date_time'], date('Ymd') . '000000' ); - $this->assertEquals( $result['values'][$result['id']]['location'], 'Pensulvania' ); - $this->assertEquals( $result['values'][$result['id']]['details'], 'a test activity' ); - $this->assertEquals( $result['values'][$result['id']]['status_id'], 1 ); - - } - */ - /** * Test civicrm_activity_create() with valid parameters * and some custom data @@ -483,10 +382,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPISuccess($this->_entity, 'create', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, ' in line ' . __LINE__); - $result = civicrm_api($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']); @@ -499,7 +397,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreateCustomContactRefField() { - civicrm_api('contact', 'create', array('version' => 3, 'id' => 17, 'sort_name' => 'Contact, Test')); + $this->callAPISuccess('contact', 'create', array('id' => $this->_contactID, 'sort_name' => 'Contact, Test')); $subfile = 'ContactRefCustomField'; $description = "demonstrates create with Contact Reference Custom Field"; $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); @@ -512,23 +410,21 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $customField = civicrm_api('custom_field', 'create', $params); + $customField = $this->callAPISuccess('custom_field', 'create', $params); $params = $this->_params; - $params['custom_' . $customField['id']] = "17"; + $params['custom_' . $customField['id']] = "$this->_contactID"; - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPISuccess($this->_entity, 'create', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertAPISuccess($result, ' in line ' . __LINE__); - $result = civicrm_api($this->_entity, 'get', array('return.custom_' . $customField['id'] => 1, 'version' => 3, 'id' => $result['id'])); + $result = $this->callAPISuccess($this->_entity, 'get', array('return.custom_' . $customField['id'] => 1, 'version' => 3, 'id' => $result['id'])); $this->documentMe($params, $result, __FUNCTION__, __FILE__, 'Get with Contact Ref Custom Field', 'ContactRefCustomFieldGet'); - $this->assertEquals('Contact, Test', $result['values'][$result['id']]['custom_' . $customField['id']], ' in line ' . __LINE__); - $this->assertEquals(17, $result['values'][$result['id']]['custom_' . $customField['id'] . "_id"], ' in line ' . __LINE__); - $this->assertEquals('Contact, Test', $result['values'][$result['id']]['custom_' . $customField['id'] . '_1'], ' in line ' . __LINE__); - $this->assertEquals(17, $result['values'][$result['id']]['custom_' . $customField['id'] . "_1_id"], ' in line ' . __LINE__); + $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__); + $this->assertEquals('Anderson, Anthony', $result['values'][$result['id']]['custom_' . $customField['id'] . '_1'], ' in line ' . __LINE__); + $this->assertEquals($this->_contactID, $result['values'][$result['id']]['custom_' . $customField['id'] . "_1_id"], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); } @@ -539,7 +435,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { function testActivityCreateBadTextStatus() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Discussion on Apis for v3', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -547,7 +443,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 'Invalid', 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, ); $result = $this->callAPIFailure('activity', 'create', $params); @@ -559,7 +454,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { function testActivityCreateSupportActivityStatus() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Discussion on Apis for v3', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -567,11 +462,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'activity_status_id' => 'Invalid', 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, ); - $result = $this->callAPIFailure('activity', 'create', $params); - $this->assertEquals("'Invalid' is not a valid option for field status_id", $result['error_message']); + $result = $this->callAPIFailure('activity', 'create', $params, + "'Invalid' is not a valid option for field status_id"); } @@ -583,7 +477,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => date('Ymd'), 'duration' => 120, @@ -591,11 +485,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'details' => 'a test activity', 'status_id' => 'Scheduled', 'activity_name' => 'Test activity type', - 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess('activity', 'create', $params); $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__); @@ -607,9 +499,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_get() with no params */ function testActivityGetEmpty() { - $params = array('version' => $this->_apiversion); - $result = civicrm_api('activity', 'get', $params); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess('activity', 'get', array()); } /** @@ -620,9 +510,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { // 13 $description = "Function demonstrates getting asignee_contact_id & using it to get the contact"; $subfile = 'ReturnAssigneeContact'; - $activity = civicrm_api('activity', 'create', $this->_params); + $activity = $this->callAPISuccess('activity', 'create', $this->_params); - $contact = civicrm_api('Contact', 'Create', array( + $contact = $this->callAPISuccess('Contact', 'Create', array( 'first_name' => "The Rock", 'last_name' =>'roccky', 'contact_type' => 'Individual', @@ -642,7 +532,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { ), ); - $result = civicrm_api('Activity', 'Get', $params); + $result = $this->callAPISuccess('Activity', 'Get', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile); $this->assertAPISuccess($result); @@ -651,7 +541,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->assertEquals($contact['id'], $result['values'][0]['assignee_contact_id'][0], 'In line ' . __LINE__); - $this->assertEquals(17, $result['values'][0]['api.contact.get']['values'][0]['contact_id'], 'In line ' . __LINE__); + $this->assertEquals($this->_contactID, $result['values'][0]['api.contact.get']['values'][0]['contact_id'], 'In line ' . __LINE__); $this->assertEquals($this->test_activity_type_value, $result['values'][0]['activity_type_id'], 'In line ' . __LINE__); $this->assertEquals("test activity type id", $result['values'][0]['subject'], 'In line ' . __LINE__); } @@ -661,7 +551,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testGetFilter() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', 'duration' => 120, @@ -672,18 +562,18 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'priority_id' => 1, ); - civicrm_api('Activity', 'Create', $params); - $result = civicrm_api('Activity', 'Get', array('version' => 3, 'subject' => 'Make-it-Happen Meeting')); + $this->callAPISuccess('Activity', 'Create', $params); + $result = $this->callAPISuccess('Activity', 'Get', array('version' => 3, 'subject' => 'Make-it-Happen Meeting')); $this->assertEquals(1, $result['count']); $this->assertEquals('Make-it-Happen Meeting', $result['values'][$result['id']]['subject']); - civicrm_api('Activity', 'Delete', array('version' => 3, 'id' => $result['id'])); + $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $result['id'])); } /* * test that get functioning does filtering */ function testGetStatusID() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110316', 'duration' => 120, @@ -694,22 +584,22 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'priority_id' => 1, ); - civicrm_api('Activity', 'Create', $params); - $result = civicrm_api('Activity', 'Get', array( + $this->callAPISuccess('Activity', 'Create', $params); + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => $this->_apiversion, 'activity_status_id' => '1')); $this->assertEquals(1, $result['count'], 'one activity of status 1 should exist'); - $result = civicrm_api('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => $this->_apiversion, 'status_id' => '1')); $this->assertEquals(1, $result['count'], 'status_id should also work'); - $result = civicrm_api('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => $this->_apiversion, 'activity_status_id' => '2')); $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); - $result = civicrm_api('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => $this->_apiversion, 'status_id' => '2')); $this->assertEquals(0, $result['count'], 'No activities of status 1 should exist'); @@ -722,7 +612,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testGetFilterMaxDate() { $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '20110101', 'duration' => 120, @@ -733,10 +623,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'priority_id' => 1, ); - $activityOne = civicrm_api('Activity', 'Create', $params); + $activityOne = $this->callAPISuccess('Activity', 'Create', $params); $params['activity_date_time'] = 20120216; - $activityTwo = civicrm_api('Activity', 'Create', $params); - $result = civicrm_api('Activity', 'Get', array( + $activityTwo = $this->callAPISuccess('Activity', 'Create', $params); + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => 3, )); $description = "demonstrates _low filter (at time of writing doesn't work if contact_id is set"; @@ -747,26 +637,26 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'filter.activity_date_time_low' => '20120101000000', 'sequential' => 1, ); - $result = civicrm_api('Activity', 'Get', $params); + $result = $this->callAPISuccess('Activity', 'Get', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['count'], 'in line ' . __LINE__); $description = "demonstrates _high filter (at time of writing doesn't work if contact_id is set"; $subfile = "DateTimeHigh"; $this->assertEquals('2012-02-16 00:00:00', $result['values'][0]['activity_date_time'], 'in line ' . __LINE__); $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'version' => 3, 'filter.activity_date_time_high' => '20120101000000', 'sequential' => 1, ); - $result = civicrm_api('Activity', 'Get', $params); + $result = $this->callAPISuccess('Activity', 'Get', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(1, $result['count']); $this->assertEquals('2011-01-01 00:00:00', $result['values'][0]['activity_date_time'], 'in line ' . __LINE__); - civicrm_api('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id'])); - civicrm_api('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id'])); + $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityOne['id'])); + $this->callAPISuccess('Activity', 'Delete', array('version' => 3, 'id' => $activityTwo['id'])); } /** @@ -779,7 +669,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPISuccess($this->_entity, 'create', $params); $this->assertAPISuccess($result, ' in line ' . __LINE__); // Retrieve the test value $params = array( @@ -788,7 +678,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'sequential' => 1, 'return.custom_' . $ids['custom_field_id'] => 1, ); - $result = civicrm_api('activity', 'get', $params, TRUE); + $result = $this->callAPISuccess('activity', 'get', $params, TRUE); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertAPISuccess($result, ' in line ' . __LINE__); $this->assertEquals("custom string", $result['values'][0]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); @@ -810,7 +700,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params = $this->_params; $params['custom_' . $ids['custom_field_id']] = "custom string"; - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPISuccess($this->_entity, 'create', $params); // Retrieve the test value $params = array( 'contact_id' => $this->_params['source_contact_id'], @@ -819,7 +709,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'sequential' => 1, 'return.custom_' . $ids['custom_field_id'] => 1, ); - $result = civicrm_api('activity', 'get', $params, TRUE); + $result = $this->callAPISuccess('activity', 'get', $params, TRUE); $this->assertAPISuccess($result, 'in line ' . __LINE__); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertAPISuccess($result); @@ -873,13 +763,13 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * check activity deletion with correct data */ function testDeleteActivity() { - $result = civicrm_api('activity', 'create', $this->_params); + $result = $this->callAPISuccess('activity', 'create', $this->_params); $params = array( 'id' => $result['id'], 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'delete', $params); + $result = $this->callAPISuccess('activity', 'delete', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertAPISuccess($result); } @@ -919,18 +809,18 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Test Activity', 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, ); - $result = $this->callAPIFailure('activity', 'create', $params); - $this->assertEquals($result['error_message'], 'Invalid Activity Id', "In line " . __LINE__); + $result = $this->callAPIFailure('activity', 'create', $params, + 'Invalid Activity Id'); } /** * Test civicrm_activity_update() to update an existing activity */ function testActivityUpdate() { - $result = civicrm_api('activity', 'create', $this->_params); + $result = $this->callAPISuccess('activity', 'create', $this->_params); $params = array( 'id' => $result['id'], @@ -940,12 +830,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'location' => '21, Park Avenue', 'details' => 'Lets update Meeting', 'status_id' => 1, - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'priority_id' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertAPISuccess($result, 'in line ' . __LINE__); //hack on date comparison - really we should make getAndCheck smarter to handle dates $params['activity_date_time'] = '2009-10-11 12:34:56'; @@ -966,7 +856,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { // Create an activity with custom data //this has been updated from the previous 'old format' function - need to make it work $params = array( - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'activity_date_time' => '2009-10-18', 'duration' => 120, @@ -977,20 +867,20 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'custom_' . $ids['custom_field_id'] => 'custom string', ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $activityId = $result['id']; $this->assertAPISuccess($result); - $result = civicrm_api($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 = civicrm_api('activity', 'getfields', array('version' => $this->_apiversion)); + $fields = $this->callAPISuccess('activity', 'getfields', array('version' => $this->_apiversion)); $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']])); // Update the activity with custom data $params = array( 'id' => $activityId, - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Make-it-Happen Meeting', 'status_id' => 1, 'activity_name' => 'Test activity type', @@ -999,10 +889,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'custom_' . $ids['custom_field_id'] => 'Updated my test data', 'version' => $this->_apiversion, ); - $result = civicrm_api('Activity', 'Create', $params); + $result = $this->callAPISuccess('Activity', 'Create', $params); $this->assertAPISuccess($result); - $result = civicrm_api($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__); } @@ -1037,7 +927,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params['assignee_contact_id'] = array($contact1, $contact2); $params['target_contact_id'] = array($contact2 => $contact2); - $result = civicrm_api('Activity', 'Create', $params); + $result = $this->callAPISuccess('Activity', 'Create', $params); $activityId = $result['id']; $this->assertAPISuccess($result); @@ -1047,7 +937,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'id' => $activityId, ); - $result = civicrm_api($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__); @@ -1084,12 +974,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params['assignee_contact_id'] = array($contact3 => $contact3); $params['target_contact_id'] = array($contact4 => $contact4); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertAPISuccess($result); $this->assertEquals($activityId, $result['id'], ' in line ' . __LINE__); - $result = civicrm_api( + $result = $this->callAPISuccess( $this->_entity, 'get', array( @@ -1122,7 +1012,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * value and there is none in the update params. */ function testActivityUpdateNotDate() { - $result = civicrm_api('activity', 'create', $this->_params); + $result = $this->callAPISuccess('activity', 'create', $this->_params); $params = array( 'id' => $result['id'], @@ -1131,12 +1021,12 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'location' => '21, Park Avenue', 'details' => 'Lets update Meeting', 'status_id' => 1, - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'priority_id' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertAPISuccess($result, 'in line ' . __LINE__); //hack on date comparison - really we should make getAndCheck smarter to handle dates $params['activity_date_time'] = $this->_params['activity_date_time']; @@ -1149,21 +1039,21 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * check activity update with status */ function testActivityUpdateWithStatus() { - $activity = civicrm_api('activity', 'create', $this->_params); + $activity = $this->callAPISuccess('activity', 'create', $this->_params); $this->assertAPISuccess($activity, "In line " . __LINE__); $params = array( 'id' => $activity['id'], - 'source_contact_id' => 17, + 'source_contact_id' => $this->_contactID, 'subject' => 'Hurry update works', 'status_id' => 1, 'activity_name' => 'Test activity type', 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertAPISuccess($result, "In line " . __LINE__); $this->assertEquals($result['id'], $activity['id'], "In line " . __LINE__); - /*$this->assertEquals($result['values'][$activity['id']]['source_contact_id'], 17, + /*$this->assertEquals($result['values'][$activity['id']]['source_contact_id'], $this->_contactID, "In line " . __LINE__ );*/ $this->assertEquals($result['values'][$activity['id']]['subject'], 'Hurry update works', @@ -1179,9 +1069,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * is not in the update params. */ function testActivityUpdateKeepSource() { - $activity = civicrm_api('activity', 'create', $this->_params); + $activity = $this->callAPISuccess('activity', 'create', $this->_params); // Updating the activity but not providing anything for the source contact - // (It was set as 17 earlier.) + // (It was set as $this->_contactID earlier.) $params = array( 'id' => $activity['id'], 'subject' => 'Updated Make-it-Happen Meeting', @@ -1194,9 +1084,9 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); + $result = $this->callAPISuccess('activity', 'create', $params); $this->assertAPISuccess($result, 'in line ' . __LINE__); - $findactivity = civicrm_api('Activity', 'Get', array('id' => $activity['id'], 'version' => 3)); + $findactivity = $this->callAPISuccess('Activity', 'Get', array('id' => $activity['id'], 'version' => 3)); $this->assertAPISuccess($findactivity); } @@ -1205,16 +1095,14 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activities_contact_get() */ function testActivitiesContactGet() { - $activity = civicrm_api('activity', 'create', $this->_params); - $activity2 = civicrm_api('activity', 'create', $this->_params2); - // Get activities associated with contact 17 + $activity = $this->callAPISuccess('activity', 'create', $this->_params); + $activity2 = $this->callAPISuccess('activity', 'create', $this->_params2); + // Get activities associated with contact $this->_contactID $params = array( - 'contact_id' => 17, - 'version' => $this->_apiversion, + 'contact_id' => $this->_contactID, ); - $result = civicrm_api('activity', 'get', $params); + $result = $this->callAPISuccess('activity', 'get', $params); - $this->assertAPISuccess($result, 'in line ' . __LINE__); $this->assertEquals(2, $result['count'], 'In line ' . __LINE__); $this->assertEquals($this->test_activity_type_value, $result['values'][$activity['id']]['activity_type_id'], 'In line ' . __LINE__); $this->assertEquals('Test activity type', $result['values'][$activity['id']]['activity_name'], 'In line ' . __LINE__); @@ -1225,8 +1113,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testchainedActivityGet() { - $activity = civicrm_api('Contact', 'Create', array( - 'version' => $this->_apiversion, + $activity = $this->callAPISuccess('Contact', 'Create', array( 'display_name' => "bob brown", 'contact_type' => 'Individual', 'api.activity_type.create' => array( @@ -1239,8 +1126,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { ), 'api.activity.create' => array('subject' => 'send letter', 'activity_type_id' => '$value.api.activity_type.create.values.0.value'), )); - $this->assertAPISuccess($activity, 'in line ' . __LINE__); - $result = civicrm_api('Activity', 'Get', array( + $result = $this->callAPISuccess('Activity', 'Get', array( 'version' => 3, 'id' => $activity['id'], 'return.assignee_contact_id' => 1, @@ -1265,22 +1151,19 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'last_name' => 'conberg', 'email' => 'dan.conberg@w.co.in', 'contact_type' => 'Individual', - 'version' => $this->_apiversion, ); - $contact = civicrm_api('contact', 'create', $params); + $contact = $this->callAPISuccess('contact', 'create', $params); $params = array( 'contact_id' => $contact['id'], - 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'get', $params); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess('activity', 'get', $params); $this->assertEquals($result['count'], 0, 'in line ' . __LINE__); } function testGetFields() { - $params = array('version' => 3, 'action' => 'create'); - $result = civicrm_api('activity', 'getfields', $params); + $params = array('action' => 'create'); + $result = $this->callAPISuccess('activity', 'getfields', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__, NULL, NULL, 'getfields'); $this->assertTrue(is_array($result['values']), 'get fields doesnt return values array in line ' . __LINE__); // $this->assertTrue(is_array($result['values']['priority_id']['options'])); -- 2.25.1