From 48ab68c7b74b17169224e2442f65a826202ba316 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 10 Jun 2013 19:59:43 +1200 Subject: [PATCH] tidy up paymentProcessor test to use apiSuccess & failure assertions. remove failure test which is in syntaxconformance --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 7 +-- tests/phpunit/api/v3/PaymentProcessorTest.php | 1 + .../api/v3/PaymentProcessorTypeTest.php | 43 ++++++++----------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8c48912089..51ab302fb2 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -908,12 +908,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { $params['version'] = API_LATEST_VERSION; $result = civicrm_api('payment_processor_type', 'create', $params); - - if (civicrm_error($params) || CRM_Utils_Array::value('is_error', $result)) { - throw new Exception('Could not create payment processor type'); - } - - require_once 'CRM/Core/PseudoConstant.php'; + $this->assertAPISuccess($result); CRM_Core_PseudoConstant::flush('paymentProcessorType'); return $result['id']; diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index dac56b5eb4..4f79205213 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -99,6 +99,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { function testPaymentProcessorCreate() { $params = $this->_params; $result = civicrm_api('payment_processor', 'create', $params); + $this->assertAPISuccess($result); $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertNotNull($result['id'], 'in line ' . __LINE__); diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index fe1dc41378..d86de47ab1 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -70,7 +70,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { ); $result = civicrm_api('payment_processor_type', 'create', $payProcParams); - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: name, title, class_name, billing_mode' ); @@ -91,6 +91,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { ); $result = civicrm_api('payment_processor_type', 'create', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); + $this->assertAPISuccess($result); $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); // mutate $params to match expected return value @@ -108,7 +109,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { require_once 'api/v3/examples/PaymentProcessorTypeCreate.php'; $result = payment_processor_type_create_example(); $expectedResult = payment_processor_type_create_expectedresult(); - $this->assertEquals($result['is_error'], 0); + $this->assertAPISuccess($result); } ///////////////// civicrm_payment_processor_type_delete methods @@ -119,8 +120,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { function testPaymentProcessorTypeDeleteEmpty() { $params = array(); $result = civicrm_api('payment_processor_type', 'delete', $params); - - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); } /** @@ -128,8 +128,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { */ function testPaymentProcessorTypeDeleteParamsNotArray() { $result = civicrm_api('payment_processor_type', 'delete', 'string'); - - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); } /** @@ -144,7 +143,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { $result = civicrm_api('payment_processor_type', 'delete', $params); - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); } @@ -159,7 +158,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { $result = civicrm_api('payment_processor_type', 'delete', $params); - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID'); } @@ -176,7 +175,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { $result = civicrm_api('payment_processor_type', 'delete', $params); $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertEquals($result['is_error'], 0); + $this->assertAPISuccess($result); } ///////////////// civicrm_payment_processor_type_update @@ -188,7 +187,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { $params = array(); $result = civicrm_api('payment_processor_type', 'create', $params); - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, name, title, class_name, billing_mode'); } @@ -198,7 +197,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { function testPaymentProcessorTypeUpdateParamsNotArray() { $result = civicrm_api('payment_processor_type', 'create', 'string'); - $this->assertEquals($result['is_error'], 1); + $this->assertAPIFailure($result); $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); } @@ -257,20 +256,12 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams); - $results = civicrm_api('payment_processor_type', 'get', array( + $result = civicrm_api('payment_processor_type', 'get', array( 'version' => $this->_apiversion, )); - $this->assertEquals($baselineCount + 2, $results['count']); - $this->assertEquals(0, $results['is_error']); - } - - /** - * check with params Not Array. - */ - function testPaymentProcessorTypesGetParamsNotArray() { - $results = civicrm_api('payment_processor_type', 'get', 'string'); - $this->assertEquals(1, $results['is_error']); + $this->assertEquals($baselineCount + 2, $result['count']); + $this->assertAPISuccess($result); } /** @@ -302,11 +293,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'name' => 'API_Test_PP_12', 'version' => $this->_apiversion, ); - $results = civicrm_api('payment_processor_type', 'get', $params); + $result = civicrm_api('payment_processor_type', 'get', $params); - $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__); - $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); - $this->assertEquals('CRM_Core_Payment_APITest_12', $results['values'][$results['id']]['class_name'], ' in line ' . __LINE__); + $this->assertAPISuccess($result); + $this->assertEquals(1, $result['count'], ' in line ' . __LINE__); + $this->assertEquals('CRM_Core_Payment_APITest_12', $result['values'][$result['id']]['class_name'], ' in line ' . __LINE__); } } -- 2.25.1