From d0e1eff24573414e78109575961c62fb081259b7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 14 Jun 2013 16:09:41 -0700 Subject: [PATCH] Mass update tests to use callAPIFailure --- tests/phpunit/api/v3/ActivityTest.php | 75 +++++------------ tests/phpunit/api/v3/AddressTest.php | 3 +- tests/phpunit/api/v3/BatchTest.php | 29 +------ tests/phpunit/api/v3/ContactTest.php | 24 ++---- tests/phpunit/api/v3/ContactTypeTest.php | 22 ++--- tests/phpunit/api/v3/ContributionSoftTest.php | 32 ++------ tests/phpunit/api/v3/ContributionTest.php | 30 ++----- tests/phpunit/api/v3/CustomFieldTest.php | 15 ++-- tests/phpunit/api/v3/CustomGroupTest.php | 21 ++--- .../api/v3/CustomValueContactTypeTest.php | 7 +- tests/phpunit/api/v3/EntityTagTest.php | 21 ++--- tests/phpunit/api/v3/EventTest.php | 39 ++------- tests/phpunit/api/v3/GroupContactTest.php | 18 ++--- .../phpunit/api/v3/GroupOrganizationTest.php | 28 ++----- tests/phpunit/api/v3/GroupTest.php | 19 ++--- tests/phpunit/api/v3/JobTest.php | 22 ++--- tests/phpunit/api/v3/MailingContactTest.php | 12 +-- tests/phpunit/api/v3/MailingGroupTest.php | 12 +-- tests/phpunit/api/v3/MembershipStatusTest.php | 25 ++---- tests/phpunit/api/v3/MembershipTest.php | 21 ++--- tests/phpunit/api/v3/MembershipTypeTest.php | 45 +++-------- tests/phpunit/api/v3/NoteTest.php | 18 ++--- tests/phpunit/api/v3/OptionGroupTest.php | 3 +- .../phpunit/api/v3/ParticipantPaymentTest.php | 40 +++------- tests/phpunit/api/v3/ParticipantTest.php | 47 +++-------- tests/phpunit/api/v3/PaymentProcessorTest.php | 4 +- .../api/v3/PaymentProcessorTypeTest.php | 30 +++---- tests/phpunit/api/v3/PhoneTest.php | 3 +- tests/phpunit/api/v3/PledgeTest.php | 9 +-- tests/phpunit/api/v3/ProfileTest.php | 49 ++++-------- tests/phpunit/api/v3/RelationshipTest.php | 80 +++++-------------- tests/phpunit/api/v3/RelationshipTypeTest.php | 39 +++------ tests/phpunit/api/v3/SettingTest.php | 9 +-- tests/phpunit/api/v3/SurveyRespondantTest.php | 8 -- .../v3/SyntaxConformanceAllEntitiesTest.php | 3 +- tests/phpunit/api/v3/TagTest.php | 31 ++----- tests/phpunit/api/v3/UFJoinTest.php | 29 ++----- tests/phpunit/api/v3/UFMatchTest.php | 6 +- 38 files changed, 251 insertions(+), 677 deletions(-) diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index aaa228798e..72fa0e78ac 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -133,8 +133,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testActivityCreateEmpty() { $params = array('version' => $this->_apiversion); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -147,8 +146,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -170,8 +168,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result);; + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -259,8 +256,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -279,8 +275,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } function testActivityCreateWithInvalidPriority() { @@ -297,8 +292,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); $this->assertEquals("'44' is not a valid option for field priority_id", $result['error_message']); $this->assertEquals(2001, $result['error_code']); $this->assertEquals('priority_id', $result['error_field']); @@ -339,8 +333,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); $this->assertEquals("'ergUrgent' is not a valid option for field priority_id", $result['error_message']); } @@ -558,9 +551,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -580,9 +571,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); $this->assertEquals("'Invalid' is not a valid option for field status_id", $result['error_message']); } @@ -847,8 +836,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testDeleteActivityForEmptyParams() { $params = array('version' => $this->_apiversion); - $result = civicrm_api('activity', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'delete', $params); } /** @@ -859,8 +847,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Meeting', 'version' => $this->_apiversion, ); - $result = civicrm_api('activity', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'delete', $params); } /** @@ -868,8 +855,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { */ function testDeleteActivityWithoutActivityType() { $params = array('id' => 1); - $result = civicrm_api('activity', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'delete', $params); } /** @@ -881,8 +867,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Test Activity', ); - $result = civicrm_api('activity', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'delete', $params); } /** @@ -909,22 +894,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'scheduled_date_time' => date('Ymd'), ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); - } - - /** - * check with incorrect required fields - */ - function testActivityUpdateWithIncorrectData() { - $params = array( - 'activity_name' => 'Meeting', - 'subject' => 'this case should fail', - 'scheduled_date_time' => date('Ymd'), - ); - - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -938,8 +908,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'scheduled_date_time' => date('Ymd'), ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); } /** @@ -951,12 +920,10 @@ class api_v3_ActivityTest extends CiviUnitTestCase { 'activity_name' => 'Test Activity', 'subject' => 'this case should fail', 'scheduled_date_time' => date('Ymd'), - 'version' => $this->_apiversion, 'source_contact_id' => 17, ); - $result = civicrm_api('activity', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'create', $params); $this->assertEquals($result['error_message'], 'Invalid Activity Id', "In line " . __LINE__); } @@ -1286,17 +1253,11 @@ class api_v3_ActivityTest extends CiviUnitTestCase { * Test civicrm_activity_contact_get() with invalid Contact Id */ function testActivitiesContactGetWithInvalidContactId() { - $params = array('contact_id' => NULL); - $result = civicrm_api('activity', 'get', $params); - $this->assertAPIFailure($result); - $params = array('contact_id' => 'contact'); - $result = civicrm_api('activity', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'get', $params); $params = array('contact_id' => 2.4); - $result = civicrm_api('activity', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('activity', 'get', $params); } /** diff --git a/tests/phpunit/api/v3/AddressTest.php b/tests/phpunit/api/v3/AddressTest.php index d18e60861b..e881e9abde 100644 --- a/tests/phpunit/api/v3/AddressTest.php +++ b/tests/phpunit/api/v3/AddressTest.php @@ -119,8 +119,7 @@ class api_v3_AddressTest extends CiviUnitTestCase { public function testCreateAddressTooLongSuffix() { $params = $this->_params; $params['street_number_suffix'] = 'really long string'; - $result = civicrm_api('address', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('address', 'create', $params); $this->assertEquals(2100, $result['error_code']); } /* diff --git a/tests/phpunit/api/v3/BatchTest.php b/tests/phpunit/api/v3/BatchTest.php index 8566d7be75..9a13f00ed3 100644 --- a/tests/phpunit/api/v3/BatchTest.php +++ b/tests/phpunit/api/v3/BatchTest.php @@ -85,21 +85,10 @@ class api_v3_BatchTest extends CiviUnitTestCase { */ public function testGetWrongParamsType() { $params = 'is_string'; - $result = civicrm_api('batch', 'get', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('batch', 'get', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } - /** - * Test civicrm_batch_get with empty params. - */ - public function testGetEmptyParams() { - $params = array(); - $result = civicrm_api('batch', 'get', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); - $this->assertEquals('Mandatory key(s) missing from params array: version', $result['error_message'], 'In line ' . __LINE__); - } - /** * Test civicrm_batch_get - success expected. */ @@ -117,22 +106,11 @@ class api_v3_BatchTest extends CiviUnitTestCase { ///////////////// civicrm_batch_create methods - /** - * Test civicrm_batch_create with wrong params type. - */ - function testCreateWrongParamsType() { - $params = 'a string'; - $result = civicrm_api('batch', 'create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); - $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); - } - /** * Test civicrm_batch_create with empty params. */ function testCreateEmptyParams() { - $result = civicrm_api('batch', 'create', $this->_params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $this->callAPIFailure('batch', 'create', $this->_params); } /** @@ -204,8 +182,7 @@ class api_v3_BatchTest extends CiviUnitTestCase { * Test civicrm_batch_delete with wrong batch id type. */ function testDeleteWrongParams() { - $result = civicrm_api('batch', 'delete', 'tyttyd'); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('batch', 'delete', 'tyttyd'); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 52ce00537d..a4e40ca6a2 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -171,8 +171,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'contact_type' => 'Does not Exist', 'version' => $this->_apiversion, ); - $result = civicrm_api('contact', 'create', $params); - $this->assertApiFailure($result); + $result = $this->callAPIFailure('contact', 'create', $params); $this->assertEquals("'Does not Exist' is not a valid option for field contact_type", $result['error_message']); } @@ -353,20 +352,17 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals(1, $contact['id'], "In line " . __LINE__); // delete the contact - civicrm_api('contact', 'delete', $contact); + $this->callAPISuccess('contact', 'delete', $contact); } /** - * Verify that attempt to create organization contact with only - * organization name succeeds + * Verify that attempt to create organization contact without organization name fails */ function testCreateNoNameOrganization() { $params = array( 'first_name' => 'The abc Organization', 'contact_type' => 'Organization', - 'version' => $this->_apiversion, ); - $result = civicrm_api('contact', 'create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $result = $this->callAPIFailure('contact', 'create', $params); } /** * check with complete array + custom field @@ -788,8 +784,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('contact', 'create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $result = $this->callAPIFailure('contact', 'create', $params); } /** * Verify that attempt to create individual contact with first @@ -901,8 +896,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('contact', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'should fail due to missing household name on line ' . __LINE__); + $result = $this->callAPIFailure('contact', 'create', $params); } /** @@ -1735,8 +1729,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { ); $config = CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array('access CiviCRM'); - $result = civicrm_api('contact', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to create a contact'); + $result = $this->callAPIFailure('contact', 'create', $params); $this->assertEquals('API permission check failed for contact/create call; missing permission: add contacts.', $result['error_message'], 'lacking permissions should not be enough to create a contact'); $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts'); @@ -1751,8 +1744,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { $params = array('id' => $result['id'], 'contact_type' => 'Individual', 'last_name' => 'Bar', 'check_permissions' => TRUE, 'version' => $this->_apiversion); $config->userPermissionClass->permissions = array('access CiviCRM'); - $result = civicrm_api('contact', 'update', $params); - $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to update a contact'); + $result = $this->callAPIFailure('contact', 'update', $params); $this->assertEquals('API permission check failed for contact/update call; missing permission: edit all contacts.', $result['error_message'], 'lacking permissions should not be enough to update a contact'); $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'view all contacts', 'edit all contacts', 'import contacts'); diff --git a/tests/phpunit/api/v3/ContactTypeTest.php b/tests/phpunit/api/v3/ContactTypeTest.php index 97edaac81d..f031d25dfd 100644 --- a/tests/phpunit/api/v3/ContactTypeTest.php +++ b/tests/phpunit/api/v3/ContactTypeTest.php @@ -150,8 +150,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeHousehold, 'version' => $this->_apiversion, ); - $contact = civicrm_api('contact', 'create', $contactParams); - $this->assertEquals($contact['is_error'], 1, "In line " . __LINE__); + $contact = $this->callAPIFailure('contact', 'create', $contactParams); // check for Type:Organization Subtype:sub_individual $contactParams = array( @@ -160,8 +159,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeIndividual, 'version' => $this->_apiversion, ); - $contact = civicrm_api('contact', 'create', $contactParams); - $this->assertEquals($contact['is_error'], 1, "In line " . __LINE__); + $contact = $this->callAPIFailure('contact', 'create', $contactParams); } @@ -263,9 +261,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeHousehold, 'version' => $this->_apiversion, ); - $updateContact = civicrm_api('contact', 'create', $updateParams); - - $this->assertEquals($updateContact['is_error'], 1, "In line " . __LINE__); + $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); $params = array( 'contact_id' => $contact['id'], 'version' => $this->_apiversion, @@ -287,9 +283,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeIndividual, 'version' => $this->_apiversion, ); - $updateContact = civicrm_api('contact', 'create', $updateParams); - - $this->assertEquals($updateContact['is_error'], 1, "In line " . __LINE__); + $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); $params = array( 'contact_id' => $contact['id'], 'version' => $this->_apiversion, @@ -420,9 +414,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeHousehold, 'version' => $this->_apiversion, ); - $updateContact = civicrm_api('contact', 'create', $updateParams); - - $this->assertEquals($updateContact['is_error'], 1, "In line " . __LINE__); + $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); $params = array( 'contact_id' => $contact['id'], 'version' => $this->_apiversion, @@ -444,9 +436,7 @@ class api_v3_ContactTypeTest extends CiviUnitTestCase { 'contact_sub_type' => $this->subTypeIndividual, 'version' => $this->_apiversion, ); - $updateContact = civicrm_api('contact', 'create', $updateParams); - - $this->assertEquals($updateContact['is_error'], 1, "In line " . __LINE__); + $updateContact = $this->callAPIFailure('contact', 'create', $updateParams); $params = array( 'contact_id' => $contact['id'], 'version' => $this->_apiversion, diff --git a/tests/phpunit/api/v3/ContributionSoftTest.php b/tests/phpunit/api/v3/ContributionSoftTest.php index 999db71c46..2ffb5fb099 100644 --- a/tests/phpunit/api/v3/ContributionSoftTest.php +++ b/tests/phpunit/api/v3/ContributionSoftTest.php @@ -118,17 +118,9 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { )); } - function testGetEmptyParamsContributionSoft() { - $params = array(); - $contribution = civicrm_api('contribution_soft', 'get', $params); - $this->assertEquals($contribution['is_error'], 1); - $this->assertEquals($contribution['error_message'], 'Mandatory key(s) missing from params array: version'); - } - function testGetParamsNotArrayContributionSoft() { $params = 'contact_id= 1'; - $contribution = civicrm_api('contribution', 'get', $params); - $this->assertEquals($contribution['is_error'], 1); + $contribution = $this->callAPIFailure('contribution', 'get', $params); $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array'); } @@ -217,23 +209,20 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { $params = array('version' => $this->_apiversion); - $softcontribution = civicrm_api('contribution_soft', 'create', $params); - $this->assertEquals($softcontribution['is_error'], 1, 'In line ' . __LINE__); + $softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params); $this->assertEquals($softcontribution['error_message'], 'Mandatory key(s) missing from params array: contribution_id, amount, contact_id', 'In line ' . __LINE__); } function testCreateParamsNotArrayContributionSoft() { $params = 'contact_id= 1'; - $softcontribution = civicrm_api('contribution_soft', 'create', $params); - $this->assertEquals($softcontribution['is_error'], 1); + $softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params); $this->assertEquals($softcontribution['error_message'], 'Input variable `params` is not an array'); } function testCreateParamsWithoutRequiredKeysContributionSoft() { $params = array('version' => 3); - $softcontribution = civicrm_api('contribution_soft', 'create', $params); - $this->assertEquals($softcontribution['is_error'], 1); + $softcontribution = $this->callAPIFailure('contribution_soft', 'create', $params); $this->assertEquals($softcontribution['error_message'], 'Mandatory key(s) missing from params array: contribution_id, amount, contact_id'); } @@ -368,14 +357,12 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { ///////////////// civicrm_contribution_soft_delete methods function testDeleteEmptyParamsContributionSoft() { $params = array('version' => $this->_apiversion); - $softcontribution = civicrm_api('contribution_soft', 'delete', $params); - $this->assertEquals($softcontribution['is_error'], 1); + $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params); } function testDeleteParamsNotArrayContributionSoft() { $params = 'id= 1'; - $softcontribution = civicrm_api('contribution_soft', 'delete', $params); - $this->assertEquals($softcontribution['is_error'], 1); + $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params); $this->assertEquals($softcontribution['error_message'], 'Input variable `params` is not an array'); } @@ -384,8 +371,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { 'contribution_source' => 'SSF', 'version' => $this->_apiversion, ); - $softcontribution = civicrm_api('contribution_soft', 'delete', $params); - $this->assertEquals($softcontribution['is_error'], 1); + $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params); } function testDeleteContributionSoft() { @@ -416,9 +402,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { */ function testSearchWrongParamsType() { $params = 'a string'; - $result = civicrm_api('contribution_soft', 'get', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('contribution_soft', 'get', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 306cf5188c..4ad8036b3d 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -111,17 +111,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } ///////////////// civicrm_contribution_get methods - function testGetEmptyParamsContribution() { - $params = array(); - $contribution = civicrm_api('contribution', 'get', $params); - $this->assertAPIFailure($contribution); - $this->assertEquals($contribution['error_message'], 'Mandatory key(s) missing from params array: version'); - } function testGetParamsNotArrayContribution() { $params = 'contact_id= 1'; - $contribution = civicrm_api('contribution', 'get', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'get', $params); $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array'); } @@ -354,23 +347,20 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $params = array('version' => $this->_apiversion); - $contribution = civicrm_api('contribution', 'create', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'create', $params); $this->assertEquals($contribution['error_message'], 'Mandatory key(s) missing from params array: financial_type_id, total_amount, contact_id', 'In line ' . __LINE__); } function testCreateParamsNotArrayContribution() { $params = 'contact_id= 1'; - $contribution = civicrm_api('contribution', 'create', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'create', $params); $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array'); } function testCreateParamsWithoutRequiredKeys() { $params = array('version' => 3); - $contribution = civicrm_api('contribution', 'create', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'create', $params); $this->assertEquals($contribution['error_message'], 'Mandatory key(s) missing from params array: financial_type_id, total_amount, contact_id'); } @@ -1042,8 +1032,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_status_id' => 2, ) ); - $contribution = civicrm_api('contribution', 'update', $newParams); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'update', $newParams); $this->assertEquals($contribution['error_message'], ts('Cannot change contribution status from Completed to Pending.'), 'In line ' . __LINE__); } @@ -1173,14 +1162,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { ///////////////// civicrm_contribution_delete methods function testDeleteEmptyParamsContribution() { $params = array('version' => $this->_apiversion); - $contribution = civicrm_api('contribution', 'delete', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'delete', $params); } function testDeleteParamsNotArrayContribution() { $params = 'contribution_id= 1'; - $contribution = civicrm_api('contribution', 'delete', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'delete', $params); $this->assertEquals($contribution['error_message'], 'Input variable `params` is not an array'); } @@ -1189,8 +1176,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'contribution_source' => 'SSF', 'version' => $this->_apiversion, ); - $contribution = civicrm_api('contribution', 'delete', $params); - $this->assertAPIFailure($contribution); + $contribution = $this->callAPIFailure('contribution', 'delete', $params); } function testDeleteContribution() { diff --git a/tests/phpunit/api/v3/CustomFieldTest.php b/tests/phpunit/api/v3/CustomFieldTest.php index 922c742a47..5d7e321442 100644 --- a/tests/phpunit/api/v3/CustomFieldTest.php +++ b/tests/phpunit/api/v3/CustomFieldTest.php @@ -67,8 +67,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { function testCustomFieldCreateNoArray() { $fieldParams = NULL; - $customField = civicrm_api('custom_field', 'create', $fieldParams); - $this->assertEquals($customField['is_error'], 1); + $customField = $this->callAPIFailure('custom_field', 'create', $fieldParams); $this->assertEquals($customField['error_message'], 'Input variable `params` is not an array'); } @@ -90,8 +89,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $customField = civicrm_api('custom_field', 'create', $params); - $this->assertEquals($customField['is_error'], 1); + $customField = $this->callAPIFailure('custom_field', 'create', $params); $this->assertEquals($customField['error_message'], 'Mandatory key(s) missing from params array: label'); } @@ -139,8 +137,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $customField = civicrm_api('custom_field', 'create', $fieldParams); - $this->assertEquals($customField['is_error'], 1); + $customField = $this->callAPIFailure('custom_field', 'create', $fieldParams); $this->assertEquals($customField['error_message'], 'Mandatory key(s) missing from params array: custom_group_id'); } @@ -365,8 +362,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { */ function testCustomFieldDeleteNoArray() { $params = NULL; - $customField = civicrm_api('custom_field', 'delete', $params); - $this->assertEquals($customField['is_error'], 1); + $customField = $this->callAPIFailure('custom_field', 'delete', $params); $this->assertEquals($customField['error_message'], 'Input variable `params` is not an array'); } @@ -375,8 +371,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { */ function testCustomFieldDeleteWithoutFieldID() { $params = array('version' => $this->_apiversion); - $customField = civicrm_api('custom_field', 'delete', $params); - $this->assertEquals($customField['is_error'], 1); + $customField = $this->callAPIFailure('custom_field', 'delete', $params); $this->assertEquals($customField['error_message'], 'Mandatory key(s) missing from params array: id'); } diff --git a/tests/phpunit/api/v3/CustomGroupTest.php b/tests/phpunit/api/v3/CustomGroupTest.php index 648f003926..2a271cfbcd 100644 --- a/tests/phpunit/api/v3/CustomGroupTest.php +++ b/tests/phpunit/api/v3/CustomGroupTest.php @@ -83,8 +83,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { $params = array( 'version' => $this->_apiversion, ); - $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); + $customGroup = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: title, extends', 'In line ' . __LINE__ ); @@ -130,8 +129,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); + $customGroup = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: extends', 'In line ' . __LINE__); } @@ -213,8 +211,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('custom_group', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($result['error_message'], 'implode(): Invalid arguments passed', 'In line ' . __LINE__); } @@ -245,8 +242,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { */ function testCustomGroupCreateNotArray() { $params = NULL; - $customGroup = civicrm_api('custom_group', 'create', $params); - $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); + $customGroup = $this->callAPIFailure('custom_group', 'create', $params); $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } @@ -366,11 +362,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { * check without GroupID */ function testCustomGroupDeleteWithoutGroupID() { - $params = array( - 'version' => $this->_apiversion, - ); - $customGroup = civicrm_api('custom_group', 'delete', $params); - $this->assertAPIFailure($customGroup, 'In line ' . __LINE__); + $customGroup = $this->callAPIFailure('custom_group', 'delete', array()); $this->assertEquals($customGroup['error_message'], 'Mandatory key(s) missing from params array: id', 'In line ' . __LINE__); } @@ -379,8 +371,7 @@ class api_v3_CustomGroupTest extends CiviUnitTestCase { */ function testCustomGroupDeleteNoArray() { $params = NULL; - $customGroup = civicrm_api('custom_group', 'delete', $params); - $this->assertEquals($customGroup['is_error'], 1, 'In line ' . __LINE__); + $customGroup = $this->callAPIFailure('custom_group', 'delete', $params); $this->assertEquals($customGroup['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/CustomValueContactTypeTest.php b/tests/phpunit/api/v3/CustomValueContactTypeTest.php index b80fec3848..e85e5a573c 100644 --- a/tests/phpunit/api/v3/CustomValueContactTypeTest.php +++ b/tests/phpunit/api/v3/CustomValueContactTypeTest.php @@ -136,11 +136,11 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { $result = civicrm_api('Contact', 'getfields', array('version' => 3)); $this->assertAPISuccess($result); $this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'If This fails there is probably a cachine issue - failure in line' . __LINE__ . print_r(array_keys($result['values']), TRUE)); - $result = civicrm_api('Contact', 'getfields', array('version' => 3, 'action' => 'create', 'contact_type' => 'Individual'), 'in line' . __LINE__);; + $result = civicrm_api('Contact', 'getfields', array('version' => 3, 'action' => 'create', 'contact_type' => 'Individual'), 'in line' . __LINE__); $this->assertArrayHasKey("custom_{$this->IndividualField['id']}", $result['values']); $result = civicrm_api('Contact', 'getfields', array('version' => 3, 'action' => 'create', 'contact_type' => 'Organization')); $this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values'], 'in line' . __LINE__ . print_r(array_keys($result['values']), TRUE)); - $result = civicrm_api('Relationship', 'getfields', array('version' => 3, 'action' => 'create'), 'in line' . __LINE__);; + $result = civicrm_api('Relationship', 'getfields', array('version' => 3, 'action' => 'create'), 'in line' . __LINE__); $this->assertArrayNotHasKey("custom_{$this->IndividualField['id']}", $result['values']); } @@ -170,8 +170,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { $params = array( 'version' => 3, ); - $contact = civicrm_api('contact', 'create', $params); - $this->assertEquals($contact['is_error'], 1); + $contact = $this->callAPIFailure('contact', 'create', $params); $this->assertEquals($contact['error_message'], 'Mandatory key(s) missing from params array: contact_type'); } diff --git a/tests/phpunit/api/v3/EntityTagTest.php b/tests/phpunit/api/v3/EntityTagTest.php index a023b4bd48..ef387e106e 100644 --- a/tests/phpunit/api/v3/EntityTagTest.php +++ b/tests/phpunit/api/v3/EntityTagTest.php @@ -63,8 +63,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { function testAddEmptyParams() { $params = array('version' => $this->_apiversion); - $individualEntity = civicrm_api('entity_tag', 'create', $params); - $this->assertEquals($individualEntity['is_error'], 1); + $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params); $this->assertEquals($individualEntity['error_message'], 'contact_id is a required field'); } @@ -73,8 +72,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { 'contact_id' => $this->_individualID, 'version' => $this->_apiversion, ); - $individualEntity = civicrm_api('entity_tag', 'create', $params); - $this->assertEquals($individualEntity['is_error'], 1); + $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params); $this->assertEquals($individualEntity['error_message'], 'tag_id is a required field'); } @@ -83,8 +81,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { 'tag_id' => $this->_tagID, 'version' => $this->_apiversion, ); - $individualEntity = civicrm_api('entity_tag', 'create', $params); - $this->assertEquals($individualEntity['is_error'], 1); + $individualEntity = $this->callAPIFailure('entity_tag', 'create', $params); $this->assertEquals($individualEntity['error_message'], 'contact_id is a required field'); } @@ -155,8 +152,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { function testIndividualEntityTagGetWithoutContactID() { $paramsEntity = array('version' => $this->_apiversion); - $entity = civicrm_api('entity_tag', 'get', $paramsEntity); - $this->assertEquals($entity['is_error'], 1); + $entity = $this->callAPIFailure('entity_tag', 'get', $paramsEntity); $this->assertNotNull($entity['error_message']); $this->assertEquals($entity['error_message'], 'Mandatory key(s) missing from params array: entity_id'); } @@ -183,8 +179,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { function testHouseholdEntityGetWithoutContactID() { $paramsEntity = array('version' => $this->_apiversion); - $entity = civicrm_api('entity_tag', 'get', $paramsEntity); - $this->assertEquals($entity['is_error'], 1); + $entity = $this->callAPIFailure('entity_tag', 'get', $paramsEntity); $this->assertNotNull($entity['error_message']); } @@ -207,8 +202,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { function testOrganizationEntityGetWithoutContactID() { $paramsEntity = array('version' => $this->_apiversion); - $entity = civicrm_api('entity_tag', 'get', $paramsEntity); - $this->assertEquals($entity['is_error'], 1); + $entity = $this->callAPIFailure('entity_tag', 'get', $paramsEntity); $this->assertNotNull($entity['error_message']); } @@ -245,8 +239,7 @@ class api_v3_EntityTagTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('entity_tag', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('entity_tag', 'delete', $params); $this->assertEquals($result['error_message'], 'tag_id is a required field'); } diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index e19d567264..d96821f1c0 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -129,19 +129,6 @@ class api_v3_EventTest extends CiviUnitTestCase { } ///////////////// civicrm_event_get methods - function testGetWrongParamsType() { - $params = 'Annual CiviCRM meet'; - $result = civicrm_api('Event', 'Get', $params); - - $this->assertAPIFailure($result); - } - - function testGetEventEmptyParams() { - $params = array(); - $result = civicrm_api('event', 'get', $params); - - $this->assertAPIFailure($result); - } function testGetEventById() { $params = array( @@ -263,8 +250,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $params = $this->_params[0]; $params['sequential'] =1; $params['loc_block_id'] =100; - $result = civicrm_api('event', 'create', $params); - $this->assertEquals(1, $result['is_error']); + $result = $this->callAPIFailure('event', 'create', $params); } @@ -346,14 +332,12 @@ class api_v3_EventTest extends CiviUnitTestCase { function testCreateEventParamsNotArray() { $params = NULL; - $result = civicrm_api('event', 'create', $params); - $this->assertEquals(1, $result['is_error']); + $result = $this->callAPIFailure('event', 'create', $params); } function testCreateEventEmptyParams() { $params = array(); - $result = civicrm_api('event', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('event', 'create', $params); } function testCreateEventParamsWithoutTitle() { @@ -430,15 +414,12 @@ class api_v3_EventTest extends CiviUnitTestCase { ///////////////// civicrm_event_delete methods function testDeleteWrongParamsType() { $params = 'Annual CiviCRM meet'; - $result = civicrm_api('Event', 'Delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('Event', 'Delete', $params); } function testDeleteEmptyParams() { $params = array(); - $result = civicrm_api('Event', 'Delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('Event', 'Delete', $params); } function testDelete() { @@ -481,8 +462,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = civicrm_api('Event', 'Delete', $params); // try to delete again - there's no such event anymore $params = array('event_id' => $this->_eventIds[0]); - $result = civicrm_api('Event', 'Delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('Event', 'Delete', $params); } ///////////////// civicrm_event_search methods @@ -492,9 +472,7 @@ class api_v3_EventTest extends CiviUnitTestCase { */ function testSearchWrongParamsType() { $params = 'a string'; - $result = civicrm_api('event', 'get', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('event', 'get', $params); } /** @@ -569,8 +547,7 @@ class api_v3_EventTest extends CiviUnitTestCase { ); $config = &CRM_Core_Config::singleton(); $config->userPermissionClass->permissions = array('access CiviCRM'); - $result = civicrm_api('event', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to create an event'); + $result = $this->callAPIFailure('event', 'create', $params); $this->assertEquals('API permission check failed for event/create call; missing permission: access CiviEvent.', $result['error_message'], 'lacking permissions should not be enough to create an event'); $config->userPermissionClass->permissions = array('access CiviEvent', 'edit all events', 'access CiviCRM'); diff --git a/tests/phpunit/api/v3/GroupContactTest.php b/tests/phpunit/api/v3/GroupContactTest.php index ce9908da40..ab368ef115 100644 --- a/tests/phpunit/api/v3/GroupContactTest.php +++ b/tests/phpunit/api/v3/GroupContactTest.php @@ -141,19 +141,15 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { ///////////////// civicrm_group_contact_add methods function testCreateWithWrongParamsType() { $params = 1; - $groups = civicrm_api('group_contact', 'create', $params); - - $this->assertEquals($groups['is_error'], 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 = civicrm_api('group_contact', 'create', $params); - - $this->assertEquals($groups['is_error'], 1); + $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], - 'Mandatory key(s) missing from params array: version, group_id, contact_id' + 'Mandatory key(s) missing from params array: group_id, contact_id' ); } @@ -163,9 +159,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $groups = civicrm_api('group_contact', 'create', $params); - - $this->assertEquals($groups['is_error'], 1); + $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); } @@ -174,9 +168,7 @@ class api_v3_GroupContactTest extends CiviUnitTestCase { 'group_id' => $this->_groupId1, 'version' => $this->_apiversion, ); - $groups = civicrm_api('group_contact', 'create', $params); - - $this->assertEquals($groups['is_error'], 1); + $groups = $this->callAPIFailure('group_contact', 'create', $params); $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); } diff --git a/tests/phpunit/api/v3/GroupOrganizationTest.php b/tests/phpunit/api/v3/GroupOrganizationTest.php index ede6851d90..c936cfa01f 100644 --- a/tests/phpunit/api/v3/GroupOrganizationTest.php +++ b/tests/phpunit/api/v3/GroupOrganizationTest.php @@ -138,9 +138,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { */ public function testGroupOrganizationGetWithWrongParams() { $params = 'groupOrg'; - $result = civicrm_api('group_organization', 'get', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'get', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -180,9 +178,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { $params = array( 'version' => $this->_apiversion, ); - $result = civicrm_api('group_organization', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); } @@ -191,9 +187,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { */ public function testGroupOrganizationCreateParamsNotArray() { $params = 'group_org'; - $result = civicrm_api('group_organization', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'create', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -205,9 +199,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { 'invalid_key' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('group_organization', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: group_id, organization_id'); } @@ -218,9 +210,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { */ public function testGroupOrganizationDeleteParamsNotArray() { $params = 'delete'; - $result = civicrm_api('group_organization', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'delete', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -231,9 +221,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { $params = array( 'version' => $this->_apiversion, ); - $result = civicrm_api('group_organization', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'delete', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } @@ -265,9 +253,7 @@ class api_v3_GroupOrganizationTest extends CiviUnitTestCase { 'invalid_key' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('group_organization', 'delete', $paramsDelete); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('group_organization', 'delete', $paramsDelete); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } } diff --git a/tests/phpunit/api/v3/GroupTest.php b/tests/phpunit/api/v3/GroupTest.php index dda96b59bf..7bc383ae6e 100644 --- a/tests/phpunit/api/v3/GroupTest.php +++ b/tests/phpunit/api/v3/GroupTest.php @@ -61,7 +61,7 @@ class api_v3_GroupTest extends CiviUnitTestCase { function testgroupCreateEmptyParams() { $params = array(); $group = civicrm_api('group', 'create', $params); - $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title'); + $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: title'); } function testgroupCreateNoTitle() { @@ -77,8 +77,8 @@ class api_v3_GroupTest extends CiviUnitTestCase { ), ); - $group = civicrm_api('group', 'create', $params); - $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title'); + $group = $this->callAPISuccess('group', 'create', $params); + $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: title'); } function testGetGroupEmptyParams() { @@ -158,19 +158,12 @@ class api_v3_GroupTest extends CiviUnitTestCase { $params = array('version' => $this->_apiversion); $params['title'] = 'No such group Exist'; $group = civicrm_api('group', 'get', $params); - $this->assertEquals(0, $group['is_error']); - } - - function testgroupdeleteNonArrayParams() { - $params = 'TestNotArray'; - $group = civicrm_api('group', 'delete', $params); - $this->assertEquals($group['error_message'], 'Input variable `params` is not an array'); + $this->assertEquals(0, $group['count']); } function testgroupdeleteParamsnoId() { - $params = array(); - $group = civicrm_api('group', 'delete', $params); - $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $group = $this->callAPIFailure('group', 'delete', array()); + $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: id'); } function testgetfields() { diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index 4619550c4b..e240a88e4d 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -63,9 +63,7 @@ class api_v3_JobTest extends CiviUnitTestCase { 'is_active' => 1, 'version' => $this->_apiVersion, ); - $result = civicrm_api('job', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('job', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action' ); @@ -86,8 +84,7 @@ class api_v3_JobTest extends CiviUnitTestCase { 'parameters' => 'Semi-formal explanation of runtime job parameters', 'is_active' => 1, ); - $result = civicrm_api('job', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('job', 'create', $params); } /** @@ -122,16 +119,14 @@ class api_v3_JobTest extends CiviUnitTestCase { */ function testDeleteEmpty() { $params = array(); - $result = civicrm_api('job', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('job', 'delete', $params); } /** * check with No array */ function testDeleteParamsNotArray() { - $result = civicrm_api('job', 'delete', 'string'); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('job', 'delete', 'string'); } /** @@ -144,9 +139,8 @@ class api_v3_JobTest extends CiviUnitTestCase { 'class_name' => 'CRM_Core_Payment_APITest', ); - $result = civicrm_api('job', 'delete', $params); - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $result = $this->callAPIFailure('job', 'delete', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } /** @@ -158,9 +152,7 @@ class api_v3_JobTest extends CiviUnitTestCase { 'version' => $this->_apiVersion, ); - $result = civicrm_api('job', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('job', 'delete', $params); $this->assertEquals($result['error_message'], 'Invalid value for job ID'); } diff --git a/tests/phpunit/api/v3/MailingContactTest.php b/tests/phpunit/api/v3/MailingContactTest.php index 91ca72b6b3..4b58a66b9f 100644 --- a/tests/phpunit/api/v3/MailingContactTest.php +++ b/tests/phpunit/api/v3/MailingContactTest.php @@ -75,8 +75,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { */ public function testMailingNullParams() { - $result = civicrm_api('MailingContact', 'get', null); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('MailingContact', 'get', null); } public function testMailingContactGetFields() { $result = civicrm_api('MailingContact', 'getfields', array( @@ -99,8 +98,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('MailingContact', 'get', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('MailingContact', 'get', $params); } /* @@ -112,8 +110,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('MailingContact', 'get', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('MailingContact', 'get', $params); } /* @@ -126,8 +123,7 @@ class api_v3_MailingContactTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('MailingContact', 'get', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('MailingContact', 'get', $params); } diff --git a/tests/phpunit/api/v3/MailingGroupTest.php b/tests/phpunit/api/v3/MailingGroupTest.php index 649f86e714..0750bf3906 100644 --- a/tests/phpunit/api/v3/MailingGroupTest.php +++ b/tests/phpunit/api/v3/MailingGroupTest.php @@ -70,8 +70,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { 'time_stamp' => '20111111010101', 'hash' => 'sasa', ); - $result = civicrm_api('mailing_event_subscribe', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params); if ($result['error_message'] != 'Subscription failed') { $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__); } @@ -123,8 +122,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { 'time_stamp' => '20101212121212', ); - $result = civicrm_api('mailing_event_unsubscribe', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__); } @@ -143,8 +141,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { 'time_stamp' => '20101212121212', ); - $result = civicrm_api('mailing_event_unsubscribe', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__); } @@ -167,8 +164,7 @@ class api_v3_MailingGroupTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'time_stamp' => '20101212121212', ); - $result = civicrm_api('mailing_event_resubscribe', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params); $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/MembershipStatusTest.php b/tests/phpunit/api/v3/MembershipStatusTest.php index e3be7f2d4e..d44b4bd104 100644 --- a/tests/phpunit/api/v3/MembershipStatusTest.php +++ b/tests/phpunit/api/v3/MembershipStatusTest.php @@ -68,9 +68,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { */ function testGetWrongParamsType() { $params = 'a string'; - $result = civicrm_api('membership_status', 'get', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('membership_status', 'get', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } @@ -123,14 +121,12 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { ///////////////// civicrm_membership_status_create methods function testCreateWithEmptyParams() { $params = array(); - $result = civicrm_api('membership_status', 'create', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'create', $params); } function testCreateWithWrongParamsType() { $params = 'a string'; - $result = civicrm_api('membership_status', 'create', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'create', $params); $params = array('version' =>3, 'id' => 'string'); $result = civicrm_api('membership_status', 'create', $params); } @@ -146,8 +142,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { function testCreateWithMissingRequired() { $params = array('title' => 'Does not make sense'); - $result = civicrm_api('membership_status', 'create', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'create', $params); } function testCreate() { @@ -237,20 +232,17 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { ///////////////// civicrm_membership_status_delete methods function testDeleteEmptyParams() { $params = array(); - $result = civicrm_api('membership_status', 'delete', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'delete', $params); } function testDeleteWrongParamsType() { $params = 'incorrect value'; - $result = civicrm_api('membership_status', 'delete', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'delete', $params); } function testDeleteWithMissingRequired() { $params = array('title' => 'Does not make sense'); - $result = civicrm_api('membership_status', 'delete', $params); - $this->assertAPIFailure($result, "In line " . __LINE__); + $result = $this->callAPIFailure('membership_status', 'delete', $params); } function testDelete() { @@ -288,8 +280,7 @@ class api_v3_MembershipStatusTest extends CiviUnitTestCase { 'id' => $membershipStatusID, 'version' => $this->_apiversion, ); - $result = civicrm_api('membership_status', 'delete', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('membership_status', 'delete', $params); civicrm_api('Membership', 'Delete', array( 'id' => $membershipID, diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 002346b0bd..c4096da953 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -99,14 +99,12 @@ class api_v3_MembershipTest extends CiviUnitTestCase { function testMembershipDeleteEmpty() { $params = array(); - $result = civicrm_api('membership', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('membership', 'delete', $params); } function testMembershipDeleteInvalidID() { $params = array('version' => $this->_apiversion, 'id' => 'blah'); - $result = civicrm_api('membership', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('membership', 'delete', $params); } /** @@ -410,8 +408,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { */ function testCreateWithEmptyParams() { $params = array(); - $result = civicrm_api('membership', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('membership', 'create', $params); } /** @@ -448,8 +445,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('membership', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('membership', 'create', $params); } function testMembershipCreate() { @@ -712,19 +708,16 @@ class api_v3_MembershipTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('membership', 'create', $params); - $this->assertAPIFailure($result, "in line " . __LINE__); + $result = $this->callAPIFailure('membership', 'create', $params); //membership_contact_id which is no in contact table $params['membership_contact_id'] = 999; - $result = civicrm_api('membership', 'create', $params); - $this->assertAPIFailure($result, "in line " . __LINE__); + $result = $this->callAPIFailure('membership', 'create', $params); //invalid join date unset($params['membership_contact_id']); $params['join_date'] = "invalid"; - $result = civicrm_api('Membership', 'Create', $params); - $this->assertAPIFailure($result, "in line " . __LINE__); + $result = $this->callAPIFailure('Membership', 'Create', $params); } /** diff --git a/tests/phpunit/api/v3/MembershipTypeTest.php b/tests/phpunit/api/v3/MembershipTypeTest.php index 9b6619c30a..2dd3e7dd3c 100644 --- a/tests/phpunit/api/v3/MembershipTypeTest.php +++ b/tests/phpunit/api/v3/MembershipTypeTest.php @@ -62,13 +62,6 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { ); } - function testGetWithEmptyParams() { - $params = array(); - $membershiptype = civicrm_api('membership_type', 'get', $params); - $this->assertEquals($membershiptype['is_error'], 1); - $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: version'); - } - function testGetWithoutId() { $params = array( 'name' => '60+ Membership', @@ -107,9 +100,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { ///////////////// civicrm_membership_type_create methods function testCreateWithEmptyParams() { - $params = array('version' => $this->_apiversion); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', array()); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name' ); @@ -137,8 +128,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: member_of_contact_id'); } @@ -155,8 +145,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'visibility' => 'public', 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: financial_type_id' ); @@ -175,8 +164,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: duration_unit' ); @@ -194,8 +182,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'visibility' => 'public', 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: financial_type_id, duration_interval' ); @@ -213,8 +200,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id, duration_unit, name' ); @@ -234,8 +220,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name'); } @@ -272,10 +257,9 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { function testUpdateWithEmptyParams() { $params = array(); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], - 'Mandatory key(s) missing from params array: version, domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name' + 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name' ); } @@ -293,8 +277,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'create', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id'); } @@ -336,9 +319,8 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { function testDeleteWithEmptyParams() { $params = array(); - $membershiptype = civicrm_api('membership_type', 'delete', $params); - $this->assertEquals($membershiptype['is_error'], 1); - $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params); + $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: id'); } function testDeleteNotExists() { @@ -346,8 +328,7 @@ class api_v3_MembershipTypeTest extends CiviUnitTestCase { 'id' => 'doesNotExist', 'version' => $this->_apiversion, ); - $membershiptype = civicrm_api('membership_type', 'delete', $params); - $this->assertEquals($membershiptype['is_error'], 1); + $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params); $this->assertEquals($membershiptype['error_message'], 'Error while deleting membership type. id : ' . $params['id']); } diff --git a/tests/phpunit/api/v3/NoteTest.php b/tests/phpunit/api/v3/NoteTest.php index 5d451a6f50..26c96bf3bf 100644 --- a/tests/phpunit/api/v3/NoteTest.php +++ b/tests/phpunit/api/v3/NoteTest.php @@ -100,9 +100,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { * Error expected */ function testGetWithEmptyParams() { - $params = array(); - $note = civicrm_api('note', 'get', $params); - $this->assertEquals($note['is_error'], 1); + $this->callAPISuccess('note', 'get', array()); } /** @@ -261,8 +259,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ function testUpdateWithEmptyParams() { $params = array(); - $note = civicrm_api('note', 'create', $params); - $this->assertEquals($note['is_error'], 1); + $note = $this->callAPIFailure('note', 'create', $params); } /** @@ -275,8 +272,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { 'entity_table' => 'civicrm_contact', 'version' => $this->_apiversion, ); - $note = civicrm_api('note', 'create', $params); - $this->assertEquals($note['is_error'], 1); + $note = $this->callAPIFailure('note', 'create', $params); $this->assertEquals($note['error_message'], 'Mandatory key(s) missing from params array: note'); } @@ -323,9 +319,8 @@ class api_v3_NoteTest extends CiviUnitTestCase { */ function testDeleteWithEmptyParams() { $params = array(); - $deleteNote = civicrm_api('note', 'delete', $params); - $this->assertEquals($deleteNote['is_error'], 1); - $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $deleteNote = $this->callAPIFailure('note', 'delete', $params); + $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: id'); } /** @@ -337,8 +332,7 @@ class api_v3_NoteTest extends CiviUnitTestCase { 'id' => 0, 'version' => $this->_apiversion, ); - $deleteNote = civicrm_api('note', 'delete', $params); - $this->assertEquals($deleteNote['is_error'], 1); + $deleteNote = $this->callAPIFailure('note', 'delete', $params); $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: id'); } diff --git a/tests/phpunit/api/v3/OptionGroupTest.php b/tests/phpunit/api/v3/OptionGroupTest.php index caa7528096..b998870b52 100644 --- a/tests/phpunit/api/v3/OptionGroupTest.php +++ b/tests/phpunit/api/v3/OptionGroupTest.php @@ -132,8 +132,7 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase { 'debug' => 0, ), ); - $result = civicrm_api('OptionGroup', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'Error should be passed up to top level In line ' . __LINE__); + $result = $this->callAPIFailure('OptionGroup', 'create', $params); $countAfter = civicrm_api('OptionGroup', 'getcount', array( 'version' => 3, 'options' => array('limit' => 5000), diff --git a/tests/phpunit/api/v3/ParticipantPaymentTest.php b/tests/phpunit/api/v3/ParticipantPaymentTest.php index 2ea76fb993..6a9a978873 100644 --- a/tests/phpunit/api/v3/ParticipantPaymentTest.php +++ b/tests/phpunit/api/v3/ParticipantPaymentTest.php @@ -104,8 +104,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentCreateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -113,8 +112,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentCreateEmptyParams() { $params = array(); - $result = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -127,8 +125,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $participantPayment = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals($participantPayment['is_error'], 1); + $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -162,9 +159,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentUpdateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant_payment', 'create', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant_payment', 'create', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } @@ -173,8 +168,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentUpdateEmpty() { $params = array(); - $participantPayment = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals($participantPayment['is_error'], 1); + $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -187,8 +181,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $participantPayment = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals($participantPayment['is_error'], 1); + $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -199,8 +192,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'participant_id' => $this->_participantID, 'version' => $this->_apiversion, ); - $participantPayment = civicrm_api('participant_payment', 'create', $params); - $this->assertEquals($participantPayment['is_error'], 1); + $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); } /** @@ -316,8 +308,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentDeleteWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant_payment', 'delete', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant_payment', 'delete', $params); } /** @@ -325,8 +316,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { */ function testPaymentDeleteWithEmptyParams() { $params = array('version' => $this->_apiversion); - $deletePayment = civicrm_api('participant_payment', 'delete', $params); - $this->assertEquals(1, $deletePayment['is_error']); + $deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params); $this->assertEquals('Mandatory key(s) missing from params array: id', $deletePayment['error_message']); } @@ -338,8 +328,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'id' => 0, 'version' => $this->_apiversion, ); - $deletePayment = civicrm_api('participant_payment', 'delete', $params); - $this->assertEquals($deletePayment['is_error'], 1); + $deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params); $this->assertEquals($deletePayment['error_message'], 'Mandatory key(s) missing from params array: id'); } @@ -374,15 +363,6 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->assertEquals($GetWrongParamsType['error_message'], 'Input variable `params` is not an array'); } - /** - * Test civicrm_participantPayment_get with empty params. - */ - public function testGetEmptyParams() { - $params = array(); - $GetEmptyParams = civicrm_api('participant_payment', 'get', $params); - $this->assertEquals($GetEmptyParams['error_message'], 'Mandatory key(s) missing from params array: version'); - } - /** * Test civicrm_participantPayment_get - success expected. */ diff --git a/tests/phpunit/api/v3/ParticipantTest.php b/tests/phpunit/api/v3/ParticipantTest.php index 8027e3da64..21fdbaf987 100644 --- a/tests/phpunit/api/v3/ParticipantTest.php +++ b/tests/phpunit/api/v3/ParticipantTest.php @@ -124,19 +124,14 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testGetWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant', 'get', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'get', $params); } /** * Test civicrm_participant_get with empty params */ function testGetEmptyParams() { - $params = array(); - $result = civicrm_api('participant', 'get', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $this->callAPISuccess('participant', 'get', array()); } /** @@ -289,9 +284,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testSearchWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant', 'get', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'get', $params); } /** @@ -377,9 +370,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testCreateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant', 'create', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'create', $params); } /** @@ -387,9 +378,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testCreateEmptyParams() { $params = array(); - $result = civicrm_api('participant', 'create', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'create', $params); } /** @@ -520,8 +509,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testUpdateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant', 'create', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'create', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } @@ -530,8 +518,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testUpdateEmptyParams() { $params = array('version' => $this->_apiversion); - $participant = civicrm_api('participant', 'create', $params); - $this->assertEquals($participant['is_error'], 1); + $participant = $this->callAPIFailure('participant', 'create', $params); $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id'); } @@ -549,8 +536,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'event_level' => 'Donation', 'version' => $this->_apiversion, ); - $participant = civicrm_api('participant', 'create', $params); - $this->assertEquals($participant['is_error'], 1); + $participant = $this->callAPIFailure('participant', 'create', $params); $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id'); // Cleanup created participant records. $result = $this->participantDelete($participantId); @@ -569,8 +555,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'event_level' => 'Donation', 'version' => $this->_apiversion, ); - $participant = civicrm_api('Participant', 'update', $params); - $this->assertEquals($participant['is_error'], 1); + $participant = $this->callAPIFailure('Participant', 'update', $params); } /** @@ -591,8 +576,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'event_level' => 'Donation', 'version' => $this->_apiversion, ); - $participant = civicrm_api('participant', 'create', $params); - $this->assertEquals($participant['is_error'], 1); + $participant = $this->callAPIFailure('participant', 'create', $params); $result = $this->participantDelete($participantId); } @@ -639,9 +623,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testDeleteWrongParamsType() { $params = 'a string'; - $result = civicrm_api('participant', 'delete', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'delete', $params); } /** @@ -649,9 +631,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { */ function testDeleteEmptyParams() { $params = array(); - $result = civicrm_api('participant', 'delete', $params); - - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('participant', 'delete', $params); } /** @@ -677,8 +657,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'event_id' => $this->_eventID, 'version' => $this->_apiversion, ); - $participant = civicrm_api('participant', 'delete', $params); - $this->assertEquals($participant['is_error'], 1); + $participant = $this->callAPIFailure('participant', 'delete', $params); $this->assertNotNull($participant['error_message']); } /* diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index 77b6611c2a..701a2e7955 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -88,9 +88,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { 'is_active' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('payment_processor', 'create', $payProcParams); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams); } /** diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index d86de47ab1..50d857e528 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -68,9 +68,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'is_active' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('payment_processor_type', 'create', $payProcParams); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor_type', 'create', $payProcParams); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode' ); @@ -119,16 +117,14 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { */ function testPaymentProcessorTypeDeleteEmpty() { $params = array(); - $result = civicrm_api('payment_processor_type', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); } /** * check with No array */ function testPaymentProcessorTypeDeleteParamsNotArray() { - $result = civicrm_api('payment_processor_type', 'delete', 'string'); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor_type', 'delete', 'string'); } /** @@ -141,10 +137,8 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'class_name' => 'CRM_Core_Payment_APITest', ); - $result = civicrm_api('payment_processor_type', 'delete', $params); - - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } /** @@ -156,9 +150,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('payment_processor_type', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID'); } @@ -185,19 +177,15 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { */ function testPaymentProcessorTypeUpdateEmpty() { $params = array(); - $result = civicrm_api('payment_processor_type', 'create', $params); - - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name, title, class_name, billing_mode'); + $result = $this->callAPIFailure('payment_processor_type', 'create', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode'); } /** * check with No array */ function testPaymentProcessorTypeUpdateParamsNotArray() { - $result = civicrm_api('payment_processor_type', 'create', 'string'); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('payment_processor_type', 'create', 'string'); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } diff --git a/tests/phpunit/api/v3/PhoneTest.php b/tests/phpunit/api/v3/PhoneTest.php index bd3878e9f1..3e22656c8a 100644 --- a/tests/phpunit/api/v3/PhoneTest.php +++ b/tests/phpunit/api/v3/PhoneTest.php @@ -154,8 +154,7 @@ class api_v3_PhoneTest extends CiviUnitTestCase { */ public function testCreateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('Phone', 'Create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $result = $this->callAPIFailure('Phone', 'Create', $params); } /** diff --git a/tests/phpunit/api/v3/PledgeTest.php b/tests/phpunit/api/v3/PledgeTest.php index 3b59cf66ec..ac96afe8bc 100644 --- a/tests/phpunit/api/v3/PledgeTest.php +++ b/tests/phpunit/api/v3/PledgeTest.php @@ -506,15 +506,13 @@ class api_v3_PledgeTest extends CiviUnitTestCase { function testDeleteEmptyParamsPledge() { $params = array('version' => $this->_apiversion); - $pledge = civicrm_api('pledge', 'delete', $params); - $this->assertEquals($pledge['is_error'], 1); + $pledge = $this->callAPIFailure('pledge', 'delete', $params); $this->assertEquals($pledge['error_message'], 'Mandatory key(s) missing from params array: id'); } function testDeleteParamsNotArrayPledge() { $params = 'pledge_id= 1'; - $pledge = civicrm_api('pledge', 'delete', $params); - $this->assertEquals($pledge['is_error'], 1); + $pledge = $this->callAPIFailure('pledge', 'delete', $params); $this->assertEquals($pledge['error_message'], 'Input variable `params` is not an array'); } @@ -523,8 +521,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { 'pledge_source' => 'SSF', 'version' => $this->_apiversion, ); - $pledge = civicrm_api('pledge', 'delete', $params); - $this->assertEquals($pledge['is_error'], 1); + $pledge = $this->callAPIFailure('pledge', 'delete', $params); $this->assertEquals($pledge['error_message'], 'Mandatory key(s) missing from params array: id'); } diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 9955920a67..5696d6e2d4 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -77,8 +77,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'contact_id' => 1, 'version' => 3, ); - $result = civicrm_api('profile', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'get', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); } @@ -91,8 +90,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'profile_id' => 1000, 'version' => 3, ); - $result = civicrm_api('profile', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'get', $params); } /** @@ -129,9 +127,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { list($params, $expected) = $this->_createContactWithActivity(); unset($params['activity_id']); - $result = civicrm_api('profile', 'get', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'get', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id'); } @@ -142,9 +138,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { list($params, $expected) = $this->_createContactWithActivity(); $params['activity_id'] = 100001; - $result = civicrm_api('profile', 'get', $params); - - $this->assertAPIFailure($result); + $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')); @@ -181,9 +175,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { list($params, $expected) = $this->_createContactWithActivity(); $params['activity_id'] = $activityValues['id']; - $result = civicrm_api('profile', 'get', $params); - - $this->assertAPIFailure($result); + $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')); @@ -215,8 +207,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { */ function testProfileSetNoArray() { $params = NULL; - $result = civicrm_api('profile', 'set', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'set', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -228,8 +219,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'contact_id' => 1, 'version' => 3, ); - $result = civicrm_api('profile', 'set', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'set', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); } @@ -242,8 +232,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'profile_id' => 1000, 'version' => 3, ); - $result = civicrm_api('profile', 'set', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'set', $params); } /** @@ -265,9 +254,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $updateParams ); - $result = civicrm_api('profile', 'set', $params); - - $this->assertAPIFailure($result); + $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')); @@ -325,9 +312,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array_merge($params, $expected); unset($params['activity_id']); - $result = civicrm_api('profile', 'set', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'set', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: activity_id'); $this->quickCleanup(array('civicrm_uf_field', 'civicrm_uf_join', 'civicrm_uf_group', 'civicrm_custom_field', 'civicrm_custom_group', 'civicrm_contact')); @@ -341,9 +326,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array_merge($params, $expected); $params['activity_id'] = 100001; - $result = civicrm_api('profile', 'set', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'set', $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')); @@ -381,9 +364,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array_merge($params, $expected); $params['activity_id'] = $activityValues['id']; - $result = civicrm_api('profile', 'set', $params); - - $this->assertAPIFailure($result); + $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')); @@ -438,8 +419,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'contact_id' => 1, 'version' => 3, ); - $result = civicrm_api('profile', 'apply', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'apply', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: profile_id'); } @@ -452,8 +432,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'profile_id' => 1000, 'version' => 3, ); - $result = civicrm_api('profile', 'apply', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('profile', 'apply', $params); } /** diff --git a/tests/phpunit/api/v3/RelationshipTest.php b/tests/phpunit/api/v3/RelationshipTest.php index 4b34a51d2c..19d74ffa02 100644 --- a/tests/phpunit/api/v3/RelationshipTest.php +++ b/tests/phpunit/api/v3/RelationshipTest.php @@ -95,8 +95,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ function testRelationshipCreateEmpty() { $params = array('version' => $this->_apiversion); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); } /** @@ -104,8 +103,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ function testRelationshipCreateParamsNotArray() { $params = 'relationship_type_id = 5'; - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); } /** @@ -118,8 +116,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'is_active' => 1, ); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); } /** @@ -134,8 +131,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'version' => 3, ); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); //contact id is not an integer $params = array( @@ -145,19 +141,16 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'start_date' => array('d' => '10', 'M' => '1', 'Y' => '2008'), 'is_active' => 1, ); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); //contact id does not exists $params['contact_id_a'] = 999; - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); //invalid date $params['contact_id_a'] = $this->_cId_a; $params['start_date'] = array('d' => '1', 'M' => '1'); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); } /** @@ -174,8 +167,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'version' => 3, ); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); // both the contact of type Organization $params = array( @@ -187,8 +179,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'version' => 3, ); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $this->callAPIFailure('relationship', 'create', $params); } /** @@ -211,11 +202,8 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'relationship_type_id' => $this->_relTypeID, 'start_date' => '2008-12-20', 'is_active' => 1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship', 'create', $params); $this->assertEquals($result['error_message'], 'Relationship already exists'); $params['id'] = $relationship['id']; @@ -537,21 +525,10 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { */ function testRelationshipDeleteEmpty() { $params = array('version' => $this->_apiversion); - $result = civicrm_api('relationship', 'delete', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship', 'delete', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } - /** - * check with No array - */ - function testRelationshipDeleteParamsNotArray() { - $params = 'relationship_type_id = 5'; - $result = civicrm_api('relationship', 'delete', $params); - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); - } - /** * check if required fields are not passed */ @@ -562,9 +539,8 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'is_active' => 1, ); - $result = civicrm_api('relationship', 'delete', $params); - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $result = $this->callAPIFailure('relationship', 'delete', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } /** @@ -578,13 +554,11 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship', 'delete', $params); - $this->assertAPIFailure($result, 'in line ' . __LINE__); + $result = $this->callAPIFailure('relationship', 'delete', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id', 'in line ' . __LINE__); $params['id'] = "Invalid"; - $result = civicrm_api('relationship', 'delete', $params); - $this->assertAPIFailure($result, 'in line ' . __LINE__); + $result = $this->callAPIFailure('relationship', 'delete', $params); $this->assertEquals($result['error_message'], 'Invalid value for relationship ID', 'in line ' . __LINE__); } @@ -619,22 +593,10 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { * check with empty array */ function testRelationshipUpdateEmpty() { - $params = array('version' => 3); - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship', 'create', array()); $this->assertEquals('Mandatory key(s) missing from params array: contact_id_a, contact_id_b, relationship_type_id', $result['error_message'], 'In line ' . __LINE__); } - /** - * check with No array - */ - function testRelationshipUpdateParamsNotArray() { - $params = 'relationship_type_id = 5'; - $result = civicrm_api('relationship', 'create', $params); - $this->assertAPIFailure($result); - $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); - } - /** * check if required fields are not passed */ @@ -667,9 +629,7 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship', 'create', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('relationship', 'create', $params); $this->assertEquals($result['error_message'], 'Relationship already exists', 'In line ' . __LINE__); //delete created relationship @@ -901,11 +861,9 @@ class api_v3_RelationshipTest extends CiviUnitTestCase { 'name_b_a' => 'Relation 2 for delete', 'contact_type_a' => 'Individual', 'contact_type_b' => 'Organization', - 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship_type', 'create', $relTypeParams); - $this->assertAPIFailure($result, 'in line ' . __LINE__); - $this->assertEquals($result['error_message'], 'Invalid value for relationship type ID', 'in line ' . __LINE__); + $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); + $this->assertEquals('id is not a valid integer', $result['error_message'], 'in line ' . __LINE__); } ///////////////// civicrm_get_relationships diff --git a/tests/phpunit/api/v3/RelationshipTypeTest.php b/tests/phpunit/api/v3/RelationshipTypeTest.php index 79adf832cd..17be464f81 100644 --- a/tests/phpunit/api/v3/RelationshipTypeTest.php +++ b/tests/phpunit/api/v3/RelationshipTypeTest.php @@ -100,9 +100,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'contact_type_b' => 'Organization', 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship_type', 'create', $relTypeParams); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a' ); @@ -117,9 +115,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'name_b_a' => 'Relation 2 without contact type', 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship_type', 'create', $relTypeParams); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'create', $relTypeParams); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: contact_type_a, contact_type_b' ); @@ -165,9 +161,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ function testRelationshipTypeDeleteEmpty() { $params = array(); - $result = civicrm_api('relationship_type', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'delete', $params); } /** @@ -175,9 +169,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ function testRelationshipTypeDeleteParamsNotArray() { $params = 'name_a_b = Test1'; - $result = civicrm_api('relationship_type', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'delete', $params); } /** @@ -191,10 +183,8 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'is_active' => 0, ); - $result = civicrm_api('relationship_type', 'delete', $params); - - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); + $result = $this->callAPIFailure('relationship_type', 'delete', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id'); } /** @@ -212,9 +202,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = civicrm_api('relationship_type', 'delete', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'delete', $params); $this->assertEquals($result['error_message'], 'Invalid value for relationship type ID'); } @@ -240,10 +228,8 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ function testRelationshipTypeUpdateEmpty() { $params = array(); - $result = civicrm_api('relationship_type', 'create', $params); - - $this->assertAPIFailure($result); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name_a_b, name_b_a, contact_type_a, contact_type_b'); + $result = $this->callAPIFailure('relationship_type', 'create', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name_a_b, name_b_a, contact_type_a, contact_type_b'); } /** @@ -251,9 +237,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ function testRelationshipTypeUpdateParamsNotArray() { $params = 'name_a_b = Relation 1'; - $result = civicrm_api('relationship_type', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('relationship_type', 'create', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -350,8 +334,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { */ function testRelationshipTypesGetParamsNotArray() { - $results = civicrm_api('relationship_type', 'get', 'string'); - $this->assertEquals(1, $results['is_error']); + $results = $this->callAPIFailure('relationship_type', 'get', 'string'); } /** diff --git a/tests/phpunit/api/v3/SettingTest.php b/tests/phpunit/api/v3/SettingTest.php index dc78e6d63d..affbec27e5 100644 --- a/tests/phpunit/api/v3/SettingTest.php +++ b/tests/phpunit/api/v3/SettingTest.php @@ -170,8 +170,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { 'domain_id' => $this->_domainID2, 'invalid_key' => 1, ); - $result = civicrm_api('setting', 'create', $params); - $this->assertEquals(1, $result['is_error']); + $result = $this->callAPIFailure('setting', 'create', $params); } /** @@ -184,8 +183,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'dfhkdhfd', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertEquals(1, $result['is_error']); + $result = $this->callAPIFailure('setting', 'create', $params); $params = array('version' => $this->_apiversion, 'domain_id' => $this->_domainID2, 'userFrameworkResourceURL' => 'http://blah.com', @@ -204,8 +202,7 @@ class api_v3_SettingTest extends CiviUnitTestCase { 'domain_id' => $this->_domainID2, 'track_civimail_replies' => 'dfhkdhfd', ); - $result = civicrm_api('setting', 'create', $params); - $this->assertEquals(1, $result['is_error']); + $result = $this->callAPIFailure('setting', 'create', $params); $params = array('version' => $this->_apiversion, 'track_civimail_replies' => '0', diff --git a/tests/phpunit/api/v3/SurveyRespondantTest.php b/tests/phpunit/api/v3/SurveyRespondantTest.php index 7d1bceed1a..6e591007ba 100644 --- a/tests/phpunit/api/v3/SurveyRespondantTest.php +++ b/tests/phpunit/api/v3/SurveyRespondantTest.php @@ -63,14 +63,6 @@ class api_v3_SurveyRespondantTest extends CiviUnitTestCase { $this->assertEquals($GetWrongParamsType['error_message'], 'Input variable `params` is not an array'); } - /** - * Test surveyRespondent get with empty params. - */ - public function testGetEmptyParams() { - $params = array(); - $GetEmptyParams = civicrm_api("SurveyRespondant","get", $params ); - $this->assertEquals($GetEmptyParams['error_message'], 'Mandatory key(s) missing from params array: version'); - } /** * Test survey respondent get. */ diff --git a/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php b/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php index 2279065019..cac59c7e5c 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceAllEntitiesTest.php @@ -366,8 +366,7 @@ class api_v3_SyntaxConformanceAllEntitiesTest extends CiviUnitTestCase { // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented"); return; } - $result = civicrm_api($Entity, 'Get', 'string'); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure($Entity, 'Get', 'string'); $this->assertEquals(2000, $result['error_code']); $this->assertEquals('Input variable `params` is not an array', $result['error_message']); } diff --git a/tests/phpunit/api/v3/TagTest.php b/tests/phpunit/api/v3/TagTest.php index 134eaab63d..bb39de24f9 100644 --- a/tests/phpunit/api/v3/TagTest.php +++ b/tests/phpunit/api/v3/TagTest.php @@ -52,21 +52,10 @@ class api_v3_TagTest extends CiviUnitTestCase { */ public function testGetWrongParamsType() { $params = 'is_string'; - $result = civicrm_api('tag', 'get', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('tag', 'get', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } - /** - * Test civicrm_tag_get with empty params. - */ - public function testGetEmptyParams() { - $params = array(); - $result = civicrm_api('tag', 'get', $params); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); - $this->assertEquals('Mandatory key(s) missing from params array: version', $result['error_message'], 'In line ' . __LINE__); - } - /** * Test civicrm_tag_get with wrong params. */ @@ -125,8 +114,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ function testCreateWrongParamsType() { $params = 'a string'; - $result = civicrm_api('tag', 'create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $result = $this->callAPIFailure('tag', 'create', $params); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } @@ -135,8 +123,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ function testCreateEmptyParams() { $params = array('version' => $this->_apiversion); - $result = civicrm_api('tag', 'create', $params); - $this->assertEquals(1, $result['is_error'], "In line " . __LINE__); + $result = $this->callAPIFailure('tag', 'create', $params); $this->assertEquals('Mandatory key(s) missing from params array: name', $result['error_message'], 'In line ' . __LINE__); } @@ -202,8 +189,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ function testDeleteWrongParamsType() { $tag = 'is string'; - $result = civicrm_api('tag', 'delete', $tag); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('tag', 'delete', $tag); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } @@ -212,8 +198,7 @@ class api_v3_TagTest extends CiviUnitTestCase { */ function testDeleteEmptyParams() { $tag = array('version' => $this->_apiversion); - $result = civicrm_api('tag', 'delete', $tag); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('tag', 'delete', $tag); $this->assertEquals('Mandatory key(s) missing from params array: id', $result['error_message'], 'In line ' . __LINE__); } @@ -223,8 +208,7 @@ class api_v3_TagTest extends CiviUnitTestCase { function testDeleteWithoutTagId() { $tag = array('version' => 3); - $result = civicrm_api('tag', 'delete', $tag); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('tag', 'delete', $tag); $this->assertEquals('Mandatory key(s) missing from params array: id', $result['error_message'], 'In line ' . __LINE__); } @@ -232,8 +216,7 @@ class api_v3_TagTest extends CiviUnitTestCase { * Test civicrm_tag_delete with wrong tag id type. */ function testDeleteWrongParams() { - $result = civicrm_api('tag', 'delete', 'tyttyd'); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('tag', 'delete', 'tyttyd'); $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/UFJoinTest.php b/tests/phpunit/api/v3/UFJoinTest.php index 2b9898fefa..9d81255ca7 100644 --- a/tests/phpunit/api/v3/UFJoinTest.php +++ b/tests/phpunit/api/v3/UFJoinTest.php @@ -154,18 +154,14 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { public function testUFJoinEditWrongParamsType() { $params = 'a string'; - $result = civicrm_api('uf_join', 'create', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } public function testUFJoinEditEmptyParams() { $params = array(); - $result = civicrm_api('uf_join', 'create', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__); + $result = $this->callAPIFailure('uf_join', 'create', $params); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__); } public function testUFJoinEditWithoutUFGroupId() { @@ -177,8 +173,7 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'is_active' => 1, 'version' => $this->_apiversion, ); - $result = civicrm_api('uf_join', 'create', $params); - $this->assertAPIFailure($result, 'In line ' . __LINE__); + $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__); } @@ -222,18 +217,13 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { public function testFindUFJoinWrongParamsType() { $params = 'a string'; - $result = civicrm_api('uf_join', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); } public function testFindUFJoinEmptyParams() { - $params = array(); - $result = civicrm_api('uf_join', 'create', $params); - - $this->assertAPIFailure($result, 'In line ' . __LINE__); - $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, module, weight, uf_group_id', 'In line ' . __LINE__); + $result = $this->callAPIFailure('uf_join', 'create', array()); + $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__); } public function testFindUFJoinWithoutUFGroupId() { @@ -243,11 +233,8 @@ class api_v3_UFJoinTest extends CiviUnitTestCase { 'entity_id' => 1, 'weight' => 1, 'is_active' => 1, - 'version' => $this->_apiversion, ); - $result = civicrm_api('uf_join', 'create', $params); - - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_join', 'create', $params); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/UFMatchTest.php b/tests/phpunit/api/v3/UFMatchTest.php index 29d71ec55d..dc1f7919aa 100644 --- a/tests/phpunit/api/v3/UFMatchTest.php +++ b/tests/phpunit/api/v3/UFMatchTest.php @@ -103,8 +103,7 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { function testGetUFMatchIDWrongParam() { $params = 'a string'; - $result = civicrm_api('uf_match', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_match', 'get', $params); } /** @@ -123,8 +122,7 @@ class api_v3_UFMatchTest extends CiviUnitTestCase { function testGetUFIDWrongParam() { $params = 'a string'; - $result = civicrm_api('uf_match', 'get', $params); - $this->assertAPIFailure($result); + $result = $this->callAPIFailure('uf_match', 'get', $params); } /** -- 2.25.1