From fa7b9efbc4c752e9e2daabad04421badb3fa734d Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 26 Jul 2013 02:53:21 +1200 Subject: [PATCH] CRM-13072 upgrade PaymentProcessTypeTest & PaymentProcessorTest to pass post update to delete validation --- tests/phpunit/api/v3/PaymentProcessorTest.php | 29 ++------ .../api/v3/PaymentProcessorTypeTest.php | 73 +++++-------------- 2 files changed, 26 insertions(+), 76 deletions(-) diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index 701a2e7955..f3b21bb824 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -1,5 +1,4 @@ _apiversion = 3; // Create dummy processor $params = array( - 'version' => $this->_apiversion, 'name' => 'API_Test_PP_Type', 'title' => 'API Test Payment Processor Type', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 'form', 'is_recur' => 0, ); - $result = civicrm_api('payment_processor_type', 'create', $params); + $result = $this->callAPISuccess('payment_processor_type', 'create', $params); $this->_paymentProcessorType = $result['id']; $this->_params = array( - 'version' => $this->_apiversion, 'name' => 'API Test PP', 'payment_processor_type_id' => $this->_paymentProcessorType, 'class_name' => 'CRM_Core_Payment_APITest', @@ -86,7 +82,6 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { function testPaymentProcessorCreateWithoutName() { $payProcParams = array( 'is_active' => 1, - 'version' => $this->_apiversion, ); $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams); } @@ -96,13 +91,9 @@ 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__); + $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id'], 'in line ' . __LINE__); - // mutate $params to match expected return value - unset($params['version']); //assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); return $result['id']; @@ -121,19 +112,15 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { ///////////////// civicrm_payment_processor_delete methods /** - * check payment processor type delete + * check payment processor delete */ function testPaymentProcessorDelete() { $id = $this->testPaymentProcessorCreate(); - // create sample payment processor type. $params = array( 'id' => $id, - 'version' => $this->_apiversion, ); - $result = civicrm_api('payment_processor', 'delete', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result); + $result = $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); } ///////////////// civicrm_payment_processors_get methods @@ -144,15 +131,13 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { function testPaymentProcessorsGet() { $params = $this->_params; $params['user_name'] = 'test@test.com'; - civicrm_api('payment_processor', 'create', $params); + $this->callAPISuccess('payment_processor', 'create', $params); $params = array( 'user_name' => 'test@test.com', - 'version' => $this->_apiversion, ); - $results = civicrm_api('payment_processor', 'get', $params); + $results = $this->callAPISuccess('payment_processor', 'get', $params); - $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__); $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__); } diff --git a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php index 50d857e528..0b11710a9f 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -1,5 +1,4 @@ 1, - 'version' => $this->_apiversion, - ); + 'is_active' => 1, ); $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' @@ -78,22 +75,17 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * create payment processor type */ function testPaymentProcessorTypeCreate() { - $params = array( - 'version' => $this->_apiversion, - 'sequential' => 1, + $params = array( 'sequential' => 1, 'name' => 'API_Test_PP', 'title' => 'API Test Payment Processor', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 'form', 'is_recur' => 0, ); - $result = civicrm_api('payment_processor_type', 'create', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result); + $result = $this->callAPIAndDocument('payment_processor_type', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); // mutate $params to match expected return value - unset($params['version']); unset($params['sequential']); $params['billing_mode'] = CRM_Core_Payment::BILLING_MODE_FORM; //assertDBState compares expected values in $result to actual values in the DB @@ -145,13 +137,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * check with incorrect required fields */ function testPaymentProcessorTypeDeleteWithIncorrectData() { - $params = array( - 'id' => 'abcd', - 'version' => $this->_apiversion, - ); - - $result = $this->callAPIFailure('payment_processor_type', 'delete', $params); - $this->assertEquals($result['error_message'], 'Invalid value for payment processor type ID'); + $result = $this->callAPIFailure('payment_processor_type', 'delete', array('id' => 'abcd')); } /** @@ -159,15 +145,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { */ function testPaymentProcessorTypeDelete() { $payProcType = $this->paymentProcessorTypeCreate(); - // create sample payment processor type. $params = array( 'id' => $payProcType, - 'version' => $this->_apiversion, ); - $result = civicrm_api('payment_processor_type', 'delete', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result); + $result = $this->callAPIAndDocument('payment_processor_type', 'delete', $params, __FUNCTION__, __FILE__); } ///////////////// civicrm_payment_processor_type_update @@ -202,13 +184,10 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'title' => 'API Test Payment Processor 2', 'class_name' => 'CRM_Core_Payment_APITest 2', 'billing_mode' => 2, - 'is_recur' => 0, - 'version' => $this->_apiversion, - ); + 'is_recur' => 0, ); - $result = civicrm_api('payment_processor_type', 'create', $params); + $result = $this->callAPISuccess('payment_processor_type', 'create', $params); $this->assertNotNull($result['id']); - unset($params['version']); // assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Financial_DAO_PaymentProcessorType', $this->_ppTypeID, $params); } @@ -219,9 +198,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { * check with empty array */ function testPaymentProcessorTypesGetEmptyParams() { - $results = civicrm_api('payment_processor_type', 'get', array( - 'version' => $this->_apiversion, - )); + $results = $this->callAPISuccess('payment_processor_type', 'get', array( )); $baselineCount = $results['count']; $firstRelTypeParams = array( @@ -229,24 +206,18 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'title' => 'API Test Payment Processor', 'class_name' => 'CRM_Core_Payment_APITest', 'billing_mode' => 1, - 'is_recur' => 0, - 'version' => $this->_apiversion, - ); + 'is_recur' => 0, ); - $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams); + $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); $secondRelTypeParams = array( 'name' => 'API_Test_PP2', 'title' => 'API Test Payment Processor 2', 'class_name' => 'CRM_Core_Payment_APITest 2', 'billing_mode' => 2, - 'is_recur' => 0, - 'version' => $this->_apiversion, - ); - $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams); - $result = civicrm_api('payment_processor_type', 'get', array( - 'version' => $this->_apiversion, - )); + 'is_recur' => 0, ); + $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); + $result = $this->callAPISuccess('payment_processor_type', 'get', array( )); $this->assertEquals($baselineCount + 2, $result['count']); $this->assertAPISuccess($result); @@ -261,27 +232,21 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'title' => 'API Test Payment Processor 11', 'class_name' => 'CRM_Core_Payment_APITest_11', 'billing_mode' => 1, - 'is_recur' => 0, - 'version' => $this->_apiversion, - ); + 'is_recur' => 0, ); - $first = civicrm_api('PaymentProcessorType', 'Create', $firstRelTypeParams); + $first = $this->callAPISuccess('PaymentProcessorType', 'Create', $firstRelTypeParams); $secondRelTypeParams = array( 'name' => 'API_Test_PP_12', 'title' => 'API Test Payment Processor 12', 'class_name' => 'CRM_Core_Payment_APITest_12', 'billing_mode' => 2, - 'is_recur' => 0, - 'version' => $this->_apiversion, - ); - $second = civicrm_api('PaymentProcessorType', 'Create', $secondRelTypeParams); + 'is_recur' => 0, ); + $second = $this->callAPISuccess('PaymentProcessorType', 'Create', $secondRelTypeParams); $params = array( - 'name' => 'API_Test_PP_12', - 'version' => $this->_apiversion, - ); - $result = civicrm_api('payment_processor_type', 'get', $params); + 'name' => 'API_Test_PP_12', ); + $result = $this->callAPISuccess('payment_processor_type', 'get', $params); $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], ' in line ' . __LINE__); -- 2.25.1