From 21150aaeff55a6f0be158f8ff591dc69ca43f636 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 7 Apr 2013 15:19:48 -0700 Subject: [PATCH] Add payment_processor api --- api/v3/PaymentProcessor.php | 88 ++++++++++ api/v3/examples/PaymentProcessorCreate.php | 81 +++++++++ api/v3/examples/PaymentProcessorDelete.php | 53 ++++++ tests/phpunit/api/v3/PaymentProcessorTest.php | 162 ++++++++++++++++++ .../api/v3/PaymentProcessorTypeTest.php | 7 +- tests/phpunit/api/v3/RelationshipTypeTest.php | 2 +- 6 files changed, 386 insertions(+), 7 deletions(-) create mode 100644 api/v3/PaymentProcessor.php create mode 100644 api/v3/examples/PaymentProcessorCreate.php create mode 100644 api/v3/examples/PaymentProcessorDelete.php create mode 100644 tests/phpunit/api/v3/PaymentProcessorTest.php diff --git a/api/v3/PaymentProcessor.php b/api/v3/PaymentProcessor.php new file mode 100644 index 0000000000..b3423d16b2 --- /dev/null +++ b/api/v3/PaymentProcessor.php @@ -0,0 +1,88 @@ + 3, + 'name' => 'API Test PP', + 'payment_processor_type_id' => 1, + 'class_name' => 'CRM_Core_Payment_APITest', + 'is_recur' => 0, + 'domain_id' => 1, +); + + $result = civicrm_api( 'payment_processor','create',$params ); + + return $result; +} + +/* + * Function returns array of result expected from previous function + */ +function payment_processor_create_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 1, + 'values' => array( + '1' => array( + 'id' => '1', + 'domain_id' => '1', + 'name' => 'API Test PP', + 'description' => '', + 'payment_processor_type_id' => '1', + 'is_active' => '', + 'is_default' => 0, + 'is_test' => 0, + 'user_name' => '', + 'password' => '', + 'signature' => '', + 'url_site' => '', + 'url_api' => '', + 'url_recur' => '', + 'url_button' => '', + 'subject' => '', + 'class_name' => 'CRM_Core_Payment_APITest', + 'billing_mode' => '1', + 'is_recur' => 0, + 'payment_type' => '1', + ), + ), +); + + return $expectedResult ; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testPaymentProcessorCreate and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/PaymentProcessorTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/api/v3/examples/PaymentProcessorDelete.php b/api/v3/examples/PaymentProcessorDelete.php new file mode 100644 index 0000000000..4156742071 --- /dev/null +++ b/api/v3/examples/PaymentProcessorDelete.php @@ -0,0 +1,53 @@ + 1, + 'version' => 3, +); + + $result = civicrm_api( 'payment_processor','delete',$params ); + + return $result; +} + +/* + * Function returns array of result expected from previous function + */ +function payment_processor_delete_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'values' => true, +); + + return $expectedResult ; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testPaymentProcessorDelete and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/PaymentProcessorTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ \ No newline at end of file diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php new file mode 100644 index 0000000000..7813b24a4e --- /dev/null +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -0,0 +1,162 @@ + 'PaymentProcessor Create', + 'description' => 'Test all PaymentProcessor Create API methods.', + 'group' => 'CiviCRM API Tests', + ); + } + + function setUp() { + parent::setUp(); + $this->_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); + $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', + 'is_recur' => 0, + 'domain_id' => 1, + ); + } + + function tearDown() { + + $tablesToTruncate = array( + 'civicrm_payment_processor', + 'civicrm_payment_processor_type', + ); + $this->quickCleanup($tablesToTruncate); + } + + ///////////////// civicrm_payment_processor_add methods + + /** + * check with no name + */ + function testPaymentProcessorCreateWithoutName() { + $payProcParams = array( + 'is_active' => 1, + 'version' => $this->_apiversion, + ); + $result = civicrm_api('payment_processor', 'create', $payProcParams); + + $this->assertEquals($result['is_error'], 1); + } + + /** + * create payment processor + */ + function testPaymentProcessorCreate() { + $params = $this->_params; + $result = civicrm_api('payment_processor', 'create', $params); + $this->documentMe($params, $result, __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']; + } + + /** + * Test using example code + */ + function testPaymentProcessorCreateExample() { + require_once 'api/v3/examples/PaymentProcessorCreate.php'; + $result = payment_processor_create_example(); + $expectedResult = payment_processor_create_expectedresult(); + $this->assertEquals($result['is_error'], 0); + } + + ///////////////// civicrm_payment_processor_delete methods + + /** + * check payment processor type 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->assertEquals($result['is_error'], 0); + } + + ///////////////// civicrm_payment_processors_get methods + + /** + * check with valid params array. + */ + function testPaymentProcessorsGet() { + $params = $this->_params; + $params['user_name'] = 'test@test.com'; + civicrm_api('payment_processor', 'create', $params); + + $params = array( + 'user_name' => 'test@test.com', + 'version' => $this->_apiversion, + ); + $results = civicrm_api('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 7cef998e47..ec5b480b3d 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTypeTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTypeTest.php @@ -34,8 +34,6 @@ require_once 'CiviTest/CiviUnitTestCase.php'; * */ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { - protected $_cId_a; - protected $_cId_b; protected $_ppTypeID; protected $_apiversion; public $_eNoticeCompliant = TRUE; @@ -51,14 +49,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { parent::setUp(); $this->_apiversion = 3; - $this->_cId_a = $this->individualCreate(NULL); - $this->_cId_b = $this->organizationCreate(NULL); } function tearDown() { $tablesToTruncate = array( - 'civicrm_contact', 'civicrm_payment_processor_type', ); $this->quickCleanup($tablesToTruncate); @@ -225,7 +220,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = &civicrm_api('payment_processor_type', 'create', $params); + $result = civicrm_api('payment_processor_type', 'create', $params); $this->assertNotNull($result['id']); unset($params['version']); // assertDBState compares expected values in $result to actual values in the DB diff --git a/tests/phpunit/api/v3/RelationshipTypeTest.php b/tests/phpunit/api/v3/RelationshipTypeTest.php index b33b8d8224..eb95ad6c21 100644 --- a/tests/phpunit/api/v3/RelationshipTypeTest.php +++ b/tests/phpunit/api/v3/RelationshipTypeTest.php @@ -275,7 +275,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase { 'version' => $this->_apiversion, ); - $result = &civicrm_api('relationship_type', 'create', $params); + $result = civicrm_api('relationship_type', 'create', $params); $this->assertNotNull($result['id']); unset($params['version']); // assertDBState compares expected values in $result to actual values in the DB -- 2.25.1