From 7fbb4198d03adaf0b536941641b438103998efa3 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 28 Jul 2013 22:12:59 +1200 Subject: [PATCH] CRM-13072 more test class upgrades --- tests/phpunit/api/v3/GroupContactTest.php | 48 +--- tests/phpunit/api/v3/PledgeTest.php | 218 +++++--------- tests/phpunit/api/v3/PriceFieldTest.php | 47 +-- tests/phpunit/api/v3/ProfileTest.php | 161 +++-------- tests/phpunit/api/v3/RelationshipTest.php | 2 +- tests/phpunit/api/v3/RelationshipTypeTest.php | 40 +-- tests/phpunit/api/v3/ReportTemplateTest.php | 19 +- tests/phpunit/api/v3/SettingTest.php | 269 +++++++----------- tests/phpunit/api/v3/SurveyRespondantTest.php | 29 +- tests/phpunit/api/v3/SurveyTest.php | 2 +- tests/phpunit/api/v3/SystemTest.php | 8 +- tests/phpunit/api/v3/UFGroupTest.php | 168 +++-------- 12 files changed, 316 insertions(+), 695 deletions(-) diff --git a/tests/phpunit/api/v3/GroupContactTest.php b/tests/phpunit/api/v3/GroupContactTest.php index ab368ef115..555c6278b3 100644 --- a/tests/phpunit/api/v3/GroupContactTest.php +++ b/tests/phpunit/api/v3/GroupContactTest.php @@ -32,7 +32,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { protected $_contactId; protected $_contactId1; - protected $_apiversion; + protected $_apiversion = 3; protected $_groupId1; public $_eNoticeCompliant = True; @@ -50,7 +50,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { * @todo set up calls function that doesn't work @ the moment */ function setUp() { - $this->_apiversion = 3; parent::setUp(); $this->_contactId = $this->individualCreate(NULL); @@ -59,10 +58,9 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $params = array( 'contact_id' => $this->_contactId, 'group_id' => $this->_groupId1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('group_contact', 'create', $params); + $result = $this->callAPISuccess('group_contact', 'create', $params); $group = array( 'name' => 'Test Group 2', @@ -71,17 +69,13 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only', - 'version' => $this->_apiversion, ); $this->_groupId2 = $this->groupCreate($group, 3); $params = array( 'contact_id.1' => $this->_contactId, 'group_id' => $this->_groupId2, - 'version' => $this->_apiversion, ); - //@todo uncomment me when I work - //civicrm_group_contact_create( $params ); $this->_group = array( $this->_groupId1 => array('title' => 'New Test Group Created', @@ -108,10 +102,8 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { function testGet() { $params = array( 'contact_id' => $this->_contactId, - 'version' => $this->_apiversion, ); - $result = civicrm_api('group_contact', 'get', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); foreach ($result['values'] as $v) { $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']); $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']); @@ -124,12 +116,10 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $subfile = "GetWithGroupID"; $params = array( 'group_id' => $this->_groupId1, - 'version' => $this->_apiversion, 'api.group.get' => 1, 'sequential' => 1, ); - $result = civicrm_api('group_contact', 'get', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile); + $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); foreach ($result['values'][0]['api.group.get']['values'] as $values) { $key = $values['id']; $this->assertEquals($values['title'], $this->_group[$key]['title']); @@ -137,14 +127,6 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { } } - - ///////////////// civicrm_group_contact_add methods - function testCreateWithWrongParamsType() { - $params = 1; - $groups = $this->callAPIFailure('group_contact', 'create', $params); - $this->assertEquals($groups['error_message'], 'Input variable `params` is not an array'); - } - function testCreateWithEmptyParams() { $params = array(); $groups = $this->callAPIFailure('group_contact', 'create', $params); @@ -155,9 +137,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { function testCreateWithoutGroupIdParams() { $params = array( - 'contact_id' => $this->_contactId, - 'version' => $this->_apiversion, - ); + 'contact_id' => $this->_contactId, ); $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); @@ -165,9 +145,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { function testCreateWithoutContactIdParams() { $params = array( - 'group_id' => $this->_groupId1, - 'version' => $this->_apiversion, - ); + 'group_id' => $this->_groupId1, ); $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); } @@ -180,21 +158,16 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'prefix_id' => 3, 'suffix_id' => 3, 'email' => 'amiteshwar.prasad@civicrm.org', - 'contact_type' => 'Individual', - 'version' => $this->_apiversion, - ); + 'contact_type' => 'Individual', ); $this->_contactId1 = $this->individualCreate($cont); $params = array( 'contact_id' => $this->_contactId, 'contact_id.2' => $this->_contactId1, 'group_id' => $this->_groupId1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('group_contact', 'create', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['not_added'], 1, "in line " . __LINE__); $this->assertEquals($result['added'], 1, "in line " . __LINE__); $this->assertEquals($result['total_count'], 2, "in line " . __LINE__); @@ -205,12 +178,9 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { $params = array( 'contact_id' => $this->_contactId, 'group_id' => 1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('group_contact', 'delete', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['removed'], 1, "in line " . __LINE__); $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); } diff --git a/tests/phpunit/api/v3/PledgeTest.php b/tests/phpunit/api/v3/PledgeTest.php index ac96afe8bc..b7c5fbead2 100644 --- a/tests/phpunit/api/v3/PledgeTest.php +++ b/tests/phpunit/api/v3/PledgeTest.php @@ -69,7 +69,6 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'frequency_day' => 15, 'installments' => 5, 'sequential' => 1, - 'version' => $this->_apiversion, ); } @@ -91,12 +90,12 @@ class api_v3_PledgeTest 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, " testCreateWithCustom "); $this->assertAPISuccess($result, ' in line ' . __LINE__); - $getparams = array('version' => 3, 'id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1); - $check = civicrm_api($this->_entity, 'get', $getparams); - civicrm_api('pledge', 'delete', array('id' => $check['values'][$check['id']], 'version' => 3)); + $getparams = array('id' => $result['id'], 'return.custom_' . $ids['custom_field_id'] => 1); + $check = $this->callAPISuccess($this->_entity, 'get', $getparams); + $this->callAPISuccess('pledge', 'delete', array('id' => $check['id'])); $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); @@ -107,21 +106,19 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * */ function testgetfieldspledge() { - $result = civicrm_api('pledge', 'getfields', array('version' => 3, 'action' => 'get')); + $result = $this->callAPISuccess('pledge', 'getfields', array('action' => 'get')); $this->assertEquals(1, $result['values']['next_pay_date']['api.return']); } function testGetPledge() { - $this->_pledge = civicrm_api('pledge', 'create', $this->_params); + $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); $params = array( 'pledge_id' => $this->_pledge['id'], - 'version' => $this->_apiversion, ); - $result = civicrm_api('pledge', 'get', $params); + $result = $this->callAPIAndDocument('pledge', 'get', $params, __FUNCTION__, __FILE__); $pledge = $result['values'][$this->_pledge['id']]; - $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertEquals($this->_individualId, $pledge['contact_id'], 'in line' . __LINE__); $this->assertEquals($this->_pledge['id'], $pledge['pledge_id'], 'in line' . __LINE__); $this->assertEquals(date('Y-m-d') . ' 00:00:00', $pledge['pledge_create_date'], 'in line' . __LINE__); @@ -133,25 +130,21 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($pledge['pledge_next_pay_amount'], 20.00, 'in line' . __LINE__); $params2 = array( - 'pledge_id' => $this->_pledge['id'], - 'version' => $this->_apiversion, - ); - $pledge = civicrm_api('pledge', 'delete', $params2); + 'pledge_id' => $this->_pledge['id'], ); + $pledge = $this->callAPISuccess('pledge', 'delete', $params2); } /** * test 'return.pledge_financial_type' => 1 works */ function testGetPledgewithReturn() { - $this->_pledge = civicrm_api('pledge', 'create', $this->_params); + $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); $params = array( - 'pledge_id' => $this->_pledge['id'], - 'version' => $this->_apiversion, - 'return.pledge_financial_type' => 1, + 'pledge_id' => $this->_pledge['id'], 'return.pledge_financial_type' => 1, ); - $result = civicrm_api('pledge', 'get', $params); + $result = $this->callAPISuccess('pledge', 'get', $params); $pledge = $result['values'][$this->_pledge['id']]; - civicrm_api('pledge', 'delete', $pledge); + $this->callAPISuccess('pledge', 'delete', $pledge); $this->assertEquals('Donation', $pledge['pledge_financial_type']); } /** @@ -160,34 +153,31 @@ class api_v3_PledgeTest extends CiviUnitTestCase { */ function testGetPledgewithReturnLegacy() { - $this->_pledge = civicrm_api('pledge', 'create', $this->_params); + $this->_pledge = $this->callAPISuccess('pledge', 'create', $this->_params); $params = array( - 'pledge_id' => $this->_pledge['id'], - 'version' => $this->_apiversion, - 'return.pledge_financial_type' => 1, + 'pledge_id' => $this->_pledge['id'], 'return.pledge_financial_type' => 1, ); - $result = civicrm_api('pledge', 'get', $params); + $result = $this->callAPISuccess('pledge', 'get', $params); $pledge = $result['values'][$this->_pledge['id']]; - civicrm_api('pledge', 'delete', $pledge); + $this->callAPISuccess('pledge', 'delete', $pledge); $this->assertEquals('Donation', $pledge['pledge_financial_type']); } function testPledgeGetReturnFilters() { - $oldPledge = civicrm_api('pledge', 'create', $this->_params); + $oldPledge = $this->callAPISuccess('pledge', 'create', $this->_params); $overdueParams = array( 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', ); - $oldPledge = civicrm_api('pledge', 'create', array_merge($this->_params, $overdueParams)); + $oldPledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); - $pledgeGetParams = array('version' => 3); - $allPledges = civicrm_api('pledge', 'getcount', $pledgeGetParams); + $pledgeGetParams = array(); + $allPledges = $this->callAPISuccess('pledge', 'getcount', $pledgeGetParams); $this->assertEquals(2, $allPledges, 'Check we have 2 pledges to place with in line ' . __LINE__); $pledgeGetParams['pledge_start_date_high'] = date('YmdHis', strtotime('2 days ago')); - $earlyPledge = civicrm_api('pledge', 'get', $pledgeGetParams); - $this->documentMe($pledgeGetParams, $earlyPledge, __FUNCTION__, __FILE__, "demonstrates high date filter", "GetFilterHighDate"); + $earlyPledge = $this->callAPIAndDocument('pledge', 'get', $pledgeGetParams, __FUNCTION__, __FILE__, "demonstrates high date filter", "GetFilterHighDate"); $this->assertEquals(1, $earlyPledge['count'], ' check only one returned with start date filter in line ' . __LINE__); $this->assertEquals($oldPledge['id'], $earlyPledge['id'], ' check correct pledge returned ' . __LINE__); } @@ -199,18 +189,14 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', ); - $this->_pledge = civicrm_api('pledge', 'create', array_merge($this->_params, $overdueParams)); - $params = array( - 'version' => $this->_apiversion, - 'pledge_status_id' => '6', + $this->_pledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); + $params = array( 'pledge_status_id' => '6', ); - $result = civicrm_api('pledge', 'get', $params); - $emptyResult = civicrm_api('pledge', 'get', array( - 'version' => $this->_apiversion, - 'pledge_status_id' => '1', + $result = $this->callAPISuccess('pledge', 'get', $params); + $emptyResult = $this->callAPISuccess('pledge', 'get', array( 'pledge_status_id' => '1', )); $pledge = $result['values'][$this->_pledge['id']]; - civicrm_api('pledge', 'delete', $pledge); + $this->callAPISuccess('pledge', 'delete', $pledge); $this->assertEquals(1, $result['count']); $this->assertEquals(0, $emptyResult['count']); } @@ -220,43 +206,35 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * create 2 pledges - see if we can get by status id */ function testSortParamPledge() { - $pledge1 = civicrm_api('pledge', 'create', $this->_params); + $pledge1 = $this->callAPISuccess('pledge', 'create', $this->_params); $overdueParams = array( 'scheduled_date' => 'first saturday of march last year', 'start_date' => 'first saturday of march last year', 'create_date' => 'first saturday of march last year', ); - $pledge2 = civicrm_api('pledge', 'create', array_merge($this->_params, $overdueParams)); - $params = array( - 'version' => $this->_apiversion, - 'pledge_is_test' => 0, + $pledge2 = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams)); + $params = array( 'pledge_is_test' => 0, 'rowCount' => 1, ); - $result = civicrm_api('pledge', 'get', $params); + $result = $this->callAPISuccess('pledge', 'get', $params); - $resultSortedAsc = civicrm_api('pledge', 'get', array( - 'version' => $this->_apiversion, - 'rowCount' => 1, + $resultSortedAsc = $this->callAPISuccess('pledge', 'get', array( 'rowCount' => 1, 'sort' => 'start_date ASC', )); - $resultSortedDesc = civicrm_api('pledge', 'get', array( - 'version' => $this->_apiversion, - 'rowCount' => 1, + $resultSortedDesc = $this->callAPISuccess('pledge', 'get', array( 'rowCount' => 1, 'sort' => 'start_date DESC', )); $this->assertEquals($pledge1['id'], $result['id'], 'pledge get gets first created pledge in line ' . __LINE__); $this->assertEquals($pledge2['id'], $resultSortedAsc['id'], 'Ascending pledge sort works'); $this->assertEquals($pledge1['id'], $resultSortedDesc['id'], 'Decending pledge sort works'); - civicrm_api('pledge', 'delete', array('version' => 3, 'id' => $pledge1['id'])); - civicrm_api('pledge', 'delete', array('version' => 3, 'id' => $pledge2['id'])); + $this->callAPISuccess('pledge', 'delete', array('id' => $pledge1['id'])); + $this->callAPISuccess('pledge', 'delete', array('id' => $pledge2['id'])); } function testCreatePledge() { - $result = civicrm_api('pledge', 'create', $this->_params); - $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('pledge', 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][0]['amount'], 100.00, 'In line ' . __LINE__); $this->assertEquals($result['values'][0]['installments'], 5, 'In line ' . __LINE__); $this->assertEquals($result['values'][0]['frequency_unit'], 'year', 'In line ' . __LINE__); @@ -267,15 +245,15 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($result['values'][0]['create_date'], date('Ymd') . '000000', 'In line ' . __LINE__); $this->assertEquals($result['values'][0]['start_date'], date('Ymd') . '000000', 'In line ' . __LINE__); $this->assertAPISuccess($result, 'In line ' . __LINE__); - $payments = civicrm_api('PledgePayment', 'Get', array('version' => 3, 'pledge_id' => $result['id'], 'sequential' => 1)); + $payments = $this->callAPISuccess('PledgePayment', 'Get', array('pledge_id' => $result['id'], 'sequential' => 1)); $this->assertAPISuccess($payments, 'In line ' . __LINE__); $this->assertEquals($payments['count'], 5, 'In line ' . __LINE__); require_once 'CRM/Utils/Date.php'; $shouldBeDate = CRM_Utils_Date::format(CRM_Utils_Date::intervalAdd('year', 5 * 4, $this->scheduled_date), "-"); $this->assertEquals(substr($shouldBeDate, 0, 10), substr($payments['values'][4]['scheduled_date'], 0, 10), 'In line ' . __LINE__); - $pledgeID = array('id' => $result['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('id' => $result['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } /* @@ -289,19 +267,15 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'frequency_interval' => 2, ); $params = array_merge($this->_params, $params); - $pledge = civicrm_api('Pledge', 'Create', $params); + $pledge = $this->callAPISuccess('Pledge', 'Create', $params); //ensure that correct number of payments created & last payment has the right date - $payments = civicrm_api('PledgePayment', 'Get', array( - 'version' => 3, + $payments = $this->callAPISuccess('PledgePayment', 'Get', array( 'pledge_id' => $pledge['id'], 'sequential' => 1)); - $this->assertEquals($payments['is_error'], 0, 'In line ' . __LINE__); $this->assertEquals($payments['count'], 5, 'In line ' . __LINE__); - require_once 'CRM/Utils/Date.php'; $this->assertEquals('2011-07-06 00:00:00', $payments['values'][4]['scheduled_date'], 'In line ' . __LINE__); - $pledgeID = array('pledge_id' => $pledge['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $this->callAPISuccess('pledge', 'delete', array('pledge_id' => $pledge['id'])); } /* * Test that pledge with weekly schedule calculates dates correctly @@ -314,8 +288,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'frequency_interval' => 2, ); $params = array_merge($this->_params, $params); - $apiResult = civicrm_api('pledge', 'create', $params); - $this->assertAPISuccess($apiResult); + $apiResult = $this->callAPISuccess('pledge', 'create', $params); } @@ -337,18 +310,16 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $params = array_merge($this->_params, $params); unset($params['pledge_status_id']); - $pledge = civicrm_api('Pledge', 'Create', $params); + $pledge = $this->callAPISuccess('Pledge', 'Create', $params); //ensure that correct number of payments created & last payment has the right date - $payments = civicrm_api('PledgePayment', 'Get', array( - 'version' => 3, + $payments = $this->callAPISuccess('PledgePayment', 'Get', array( 'pledge_id' => $pledge['id'], 'sequential' => 1 )); - $this->assertEquals($payments['is_error'], 0, 'In line ' . __LINE__); $this->assertEquals(1, $payments['count'], 'In line ' . __LINE__); $this->assertEquals(2, $payments['values'][0]['status_id'], 'In line ' . __LINE__); - $pledgeID = array('id' => $pledge['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('id' => $pledge['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } /* @@ -360,30 +331,28 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $params['original_installment_amount'] = $params['pledge_original_installment_amount']; unset($params['pledge_original_installment_amount']); - $result = civicrm_api('pledge', 'create', $params); - $pledgeDetails = civicrm_api('Pledge', 'Get', array('version' => 3, 'id' => $result['id'], 'sequential' => 1)); - $pledge = $pledgeDetails['values'][0]; - $this->assertEquals(0, $result['is_error'], "in line " . __LINE__); + $result = $this->callAPISuccess('pledge', 'create', $params); + $pledgeDetails = $this->callAPISuccess('Pledge', 'Get', array('id' => $result['id'], 'sequential' => 1)); + $pledge = $pledgeDetails['values'][0]; $this->assertEquals(100.00, $pledge['pledge_amount'], 'In line ' . __LINE__); $this->assertEquals('year', $pledge['pledge_frequency_unit'], 'In line ' . __LINE__); $this->assertEquals(5, $pledge['pledge_frequency_interval'], 'In line ' . __LINE__); $this->assertEquals(20, $pledge['pledge_next_pay_amount'], 'In line ' . __LINE__); - $pledgeID = array('id' => $result['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('id' => $result['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } function testCreateCancelPledge() { - $result = civicrm_api('pledge', 'create', $this->_params); - $this->assertEquals(0, $result['is_error'], "in line " . __LINE__); + $result = $this->callAPISuccess('pledge', 'create', $this->_params); $this->assertEquals(2, $result['values'][0]['status_id'], "in line " . __LINE__); - $cancelparams = array('sequential' => 1, 'version' => $this->_apiversion, 'id' => $result['id'], 'pledge_status_id' => 3); - $result = civicrm_api('pledge', 'create', $cancelparams); + $cancelparams = array('sequential' => 1, 'id' => $result['id'], 'pledge_status_id' => 3); + $result = $this->callAPISuccess('pledge', 'create', $cancelparams); $this->assertEquals(3, $result['values'][0]['status_id'], "in line " . __LINE__); - $pledgeID = array('id' => $result['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('id' => $result['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } /* @@ -394,11 +363,11 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $params = $this->_params; unset($params['status_id']); unset($params['pledge_status_id']); - $result = civicrm_api('pledge', 'create', $params); + $result = $this->callAPISuccess('pledge', 'create', $params); $this->assertAPISuccess($result, "in line " . __LINE__); $this->assertEquals(2, $result['values'][0]['status_id'], "in line " . __LINE__); - $pledgeID = array('pledge_id' => $result['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('pledge_id' => $result['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } //To Update Pledge @@ -408,10 +377,8 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $pledgeID = $this->pledgeCreate($this->_individualId); $old_params = array( 'id' => $pledgeID, - 'sequential' => 1, - 'version' => $this->_apiversion, - ); - $original = civicrm_api('pledge', 'get', $old_params); + 'sequential' => 1, ); + $original = $this->callAPISuccess('pledge', 'get', $old_params); //Make sure it came back $this->assertEquals($original['values'][0]['pledge_id'], $pledgeID, 'In line ' . __LINE__); //set up list of old params, verify @@ -433,21 +400,16 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'amount' => 100, 'financial_type_id' => 1, 'start_date' => date('Ymd'), - 'installments' => 10, - 'version' => $this->_apiversion, - ); + 'installments' => 10, ); - $pledge = civicrm_api('pledge', 'create', $params); - $this->assertEquals($pledge['is_error'], 0); + $pledge = $this->callAPISuccess('pledge', 'create', $params); $new_params = array( 'id' => $pledge['id'], - 'version' => $this->_apiversion, ); - $pledge = civicrm_api('pledge', 'get', $new_params); + $pledge = $this->callAPISuccess('pledge', 'get', $new_params); $this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId, 'In line ' . __LINE__); $this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled', 'In line ' . __LINE__); - $pledge = civicrm_api('pledge', 'delete', $new_params); - $this->assertEquals($pledge['is_error'], 0, 'In line ' . __LINE__); + $pledge = $this->callAPISuccess('pledge', 'delete', $new_params); } /** * Here we ensure we are maintaining our 'contract' & supporting previously working syntax @@ -460,10 +422,8 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $pledgeID = $this->pledgeCreate($this->_individualId); $old_params = array( 'id' => $pledgeID, - 'sequential' => 1, - 'version' => $this->_apiversion, - ); - $original = civicrm_api('pledge', 'get', $old_params); + 'sequential' => 1, ); + $original = $this->callAPISuccess('pledge', 'get', $old_params); //Make sure it came back $this->assertEquals($original['values'][0]['pledge_id'], $pledgeID, 'In line ' . __LINE__); //set up list of old params, verify @@ -486,43 +446,29 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'contribution_type_id' => 1, 'start_date' => date('Ymd'), 'installments' => 10, - 'version' => $this->_apiversion, ); - $pledge = civicrm_api('pledge', 'create', $params); - $this->assertEquals($pledge['is_error'], 0); + $pledge = $this->callAPISuccess('pledge', 'create', $params); $new_params = array( 'id' => $pledge['id'], - 'version' => $this->_apiversion, ); - $pledge = civicrm_api('pledge', 'get', $new_params); + $pledge = $this->callAPISuccess('pledge', 'get', $new_params); $this->assertEquals($pledge['values'][$pledgeID]['contact_id'], $this->_individualId, 'In line ' . __LINE__); $this->assertEquals($pledge['values'][$pledgeID]['pledge_status'], 'Cancelled', 'In line ' . __LINE__); - $pledge = civicrm_api('pledge', 'delete', $new_params); - $this->assertEquals($pledge['is_error'], 0, 'In line ' . __LINE__); + $pledge = $this->callAPISuccess('pledge', 'delete', $new_params); } ///////////////// civicrm_pledge_delete methods function testDeleteEmptyParamsPledge() { - - $params = array('version' => $this->_apiversion); - $pledge = $this->callAPIFailure('pledge', 'delete', $params); - $this->assertEquals($pledge['error_message'], 'Mandatory key(s) missing from params array: id'); + $pledge = $this->callAPIFailure('pledge', 'delete', array(), 'Mandatory key(s) missing from params array: id'); } - function testDeleteParamsNotArrayPledge() { - $params = 'pledge_id= 1'; - $pledge = $this->callAPIFailure('pledge', 'delete', $params); - $this->assertEquals($pledge['error_message'], 'Input variable `params` is not an array'); - } function testDeleteWrongParamPledge() { $params = array( 'pledge_source' => 'SSF', - 'version' => $this->_apiversion, ); - $pledge = $this->callAPIFailure('pledge', 'delete', $params); - $this->assertEquals($pledge['error_message'], 'Mandatory key(s) missing from params array: id'); + $pledge = $this->callAPIFailure('pledge', 'delete', $params, 'Mandatory key(s) missing from params array: id'); } /* @@ -533,11 +479,8 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $pledgeID = $this->pledgeCreate($this->_individualId); $params = array( 'pledge_id' => $pledgeID, - 'version' => $this->_apiversion, ); - $result = civicrm_api('pledge', 'delete', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result); + $result = $this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__); } /* @@ -548,11 +491,8 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $pledgeID = $this->pledgeCreate($this->_individualId); $params = array( 'id' => $pledgeID, - 'version' => $this->_apiversion, ); - $result = civicrm_api('pledge', 'delete', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result); + $result = $this->callAPIAndDocument('pledge', 'delete', $params, __FUNCTION__, __FILE__); } /* * test to make sure empty get returns nothing @@ -560,12 +500,12 @@ class api_v3_PledgeTest extends CiviUnitTestCase { * contact search instead - test only checks that the get finds the one existing */ function testGetEmpty() { - $result = civicrm_api('pledge', 'create', $this->_params); - $result = civicrm_api('pledge', 'get', array('version' => 3)); + $result = $this->callAPISuccess('pledge', 'create', $this->_params); + $result = $this->callAPISuccess('pledge', 'get', array()); $this->assertAPISuccess($result, "This test is failing because it's acting like a contact get when no params set. Not sure the fix"); $this->assertEquals(1, $result['count'], 'in line ' . __LINE__); - $pledgeID = array('id' => $result['id'], 'version' => 3); - $pledge = civicrm_api('pledge', 'delete', $pledgeID); + $pledgeID = array('id' => $result['id']); + $pledge = $this->callAPISuccess('pledge', 'delete', $pledgeID); } } diff --git a/tests/phpunit/api/v3/PriceFieldTest.php b/tests/phpunit/api/v3/PriceFieldTest.php index c791604350..0ed4ff1a13 100644 --- a/tests/phpunit/api/v3/PriceFieldTest.php +++ b/tests/phpunit/api/v3/PriceFieldTest.php @@ -1,5 +1,4 @@ 3, - # [domain_id] => + # [domain_id] => 'name' => 'default_goat_priceset', 'title' => 'Goat accomodation', 'is_active' => 1, @@ -53,12 +51,10 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { 'is_reserved' => 1, ); - $price_set = civicrm_api('price_set', 'create',$priceSetparams); + $price_set = $this->callAPISuccess('price_set', 'create',$priceSetparams); $this->priceSetID = $price_set['id']; - $this->_params = array( - 'version' => $this->_apiversion, - 'price_set_id' => $this->priceSetID, + $this->_params = array( 'price_set_id' => $this->priceSetID, 'name' => 'grassvariety', 'label' => 'Grass Variety', 'html_type' => 'Text', @@ -74,57 +70,44 @@ class api_v3_PriceFieldTest extends CiviUnitTestCase { ); $this->quickCleanup($tablesToTruncate); - $delete = civicrm_api('PriceSet','delete', array( - 'version' => 3, - 'id' => $this->priceSetID, + $delete = $this->callAPISuccess('PriceSet','delete', array( + 'id' => $this->priceSetID, )); $this->assertAPISuccess($delete); } public function testCreatePriceField() { - $result = civicrm_api($this->_entity, 'create', $this->_params); - $this->id = $result['id']; - $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, 'In line ' . __LINE__); + $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); $this->getAndCheck($this->_params, $result['id'], $this->_entity); } public function testGetBasicPriceField() { - $createResult = civicrm_api($this->_entity, 'create', $this->_params); + $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); $this->id = $createResult['id']; $this->assertAPISuccess($createResult); $getParams = array( - 'version' => $this->_apiversion, 'name' => 'contribution_amount', ); - $getResult = civicrm_api($this->_entity, 'get', $getParams); - $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__); - $this->assertAPISuccess($getResult, 'In line ' . __LINE__); + $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__); - civicrm_api('price_field','delete', array('version' => 3, 'id' => $createResult['id'])); + $this->callAPISuccess('price_field','delete', array('id' => $createResult['id'])); } public function testDeletePriceField() { - $startCount = civicrm_api($this->_entity, 'getcount', array( - 'version' => $this->_apiversion, - )); - $createResult = civicrm_api($this->_entity, 'create', $this->_params); - $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']); - $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams); - $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__); + $startCount = $this->callAPISuccess($this->_entity, 'getcount', array( )); + $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); + $deleteParams = array('id' => $createResult['id']); + $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__); - $endCount = civicrm_api($this->_entity, 'getcount', array( - 'version' => $this->_apiversion, - )); + $endCount = $this->callAPISuccess($this->_entity, 'getcount', array( )); $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__); } public function testGetFieldsPriceField() { - $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create')); - $this->assertAPISuccess($result, 'In line ' . __LINE__); + $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); $this->assertEquals(1, $result['values']['options_per_line']['type']); } diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 5696d6e2d4..f2d4785aed 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -55,19 +55,18 @@ class api_v3_ProfileTest extends CiviUnitTestCase { } function tearDown() { + $this->quickCleanup(array( 'civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', - 'civicrm_custom_field', - 'civicrm_custom_group', 'civicrm_contact', 'civicrm_phone', 'civicrm_address', - )); + ), TRUE); } - ////////////// test civicrm_api3_profile_get ////////////////// + ////////////// test $this->callAPISuccess3_profile_get ////////////////// /** * check Without ProfileId @@ -75,10 +74,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { function testProfileGetWithoutProfileId() { $params = array( 'contact_id' => 1, - 'version' => 3, ); - $result = $this->callAPIFailure('profile', 'get', $params); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); + $result = $this->callAPIFailure('profile', 'get', $params, + 'Mandatory key(s) missing from params array: profile_id' + ); } /** @@ -88,7 +87,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array( 'contact_id' => 1, 'profile_id' => 1000, - 'version' => 3, ); $result = $this->callAPIFailure('profile', 'get', $params); } @@ -103,45 +101,36 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array( 'profile_id' => 25, 'contact_id' => $contactId, - 'version' => 3, ); - $result = civicrm_api('profile', 'get', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - - $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result) - ); + $result = $this->callAPIAndDocument('profile', 'get', $params, __FUNCTION__, __FILE__); foreach ($expected as $profileField => $value) { $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}" ); } - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_contact')); } - /* - * check contact activity profile without activity id - */ + /** + * check contact activity profile without activity id + */ function testContactActivityGetWithoutActivityId() { list($params, $expected) = $this->_createContactWithActivity(); unset($params['activity_id']); - $result = $this->callAPIFailure('profile', 'get', $params); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id'); + $result = $this->callAPIFailure('profile', 'get', $params, + 'Mandatory key(s) missing from params array: activity_id'); } - /* - * check contact activity profile wrong activity id - */ + /** + * check contact activity profile wrong activity id + */ function testContactActivityGetWrongActivityId() { list($params, $expected) = $this->_createContactWithActivity(); $params['activity_id'] = 100001; - $result = $this->callAPIFailure('profile', 'get', $params); - $this->assertEquals($result['error_message'], 'Invalid Activity Id (aid).'); - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact')); + $result = $this->callAPIFailure('profile', 'get', $params, + 'Invalid Activity Id (aid).'); } /* @@ -162,23 +151,19 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'location' => 'Pensulvania', 'details' => 'a test activity', 'status_id' => '1', - 'version' => '3', 'priority_id' => '1', ); - $activity = civicrm_api('activity', 'create', $activityparams); - $this->assertEquals(0, $activity['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $activity) - ); + $activity = $this->callAPISuccess('activity', 'create', $activityparams); $activityValues = array_pop($activity['values']); list($params, $expected) = $this->_createContactWithActivity(); $params['activity_id'] = $activityValues['id']; - $result = $this->callAPIFailure('profile', 'get', $params); - $this->assertEquals($result['error_message'], 'This activity cannot be edited or viewed via this profile.'); - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact')); + $result = $this->callAPIFailure('profile', 'get', $params, + 'This activity cannot be edited or viewed via this profile.' + ); } /* @@ -187,20 +172,15 @@ class api_v3_ProfileTest extends CiviUnitTestCase { function testContactActivityGetSuccess() { list($params, $expected) = $this->_createContactWithActivity(); - $result = civicrm_api('profile', 'get', $params); - - $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result) - ); + $result = $this->callAPISuccess('profile', 'get', $params); foreach ($expected as $profileField => $value) { $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}" ); } - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact')); } - /////////////// test civicrm_api3_profile_set ////////////////// + /////////////// test $this->callAPISuccess3_profile_set ////////////////// /** * check with no array @@ -217,10 +197,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { function testProfileSetWithoutProfileId() { $params = array( 'contact_id' => 1, - 'version' => 3, ); - $result = $this->callAPIFailure('profile', 'set', $params); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); + $result = $this->callAPIFailure('profile', 'set', $params, + 'Mandatory key(s) missing from params array: profile_id' + ); } /** @@ -230,7 +210,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array( 'contact_id' => 1, 'profile_id' => 1000, - 'version' => 3, ); $result = $this->callAPIFailure('profile', 'set', $params); } @@ -250,14 +229,13 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'state_province-1' => '1000', ); - $params = array_merge(array('profile_id' => 25, 'contact_id' => $contactId, 'version' => 3), + $params = array_merge(array('profile_id' => 25, 'contact_id' => $contactId), $updateParams ); - $result = $this->callAPIFailure('profile', 'set', $params); - $this->assertEquals($result['error_message'], 'Missing required parameters for profile id 25: email-Primary'); - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_contact')); + $result = $this->callAPIFailure('profile', 'set', $params, + 'Missing required parameters for profile id 25: email-Primary' + ); } /** @@ -280,23 +258,15 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array_merge(array( 'profile_id' => 25, 'contact_id' => $contactId, - 'version' => 3, ), $updateParams); - $result = civicrm_api('profile', 'set', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - - $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result) - ); + $result = $this->callAPIAndDocument('profile', 'set', $params, __FUNCTION__, __FILE__); $getParams = array( 'profile_id' => 25, 'contact_id' => $contactId, - 'version' => 3, - ); - $profileDetails = civicrm_api('profile', 'get', $getParams); - $this->assertEquals(0, $profileDetails['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $profileDetails) ); + $profileDetails = $this->callAPISuccess('profile', 'get', $getParams); foreach ($updateParams as $profileField => $value) { $this->assertEquals($value, CRM_Utils_Array::value($profileField, $profileDetails['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}" @@ -350,13 +320,10 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'location' => 'Pensulvania', 'details' => 'a test activity', 'status_id' => '1', - 'version' => '3', 'priority_id' => '1', ); - $activity = civicrm_api('activity', 'create', $activityparams); - $this->assertEquals(0, $activity['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $activity) - ); + $activity = $this->callAPISuccess('activity', 'create', $activityparams); $activityValues = array_pop($activity['values']); @@ -364,10 +331,8 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array_merge($params, $expected); $params['activity_id'] = $activityValues['id']; - $result = $this->callAPIFailure('profile', 'set', $params); - $this->assertEquals($result['error_message'], 'This activity cannot be edited or viewed via this profile.'); - - $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact')); + $result = $this->callAPIFailure('profile', 'set', $params, + 'This activity cannot be edited or viewed via this profile.'); } /* @@ -387,50 +352,33 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'activity_status_id' => '2', ); $profileParams = array_merge($params, $updateParams); - $profile = civicrm_api('profile', 'set', $profileParams); - $result = civicrm_api('profile', 'get', $params); - $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result) - ); + $profile = $this->callAPISuccess('profile', 'set', $profileParams); + $result = $this->callAPISuccess('profile', 'get', $params); foreach ($updateParams as $profileField => $value) { $this->assertEquals($value, CRM_Utils_Array::value($profileField, $result['values']), "In line " . __LINE__ . " error message: " . "missing/mismatching value for {$profileField}" ); } - - $this->quickCleanup(array( - 'civicrm_uf_field', - 'civicrm_uf_join', - 'civicrm_uf_group', - 'civicrm_custom_field', - 'civicrm_custom_group', - 'civicrm_contact', - ), - TRUE - ); } - /////////////// test civicrm_api3_profile_apply ////////////////// - /** - * check Without ProfileId + * check profile apply Without ProfileId */ function testProfileApplyWithoutProfileId() { $params = array( 'contact_id' => 1, - 'version' => 3, ); - $result = $this->callAPIFailure('profile', 'apply', $params); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); + $result = $this->callAPIFailure('profile', 'apply', $params, + 'Mandatory key(s) missing from params array: profile_id'); } /** - * check with no invalid profile Id + * check profile apply with no invalid profile Id */ function testProfileApplyInvalidProfileId() { $params = array( 'contact_id' => 1, 'profile_id' => 1000, - 'version' => 3, ); $result = $this->callAPIFailure('profile', 'apply', $params); } @@ -446,7 +394,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array( 'profile_id' => 25, 'contact_id' => $contactId, - 'version' => 3, 'first_name' => 'abc2', 'last_name' => 'xyz2', 'email-Primary' => 'abc2.xyz2@gmail.com', @@ -455,11 +402,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'state_province-1' => '1000', ); - $result = civicrm_api('profile', 'apply', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - - $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result) - ); + $result = $this->callAPIAndDocument('profile', 'apply', $params, __FUNCTION__, __FILE__); // Expected field values $expected['contact'] = array( @@ -511,7 +454,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'last_name' => 'xyz1', 'contact_type' => 'Individual', 'email' => 'abc1.xyz1@yahoo.com', - 'version' => '3', 'api.address.create' => array( 'location_type_id' => 1, 'is_primary' => 1, @@ -530,10 +472,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ), ); - $contact = civicrm_api('contact', 'create', $contactParams); - - $this->assertEquals(0, $contact['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact) - ); + $contact = $this->callAPISuccess('contact', 'create', $contactParams); $keys = array_keys($contact['values']); $contactId = array_pop($keys); @@ -589,7 +528,6 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'last_name' => 'xyz1', 'contact_type' => 'Individual', 'email' => 'abc1.xyz1@yahoo.com', - 'version' => '3', 'api.address.create' => array( 'location_type_id' => 1, 'is_primary' => 1, @@ -602,10 +540,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { ), ); - $contact = civicrm_api('contact', 'create', $contactParams); - - $this->assertEquals(0, $contact['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact) - ); + $contact = $this->callAPISuccess('contact', 'create', $contactParams); $keys = array_keys($contact['values']); $contactId = array_pop($keys); @@ -623,12 +558,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'location' => 'Pensulvania', 'details' => 'a test activity', 'status_id' => '1', - 'version' => '3', 'priority_id' => '1', ); - $activity = civicrm_api('activity', 'create', $activityParams); - $this->assertEquals(0, $activity['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $activity) - ); + $activity = $this->callAPISuccess('activity', 'create', $activityParams); $activityValues = array_pop($activity['values']); @@ -637,8 +569,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'profile_id' => 26, 'contact_id' => $contactId, 'activity_id' => $activityValues['id'], - 'version' => 3, - ); + ); // expected result of above created profile $expected = array( diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index b1b857e713..a6535a84f9 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -1,5 +1,5 @@ 'Individual', 'contact_type_b' => 'Organization', - 'version' => $this->_apiversion, ); - $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); - $this->assertEquals($result['error_message'], + $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams, 'Mandatory key(s) missing from params array: name_a_b, name_b_a' ); } @@ -112,10 +110,8 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { $relTypeParams = array( 'name_a_b' => 'Relation 1 without contact type', 'name_b_a' => 'Relation 2 without contact type', - 'version' => $this->_apiversion, ); - $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); - $this->assertEquals($result['error_message'], + $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams, 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b' ); } @@ -131,13 +127,10 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - 'version' => $this->_apiversion, 'sequential' => 1, ); - $result = civicrm_api('relationship_type', 'create', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('relationship_type', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); - unset($params['version']); unset($params['sequential']); //assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params); @@ -248,12 +241,11 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Individual', 'is_reserved' => 0, 'is_active' => 0, - 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship_type', 'create', $params); + $result = $this->callAPISuccess('relationship_type', 'create', $params); $this->assertNotNull($result['id']); - unset($params['version']); + // assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Contact_DAO_RelationshipType', $result['id'], $params); } @@ -272,10 +264,9 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $first = civicrm_api('RelationshipType', 'Create', $firstRelTypeParams); + $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams); $secondRelTypeParams = array( 'name_a_b' => 'Relation 25 for create', @@ -285,15 +276,11 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 0, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $second = civicrm_api('RelationshipType', 'Create', $secondRelTypeParams); - $results = civicrm_api('relationship_type', 'get', array( - 'version' => $this->_apiversion, - )); + $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams); + $results = $this->callAPISuccess('relationship_type', 'get', array()); $this->assertEquals(2, $results['count']); - $this->assertEquals(0, $results['is_error']); } /** @@ -316,10 +303,9 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $first = civicrm_api('RelationshipType', 'Create', $firstRelTypeParams); + $first = $this->callAPISuccess('RelationshipType', 'Create', $firstRelTypeParams); $secondRelTypeParams = array( 'name_a_b' => 'Relation 32 for create', @@ -329,19 +315,16 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 0, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $second = civicrm_api('RelationshipType', 'Create', $secondRelTypeParams); + $second = $this->callAPISuccess('RelationshipType', 'Create', $secondRelTypeParams); $params = array( 'name_a_b' => 'Relation 32 for create', 'name_b_a' => 'Relation 33 for create', 'description' => 'Testing relationship type second', - 'version' => $this->_apiversion, ); - $results = civicrm_api('relationship_type', 'get', $params); + $results = $this->callAPISuccess('relationship_type', 'get', $params); - $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__); $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); $this->assertEquals(1, $results['values'][$results['id']]['is_active'], ' in line ' . __LINE__); } @@ -359,7 +342,6 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'is_reserved' => 1, 'is_active' => 1, - 'version' => API_LATEST_VERSION, ); } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index e689782005..a9e954302d 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -46,8 +46,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { function tearDown() {} public function testReportTemplate() { - $result = civicrm_api('ReportTemplate', 'create', array( - 'version' => $this->_apiversion, + $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'label' => 'Example Form', 'description' => 'Longish description of the example form', 'class_name' => 'CRM_Report_Form_Examplez', @@ -66,9 +65,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { WHERE name = "CRM_Report_Form_Examplez"'); // change component to null - $result = civicrm_api('ReportTemplate', 'create', array( - 'version' => $this->_apiversion, - 'id' => $entityId, + $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, 'component' => '', )); $this->assertAPISuccess($result); @@ -81,9 +78,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { AND component_id IS NULL'); // deactivate - $result = civicrm_api('ReportTemplate', 'create', array( - 'version' => $this->_apiversion, - 'id' => $entityId, + $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, 'is_active' => 0, )); $this->assertAPISuccess($result); @@ -95,9 +90,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { WHERE name = "CRM_Report_Form_Examplez"'); // activate - $result = civicrm_api('ReportTemplate', 'create', array( - 'version' => $this->_apiversion, - 'id' => $entityId, + $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, 'is_active' => 1, )); $this->assertAPISuccess($result); @@ -108,9 +101,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez"'); - $result = civicrm_api('ReportTemplate', 'delete', array( - 'version' => $this->_apiversion, - 'id' => $entityId, + $result = $this->callAPISuccess('ReportTemplate', 'delete', array( 'id' => $entityId, )); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); diff --git a/tests/phpunit/api/v3/SettingTest.php b/tests/phpunit/api/v3/SettingTest.php index affbec27e5..5c48880ff9 100644 --- a/tests/phpunit/api/v3/SettingTest.php +++ b/tests/phpunit/api/v3/SettingTest.php @@ -65,26 +65,22 @@ class api_v3_SettingTest extends CiviUnitTestCase { parent::setUp(); $params = array( 'name' => 'Default Domain Name', - 'version' => 3, - ); - $result = civicrm_api( 'domain','get',$params); + ); + $result = $this->callAPISuccess( 'domain','get',$params); if(empty($result['id'])){ - $result = civicrm_api( 'domain','create',$params ); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess( 'domain','create',$params ); } $params['name'] = 'Second Domain'; - $result = civicrm_api( 'domain','get',$params); + $result = $this->callAPISuccess( 'domain','get',$params); if(empty($result['id'])){ - $result = civicrm_api( 'domain','create',$params ); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess( 'domain','create',$params ); } $this->_domainID2 = $result['id']; $params['name'] = 'A-team domain'; - $result = civicrm_api( 'domain','get',$params); + $result = $this->callAPISuccess( 'domain','get',$params); if(empty($result['id'])){ - $result = civicrm_api( 'domain','create',$params ); - $this->assertAPISuccess($result); + $result = $this->callAPISuccess( 'domain','create',$params ); } $this->_domainID3 = $result['id']; $this->_currentDomain = CRM_Core_Config::domainID(); @@ -92,27 +88,22 @@ class api_v3_SettingTest extends CiviUnitTestCase { function tearDown() { parent::tearDown(); + $this->callAPISuccess('system','flush', array()); $this->quickCleanup(array('civicrm_domain')); - civicrm_api('system','flush', array('version' => $this->_apiversion)); } /** * check getfields works */ function testGetFields() { - $params = array('version' => $this->_apiversion); - $result = civicrm_api('setting', 'getfields', $params); $description = 'Demonstrate return from getfields - see subfolder for variants'; - $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description,'', 'getfields'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'getfields', array(), __FUNCTION__, __FILE__, $description); $this->assertArrayHasKey('customCSSURL', $result['values']); $description = 'Demonstrate return from getfields'; - $result = civicrm_api('setting', 'getfields', array('version' => $this->_apiversion)); - // $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, 'GetFieldsGroup'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPISuccess('setting', 'getfields', array()); $this->assertArrayHasKey('customCSSURL', $result['values']); - civicrm_api('system','flush', array('version' => $this->_apiversion)); + $this->callAPISuccess('system','flush', array()); } /** @@ -122,18 +113,14 @@ class api_v3_SettingTest extends CiviUnitTestCase { $settingsMetadata = array(); CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Specs', 'settingsMetadata__'); CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Spec', 'All'); - $result = civicrm_api('setting', 'getfields', array('version' => $this->_apiversion)); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPISuccess('setting', 'getfields', array()); $this->assertArrayNotHasKey('customCSSURL', $result['values']); $this->quickCleanup(array('civicrm_cache')); } function testGetFieldsFilters() { - $params = array('version' => $this->_apiversion); - $filters = array('name' => 'advanced_search_options'); - $result = civicrm_api('setting', 'getfields', $params + $filters); - $this->assertAPISuccess($result, ' in LINE ' . __LINE__); - + $params = array('name' => 'advanced_search_options'); + $result = $this->callAPISuccess('setting', 'getfields', $params); $this->assertArrayNotHasKey('customCSSURL', $result['values']); $this->assertArrayHasKey('advanced_search_options',$result['values']); } @@ -141,23 +128,17 @@ class api_v3_SettingTest extends CiviUnitTestCase { * check getfields works */ function testCreateSetting() { + $description = "shows setting a variable for a given domain - if no domain is set current is assumed"; - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'uniq_email_per_site' => 1, ); - $result = civicrm_api('setting', 'create', $params); - $description = "shows setting a variable for a given domain - if no domain is set current is assumed"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__); - $params = array('version' => $this->_apiversion, - 'uniq_email_per_site' => 1, - ); - $result = civicrm_api('setting', 'create', $params); + $params = array('uniq_email_per_site' => 1,); $description = "shows setting a variable for a current domain"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain'); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); } @@ -166,7 +147,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ function testCreateInvalidSettings() { - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'invalid_key' => 1, ); @@ -179,18 +160,16 @@ class api_v3_SettingTest extends CiviUnitTestCase { function testCreateInvalidURLSettings() { - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'dfhkdhfd', ); $result = $this->callAPIFailure('setting', 'create', $params); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'http://blah.com', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertAPISuccess($result); - + $result = $this->callAPISuccess('setting', 'create', $params); } /** @@ -198,39 +177,32 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ function testCreateInvalidBooleanSettings() { - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'track_civimail_replies' => 'dfhkdhfd', ); $result = $this->callAPIFailure('setting', 'create', $params); - $params = array('version' => $this->_apiversion, - 'track_civimail_replies' => '0', - ); - $result = civicrm_api('setting', 'create', $params); - $getResult = civicrm_api('setting','get',$params); + $params = array('track_civimail_replies' => '0',); + $result = $this->callAPISuccess('setting', 'create', $params); + $getResult = $this->callAPISuccess('setting','get',$params); $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); - $this->assertAPISuccess($result); - $getResult = civicrm_api('setting','get',$params); + $getResult = $this->callAPISuccess('setting','get',$params); $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); - $params = array( - 'version' => $this->_apiversion, - 'domain_id' => $this->_domainID2, + $params = array( 'domain_id' => $this->_domainID2, 'track_civimail_replies' => '1', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertAPISuccess($result); - $getResult = civicrm_api('setting','get',$params); + $result = $this->callAPISuccess('setting', 'create', $params); + $getResult = $this->callAPISuccess('setting','get',$params); $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies']); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'track_civimail_replies' => 'TRUE', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertAPISuccess($result); - $getResult = civicrm_api('setting','get',$params); + $result = $this->callAPISuccess('setting', 'create', $params); + $getResult = $this->callAPISuccess('setting','get',$params); $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies'], "check TRUE is converted to 1"); @@ -241,51 +213,46 @@ class api_v3_SettingTest extends CiviUnitTestCase { * check getfields works */ function testCreateSettingMultipleDomains() { + $description = "shows setting a variable for all domains"; - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => 'all', 'uniq_email_per_site' => 1, ); - $result = civicrm_api('setting', 'create', $params); - $description = "shows setting a variable for all domains"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__,$description, 'CreateAllDomains'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateAllDomains'); + $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); $this->assertArrayHasKey(3, $result['values'], 'Domain create probably failed Debug this IF domain test is passing'); $this->assertEquals(1, $result['values'][3]['uniq_email_per_site'], 'failed to set setting for domain 3.'); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => 'all', 'return' => 'uniq_email_per_site' ); // we'll check it with a 'get' - $result = civicrm_api('setting', 'get', $params); $description = "shows getting a variable for all domains"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__,$description, 'GetAllDomains', 'Get'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetAllDomains', 'Get'); + $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); $this->assertEquals(1, $result['values'][3]['uniq_email_per_site']); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => array(1,3), 'uniq_email_per_site' => 0, ); - $result = civicrm_api('setting', 'create', $params); $description = "shows setting a variable for specified domains"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__,$description, 'CreateSpecifiedDomains'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateSpecifiedDomains'); + $this->assertEquals(0, $result['values'][3]['uniq_email_per_site']); $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => array(1,2), 'return' => array('uniq_email_per_site'), ); - $result = civicrm_api('setting', 'get', $params); $description = "shows getting a variable for specified domains"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__,$description, 'GetSpecifiedDomains', 'Get'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetSpecifiedDomains', 'Get'); $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); @@ -293,23 +260,19 @@ class api_v3_SettingTest extends CiviUnitTestCase { function testGetSetting() { - $params = array('version' => $this->_apiversion, - 'domain_id' => $this->_domainID2, - 'return' => 'uniq_email_per_site', + $params = array( + 'domain_id' => $this->_domainID2, + 'return' => 'uniq_email_per_site', ); - $result = civicrm_api('setting', 'get', $params); $description = "shows get setting a variable for a given domain - if no domain is set current is assumed"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + + $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__); $params = array( - 'version' => $this->_apiversion, 'return' => 'uniq_email_per_site', ); - $result = civicrm_api('setting', 'get', $params); $description = "shows getting a variable for a current domain"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain'); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); } /** @@ -318,12 +281,11 @@ class api_v3_SettingTest extends CiviUnitTestCase { function testSetConfigSetting() { $config = CRM_Core_Config::singleton(); $this->assertFalse($config->debug == 1); - $params = array('version' => $this->_apiversion, + $params = array( 'domain_id' => $this->_domainID2, 'debug_enabled' => 1, ); - $result = civicrm_api('setting', 'create', $params); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPISuccess('setting', 'create', $params); CRM_Core_BAO_Domain::setDomain($this->_domainID2); $config = CRM_Core_Config::singleton(TRUE, TRUE); CRM_Core_BAO_Domain::resetDomain(); @@ -338,12 +300,9 @@ class api_v3_SettingTest extends CiviUnitTestCase { * setting api should set & fetch settings stored in config as well as those in settings table */ function testGetConfigSetting() { - $settings = civicrm_api('setting', 'get', array( - 'name' => 'defaultCurrency', - 'version' => $this->_apiversion, - 'sequential' => 1,) + $settings = $this->callAPISuccess('setting', 'get', array( + 'name' => 'defaultCurrency', 'sequential' => 1,) ); - $this->assertAPISuccess($settings); $this->assertEquals('USD', $settings['values'][0]['defaultCurrency']); } @@ -351,21 +310,14 @@ class api_v3_SettingTest extends CiviUnitTestCase { * setting api should set & fetch settings stored in config as well as those in settings table */ function testGetSetConfigSettingMultipleDomains() { - $settings = civicrm_api('setting', 'create', array( - 'defaultCurrency' => 'USD', - 'version' => $this->_apiversion, - 'domain_id' => $this->_currentDomain) + $settings = $this->callAPISuccess('setting', 'create', array( + 'defaultCurrency' => 'USD', 'domain_id' => $this->_currentDomain) ); - $settings = civicrm_api('setting', 'create', array( - 'defaultCurrency' => 'CAD', - 'version' => $this->_apiversion, - 'domain_id' => $this->_domainID2) + $settings = $this->callAPISuccess('setting', 'create', array( + 'defaultCurrency' => 'CAD', 'domain_id' => $this->_domainID2) ); - $this->assertAPISuccess($settings); - $settings = civicrm_api('setting', 'get', array( - 'return' => 'defaultCurrency', - 'version' => $this->_apiversion, - 'domain_id' => 'all', + $settings = $this->callAPISuccess('setting', 'get', array( + 'return' => 'defaultCurrency', 'domain_id' => 'all', ) ); $this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']); @@ -378,41 +330,33 @@ class api_v3_SettingTest extends CiviUnitTestCase { * Use getValue against a config setting */ function testGetValueConfigSetting() { - $params = array( - 'version' => $this->_apiversion, - 'name' => 'monetaryThousandSeparator', + $params = array( 'name' => 'monetaryThousandSeparator', 'group' => 'Localization Setting', ); - $result = civicrm_api('setting', 'getvalue', $params); + $result = $this->callAPISuccess('setting', 'getvalue', $params); $this->assertEquals(',', $result); } function testGetValue() { - $params = array( - 'version' => $this->_apiversion, - 'name' => 'petition_contacts', + $params = array( 'name' => 'petition_contacts', 'group' => 'Campaign Preferences' ); - $result = civicrm_api('setting', 'getvalue', $params); - $this->assertEquals('Petition Contacts', $result); $description = "Demonstrates getvalue action - intended for runtime use as better caching than get"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description); + + $result = $this->callAPIAndDocument('setting', 'getvalue', $params, __FUNCTION__, __FILE__, $description); + $this->assertEquals('Petition Contacts', $result); } function testGetDefaults() { + $description = "gets defaults setting a variable for a given domain - if no domain is set current is assumed"; - $params = array('version' => $this->_apiversion, + $params = array( 'name' => 'address_format', ); - $result = civicrm_api('setting', 'getdefaults', $params); - $description = "gets defaults setting a variable for a given domain - if no domain is set current is assumed"; - $this->documentMe($params, $result, __FUNCTION__, __FILE__,$description,'GetDefaults','getdefaults'); - $this->assertAPISuccess($result, "in line " . __LINE__); + $result = $this->callAPIAndDocument('setting', 'getdefaults', $params, __FUNCTION__, __FILE__,$description,'GetDefaults','getdefaults'); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); - $params = array('version' => $this->_apiversion, - 'name' => 'mailing_format', - ); - $result = civicrm_api('setting', 'getdefaults', $params); + $params = array('name' => 'mailing_format',); + $result = $this->callAPISuccess('setting', 'getdefaults', $params); $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); } @@ -421,31 +365,24 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ function testRevert() { - $params = array( - 'version' => $this->_apiversion, - 'address_format' => 'xyz', + $params = array( 'address_format' => 'xyz', 'mailing_format' => 'bcs', ); - $result = civicrm_api('setting', 'create', $params); + $result = $this->callAPISuccess('setting', 'create', $params); $this->assertAPISuccess($result, "in line " . __LINE__); - $revertParams = array( - 'version' => $this->_apiversion, - 'name' => 'address_format' + $revertParams = array( 'name' => 'address_format' ); - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's set $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); $description = "Demonstrates reverting a parameter to default value"; - $result = civicrm_api('setting', 'revert', $revertParams); - $this->documentMe($revertParams, $result, __FUNCTION__, __FILE__,$description,'','revert'); + $result = $this->callAPIAndDocument('setting', 'revert', $revertParams, __FUNCTION__, __FILE__,$description,'','revert'); //make sure it's reverted - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'get', $params); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); - $params = array( - 'version' => $this->_apiversion, - 'return' => array('mailing_format'), + $params = array( 'return' => array('mailing_format'), ); - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's unchanged $this->assertEquals('bcs', $result['values'][CRM_Core_Config::domainID()]['mailing_format']); } @@ -454,23 +391,18 @@ class api_v3_SettingTest extends CiviUnitTestCase { */ function testRevertAll() { - $params = array( - 'version' => $this->_apiversion, - 'address_format' => 'xyz', + $params = array( 'address_format' => 'xyz', 'mailing_format' => 'bcs', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertAPISuccess($result, "in line " . __LINE__); - $revertParams = array( - 'version' => $this->_apiversion, - ); - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'create', $params); + $revertParams = array( ); + $result = $this->callAPISuccess('setting', 'get', $params); //make sure it's set $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); - civicrm_api('setting', 'revert', $revertParams); + $this->callAPISuccess('setting', 'revert', $revertParams); //make sure it's reverted - $result = civicrm_api('setting', 'get', array('version' => 3, 'group' => 'core')); + $result = $this->callAPISuccess('setting', 'get', array('group' => 'core')); $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); } @@ -481,31 +413,24 @@ class api_v3_SettingTest extends CiviUnitTestCase { function testFill() { $domparams = array( 'name' => 'B Team Domain', - 'version' => 3, + ); + $dom = $this->callAPISuccess('domain', 'create', $domparams); + $params = array( 'domain_id' => 'all', ); - $dom = civicrm_api('domain', 'create', $domparams); - $params = array( - 'version' => $this->_apiversion, - 'domain_id' => 'all', - ); - $result = civicrm_api('setting', 'get', $params); - $params = array( - 'version' => $this->_apiversion, - 'address_format' => 'xyz', + $result = $this->callAPISuccess('setting', 'get', $params); + $params = array( 'address_format' => 'xyz', 'mailing_format' => 'bcs', 'domain_id' => $this->_domainID2, ); - $result = civicrm_api('setting', 'create', $params); - $params = array( - 'version' => $this->_apiversion, - 'domain_id' => $dom['id'], + $result = $this->callAPISuccess('setting', 'create', $params); + $params = array( 'domain_id' => $dom['id'], ); - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'get', $params); $this->assertAPISuccess($result, "in line " . __LINE__); $this->assertArrayNotHasKey('tag_unconfirmed', $result['values'][$dom['id']],'setting for domain 3 should not be set. Debug this IF domain test is passing'); - $result = civicrm_api('setting', 'fill', $params); + $result = $this->callAPISuccess('setting', 'fill', $params); $this->assertAPISuccess($result, "in line " . __LINE__); - $result = civicrm_api('setting', 'get', $params); + $result = $this->callAPISuccess('setting', 'get', $params); $this->assertAPISuccess($result, "in line " . __LINE__); $this->assertArrayHasKey('tag_unconfirmed', $result['values'][$dom['id']]); $this->assertArrayHasKey('extensionsDir', $result['values'][$dom['id']]); diff --git a/tests/phpunit/api/v3/SurveyRespondantTest.php b/tests/phpunit/api/v3/SurveyRespondantTest.php index d7cea28c64..1188c338d3 100644 --- a/tests/phpunit/api/v3/SurveyRespondantTest.php +++ b/tests/phpunit/api/v3/SurveyRespondantTest.php @@ -28,27 +28,24 @@ require_once 'CiviTest/CiviUnitTestCase.php'; class api_v3_SurveyRespondantTest extends CiviUnitTestCase { - protected $_apiversion; + protected $_apiversion =3; protected $params; public $_eNoticeCompliant = TRUE; function setUp() { - $this->_apiversion = 3; - $phoneBankActivity = civicrm_api('Option_value', 'Get', array('label' => 'PhoneBank', 'version' => $this->_apiversion, 'sequential' => 1)); + $phoneBankActivity = $this->callAPISuccess('Option_value', 'Get', array('label' => 'PhoneBank', 'sequential' => 1)); $phoneBankActivityTypeID = $phoneBankActivity['values'][0]['value']; $surveyParams = array( - 'version' => $this->_apiversion, 'title' => "survey respondent", 'activity_type_id' => $phoneBankActivityTypeID, 'instructions' => "Call people, ask for money", ); - $survey = civicrm_api('survey', 'create', $surveyParams); + $survey = $this->callAPISuccess('survey', 'create', $surveyParams); $surveyID = $survey['id']; $this->params = array ( - 'version' => $this->_apiversion, - 'sequential' =>'1', - 'survey_id' => $surveyID - ); + 'sequential' =>'1', + 'survey_id' => $surveyID + ); parent::setUp(); } @@ -56,23 +53,11 @@ class api_v3_SurveyRespondantTest extends CiviUnitTestCase { $this->quickCleanup(array('civicrm_survey')); } - /** - * Test surveyRespondent get with wrong params type. - */ - public function testGetWrongParamsType() { - $params = 'abc'; - $GetWrongParamsType = civicrm_api("SurveyRespondant","get", $params ); - $this->assertEquals($GetWrongParamsType['error_message'], 'Input variable `params` is not an array'); - } - /** * Test survey respondent get. */ public function testGetSurveyRespondants() { - $result = civicrm_api("SurveyRespondant","get", $this->params ); - $this->assertAPISuccess($result); - $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, 'In line ' . __LINE__); + $result = $this->callAPIAndDocument("SurveyRespondant","get", $this->params, __FUNCTION__, __FILE__); } } diff --git a/tests/phpunit/api/v3/SurveyTest.php b/tests/phpunit/api/v3/SurveyTest.php index f191b3eb59..629dd3331e 100644 --- a/tests/phpunit/api/v3/SurveyTest.php +++ b/tests/phpunit/api/v3/SurveyTest.php @@ -122,7 +122,7 @@ class api_v3_SurveyTest extends CiviUnitTestCase { ); $result = $this->callAPISuccess('survey', 'create', $this->params); $result = $this->callAPIAndDocument('survey', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertEquals(0, civicrm_api('survey', 'getcount', array('version' => 3)), 'In line ' . __LINE__); + $this->assertEquals(0, $this->callAPISuccess('survey', 'getcount', array()), 'In line ' . __LINE__); } } diff --git a/tests/phpunit/api/v3/SystemTest.php b/tests/phpunit/api/v3/SystemTest.php index 4b766b7cd4..f41b48d0ac 100644 --- a/tests/phpunit/api/v3/SystemTest.php +++ b/tests/phpunit/api/v3/SystemTest.php @@ -107,12 +107,8 @@ class api_v3_SystemTest extends CiviUnitTestCase { $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); - $params = array( - 'version' => 3, - ); - $result = civicrm_api('system', 'flush', $params); - $this->assertAPISuccess($result); - $this->documentMe($params, $result, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush', 'flush'); + $params = array(); + $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush', 'flush'); $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); } diff --git a/tests/phpunit/api/v3/UFGroupTest.php b/tests/phpunit/api/v3/UFGroupTest.php index ad2f7961a7..0df4879bbc 100644 --- a/tests/phpunit/api/v3/UFGroupTest.php +++ b/tests/phpunit/api/v3/UFGroupTest.php @@ -1,5 +1,4 @@ _apiversion = 3; - // Truncate the tables - $this->quickCleanup( - array( - 'civicrm_group', - 'civicrm_contact', - 'civicrm_uf_group', - 'civicrm_uf_join', - 'civicrm_uf_match', - ) - ); - - $op = new PHPUnit_Extensions_Database_Operation_Insert; - $op->execute( - $this->_dbconn, - new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') - ); - - // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together - $GLOBALS['_HTML_QuickForm_registered_rules'] = array( - 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'), - 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'), - 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'), - 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'), - 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'), - 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'), - ); - // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] - $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array( - 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'), - 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'), - 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'), - 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'), - 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'), - 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'), - 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'), - 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'), - 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'), - 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'), - 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'), - 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'), - 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'), - 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'), - 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'), - 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'), - 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'), - 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'), - 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'), - 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'), - 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'), - 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'), - 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'), - 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'), - 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'), - 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'), - 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'), - ); + $this->_groupId = $this->groupCreate(); + $this->_contactId = $this->individualCreate(); + $this->createLoggedInUser(); + $ufGroup = $this->callAPISuccess('uf_group', 'create', array( + 'group_type' => 'Contact', + 'help_pre' => 'Profile to Test API', + 'title' =>'Test Profile', + )); + $this->_ufGroupId = $ufGroup['id']; + $ufMatch = $this->callAPISuccess('uf_match', 'create', array( + 'contact_id' => $this->_contactId, + 'uf_id' => 42, + 'uf_name' => 'email@mail.com', + )); + $this->_ufGroupId = $ufMatch['id']; $this->params = array( 'add_captcha' => 1, - 'add_contact_to_group' => 2, + 'add_contact_to_group' => $this->_groupId, + 'group' => $this->_groupId, 'cancel_URL' => 'http://example.org/cancel', 'created_date' => '2009-06-27 00:00:00', - 'created_id' => 69, - 'group' => 2, + 'created_id' => $this->_contactId, 'group_type' => 'Individual,Contact', 'help_post' => 'help post', 'help_pre' => 'help pre', @@ -133,12 +80,10 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { 'notify' => 'admin@example.org', 'post_URL' => 'http://example.org/post', 'title' => 'Test Group', - 'version' => $this->_apiversion, ); } function tearDown() { - // Truncate the tables $this->quickCleanup( array( @@ -159,12 +104,10 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { 'title' => 'Edited Test Profile', 'help_post' => 'Profile Pro help text.', 'is_active' => 1, - 'id' => $this->_ufGroupId, - 'version' => $this->_apiversion, - ); + 'id' => $this->_ufGroupId + ); - $result = civicrm_api('uf_group', 'create', $params); - unset($params['version']); + $result = $this->callAPISuccess('uf_group', 'create', $params); foreach ($params as $key => $value) { $this->assertEquals($result['values'][$result['id']][$key], $value); } @@ -172,14 +115,13 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { function testUFGroupCreate() { - $result = civicrm_api('uf_group', 'create', $this->params); - $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('uf_group', 'create', $this->params, __FUNCTION__, __FILE__); $this->assertAPISuccess($result); $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); $this->params['created_date'] = date('YmdHis', strtotime($this->params['created_date'])); foreach ($this->params as $key => $value) { - if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version') { + if ($key == 'add_contact_to_group' or $key == 'group') { continue; } $expected = $this->params[$key]; @@ -193,21 +135,18 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { } function testUFGroupCreateWithWrongParams() { - $result = civicrm_api('uf_group', 'create', 'a string'); - $this->assertAPIFailure($result); - $result = civicrm_api('uf_group', 'create', array('name' => 'A title-less group')); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group')); } function testUFGroupUpdate() { $params = array( 'id' => $this->_ufGroupId, 'add_captcha' => 1, - 'add_contact_to_group' => 2, + 'add_contact_to_group' => $this->_groupId, 'cancel_URL' => 'http://example.org/cancel', 'created_date' => '2009-06-27', - 'created_id' => 69, - 'group' => 2, + 'created_id' => $this->_contactId, + 'group' => $this->_groupId, 'group_type' => 'Individual,Contact', 'help_post' => 'help post', 'help_pre' => 'help pre', @@ -221,11 +160,8 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { 'name' => 'test_group', 'notify' => 'admin@example.org', 'post_URL' => 'http://example.org/post', - 'title' => 'Test Group', - 'version' => $this->_apiversion, - ); - $result = civicrm_api('uf_group', 'create', $params); - unset($params['version']); + 'title' => 'Test Group', ); + $result = $this->callAPISuccess('uf_group', 'create', $params); $params['created_date'] = date('YmdHis', strtotime($params['created_date'])); foreach ($params as $key => $value) { if ($key == 'add_contact_to_group' or $key == 'group') { @@ -239,19 +175,14 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { } function testUFGroupGet() { - - $result = civicrm_api('uf_group', 'create', $this->params); - $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__); - - $params = array('version' => 3, 'id' => $result['id']); - $result = civicrm_api('uf_group', 'get', $params); - $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__); - $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess('uf_group', 'create', $this->params); + $params = array('id' => $result['id']); + $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); foreach ($this->params as $key => $value) { // skip created date because it doesn't seem to be working properly & fixing date handling is for another day - if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'version' or $key == 'created_date') { + if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') { continue; } $expected = $this->params[$key]; @@ -265,27 +196,14 @@ class api_v3_UFGroupTest extends CiviUnitTestCase { } function testUFGroupUpdateWithEmptyParams() { - $result = civicrm_api('uf_group', 'create', array(), $this->_ufGroupId); - $this->assertAPIFailure($result); - } - - function testUFGroupUpdateWithWrongParams() { - $result = civicrm_api('uf_group', 'create', 'a string', $this->_ufGroupId); - $this->assertAPIFailure($result); - $result = civicrm_api('uf_group', 'create', array('title' => 'Title'), 'a string'); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_group', 'create', array(), $this->_ufGroupId); } function testUFGroupDelete() { - - $ufGroup = civicrm_api('uf_group', 'create', $this->params); - $this->assertAPISuccess($ufGroup); - $params = array('version' => $this->_apiversion, 'id' => $ufGroup['id']); - $this->assertEquals(1, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__); - $result = civicrm_api('uf_group', 'delete', $params, "in line " . __LINE__); - $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); - $this->assertEquals(0, civicrm_api('uf_group', 'getcount', $params), "in line " . __LINE__); - $this->assertAPISuccess($result, "in line " . __LINE__); + $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params); + $params = array('id' => $ufGroup['id']); + $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); + $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__, __FILE__); + $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); } } - -- 2.25.1