From: eileenmcnaugton Date: Sun, 18 Oct 2015 07:52:57 +0000 (+1300) Subject: minor test classes idy-up. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=78ab0ca450cd38a4cdce1eb3eb35f6174c31936d;p=civicrm-core.git minor test classes idy-up. We have been moving from the create helper classes taking a range of parameters to them taking an array which is merged with the defaults the functions provide in order to create the entity --- diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index 6847f4924c..c93236bd0d 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -36,12 +36,15 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { } /** - * Check method create() + * Check method create(). */ public function testCreate() { $contactId = $this->individualCreate(); $financialTypeId = 1; - $this->contributionCreate(array('contact_id' => $contactId), $financialTypeId); + $this->contributionCreate(array( + 'contact_id' => $contactId, + 'financial_type_id' => $financialTypeId, + )); $params = array( 'contribution_id' => $financialTypeId, 'to_financial_account_id' => 1, diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 4e9605dbb8..184e3cafe2 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -1636,17 +1636,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * * @param array $params * Array of parameters. - * @param int $cTypeID - * Id of financial type. - * @param int $invoiceID - * @param int $trxnID - * @param int $paymentInstrumentID * * @return int * id of created contribution */ - public function contributionCreate($params, $cTypeID = 1, $invoiceID = 67890, $trxnID = 12345, - $paymentInstrumentID = 1) { + public function contributionCreate($params) { $params = array_merge(array( 'domain_id' => 1, @@ -1654,11 +1648,11 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { 'total_amount' => 100.00, 'fee_amount' => 5.00, 'net_ammount' => 95.00, - 'financial_type_id' => $cTypeID, - 'payment_instrument_id' => empty($paymentInstrumentID) ? 1 : $paymentInstrumentID, + 'financial_type_id' => 1, + 'payment_instrument_id' => 1, 'non_deductible_amount' => 10.00, - 'trxn_id' => $trxnID, - 'invoice_id' => $invoiceID, + 'trxn_id' => 12345, + 'invoice_id' => 67890, 'source' => 'SSF', 'contribution_status_id' => 1, ), $params); @@ -1667,35 +1661,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { return $result['id']; } - /** - * Create online contribution. - * - * @param array $params - * @param int $financialType - * Id of financial type. - * @param int $invoiceID - * @param int $trxnID - * - * @return int - * id of created contribution - */ - public function onlineContributionCreate($params, $financialType, $invoiceID = 67890, $trxnID = 12345) { - $contribParams = array( - 'contact_id' => $params['contact_id'], - 'receive_date' => date('Ymd'), - 'total_amount' => 100.00, - 'financial_type_id' => $financialType, - 'contribution_page_id' => $params['contribution_page_id'], - 'trxn_id' => 12345, - 'invoice_id' => 67890, - 'source' => 'SSF', - ); - $contribParams = array_merge($contribParams, $params); - $result = $this->callAPISuccess('contribution', 'create', $contribParams); - - return $result['id']; - } - /** * Delete contribution. * @@ -3231,8 +3196,11 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) //create a contribution so our membership & contribution don't both have id = 1 $this->contributionCreate(array( 'contact_id' => $this->_contactID, - 'is_test' => 1), - 1, 'abcd', '345j'); + 'is_test' => 1, + 'financial_type_id' => 1, + 'invoice_id' => 'abcd', + 'trxn_id' => 345, + )); $this->setupRecurringPaymentProcessorTransaction(); $this->ids['membership'] = $this->callAPISuccess('membership', 'create', array( diff --git a/tests/phpunit/api/v3/ContributionSoftTest.php b/tests/phpunit/api/v3/ContributionSoftTest.php index a317348f7f..d9431dd0ac 100644 --- a/tests/phpunit/api/v3/ContributionSoftTest.php +++ b/tests/phpunit/api/v3/ContributionSoftTest.php @@ -36,11 +36,25 @@ require_once 'CiviTest/CiviUnitTestCase.php'; class api_v3_ContributionSoftTest extends CiviUnitTestCase { /** - * Assume empty database with just civicrm_data. + * The hard credit contact. + * + * @var int + */ + protected $_individualId; + + /** + * The first soft credit contact. + * + * @var int */ - protected $_individualId; //the hard credit contact - protected $_softIndividual1Id; //the first soft credit contact - protected $_softIndividual2Id; //the second soft credit contact + protected $_softIndividual1Id; + + /** + * The second soft credit contact. + * + * @var int + */ + protected $_softIndividual2Id; protected $_contributionId; protected $_financialTypeId = 1; protected $_apiversion = 3; @@ -85,6 +99,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase { /** * Test get methods. + * * @todo - this might be better broken down into more smaller tests */ public function testGetContributionSoft() { diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 497703f6e5..7f27b9e07c 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -1150,15 +1150,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase { */ public function testCreateUpdateContribution() { - $contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId), $this->_financialTypeId, - 'idofsh', 212355); + $contributionID = $this->contributionCreate(array( + 'contact_id' => $this->_individualId, + 'trxn_id' => 212355, + 'financial_type_id' => $this->_financialTypeId, + 'invoice_id' => 'old_invoice', + )); $old_params = array( 'contribution_id' => $contributionID, - ); $original = $this->callAPISuccess('contribution', 'get', $old_params); - // Make sure it came back. - $this->assertAPISuccess($original); $this->assertEquals($original['id'], $contributionID); //set up list of old params, verify @@ -1176,7 +1177,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($old_fee_amount, 5.00); $this->assertEquals($old_source, 'SSF'); $this->assertEquals($old_trxn_id, 212355); - $this->assertEquals($old_invoice_id, 'idofsh'); + $this->assertEquals($old_invoice_id, 'old_invoice'); $params = array( 'id' => $contributionID, 'contact_id' => $this->_individualId, @@ -1241,8 +1242,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } public function testDeleteContribution() { - - $contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId), $this->_financialTypeId, 'dfsdf', 12389); + $contributionID = $this->contributionCreate(array( + 'contact_id' => $this->_individualId, + 'financial_type_id' => $this->_financialTypeId, + )); $params = array( 'id' => $contributionID, ); diff --git a/tests/phpunit/api/v3/ParticipantPaymentTest.php b/tests/phpunit/api/v3/ParticipantPaymentTest.php index 22ab4a8560..a07f8b474d 100644 --- a/tests/phpunit/api/v3/ParticipantPaymentTest.php +++ b/tests/phpunit/api/v3/ParticipantPaymentTest.php @@ -44,6 +44,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { protected $_participantPaymentID; protected $_financialTypeId; + /** + * Set up for tests. + */ public function setUp() { parent::setUp(); $this->useTransaction(TRUE); @@ -206,8 +209,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'contact_id' => $this->_contactID, 'contribution_page_id' => $contributionPage['id'], 'payment_processor' => $paymentProcessor->id, + 'financial_type_id' => 1, ); - $contributionID = $this->onlineContributionCreate($contributionParams, 1); + $contributionID = $this->contributionCreate($contributionParams); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); $params = array( @@ -225,7 +229,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $params = array( 'id' => $this->_participantPaymentID, ); - $deletePayment = $this->callAPISuccess('participant_payment', 'delete', $params); + $this->callAPISuccess('participant_payment', 'delete', $params); } /** @@ -242,8 +246,9 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'contribution_page_id' => $contributionPage['id'], 'contribution_status_id' => 2, 'is_pay_later' => 1, + 'financial_type_id' => 1, ); - $contributionID = $this->onlineContributionCreate($contributionParams, 1); + $contributionID = $this->contributionCreate($contributionParams); $this->_participantPaymentID = $this->participantPaymentCreate($this->_participantID, $contributionID); $params = array( @@ -261,7 +266,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $params = array( 'id' => $this->_participantPaymentID, ); - $deletePayment = $this->callAPISuccess('participant_payment', 'delete', $params); + $this->callAPISuccess('participant_payment', 'delete', $params); } diff --git a/tests/phpunit/api/v3/PledgePaymentTest.php b/tests/phpunit/api/v3/PledgePaymentTest.php index fcf7c5a8ab..46c6c299bc 100644 --- a/tests/phpunit/api/v3/PledgePaymentTest.php +++ b/tests/phpunit/api/v3/PledgePaymentTest.php @@ -214,8 +214,12 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { 'sequential' => 1, ); - $contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId), $this->_financialTypeId, - 45, 45); + $contributionID = $this->contributionCreate(array( + 'contact_id' => $this->_individualId, + 'financial_type_id' => $this->_financialTypeId, + 'invoice_id' => 45, + 'trxn_id' => 45, + )); $pledge = $this->callAPISuccess('Pledge', 'Create', $pledgeParams); //test the pledge_payment_create function diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index 0e2f5e7899..51aab4e337 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -520,14 +520,19 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { } /** + * Test deleting a contribution. * + * (It is unclear why this is in this class - it seems like maybe it doesn't test anything not + * on the contribution test class & might be copy and paste....). */ public function testDeleteContribution() { - $contributionID = $this->contributionCreate(array('contact_id' => $this->_individualId), $this->financialtypeID, 'dfsdf', 12389); - $params = array( - 'id' => $contributionID, - ); - $this->callAPIAndDocument('contribution', 'delete', $params, __FUNCTION__, __FILE__); + $contributionID = $this->contributionCreate(array( + 'contact_id' => $this->_individualId, + 'trxn_id' => 12389, + 'financial_type_id' => $this->financialtypeID, + 'invoice_id' => 'dfsdf', + )); + $this->callAPISuccess('contribution', 'delete', array('id' => $contributionID)); } }