From: eileenmcnaughton Date: Wed, 8 Jul 2015 07:48:51 +0000 (+0000) Subject: Fix e-notice & add tests around where e-notice was X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=739a83363c63f7bd58ca2c75e8d84c2bfd1ad1ec;p=civicrm-core.git Fix e-notice & add tests around where e-notice was --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index adaae8a413..e77ff097e4 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1325,9 +1325,10 @@ LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.cont } if ($hasBillingField) { $address = CRM_Core_BAO_Address::add($addressParams, FALSE); + return $address->id; } + return NULL; - return $address->id; } /** diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 8461b9d31b..20be35a0a1 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -215,6 +215,16 @@ class CRM_Contribute_BAO_Query { $query->_select['contribution_campaign_title'] = "civicrm_campaign.title as contribution_campaign_title"; $query->_element['contribution_campaign_title'] = $query->_tables['civicrm_campaign'] = 1; } + + // Adding address_id in a way that is more easily extendable since the above is a bit ... wordy. + $supportedBasicReturnValues = array('address_id'); + foreach ($supportedBasicReturnValues as $fieldName) { + if (!empty($query->_returnProperties[$fieldName])) { + $query->_select[$fieldName] = "civicrm_contribution.{$fieldName} as $fieldName"; + $query->_element[$fieldName] = $query->_tables['civicrm_contribution'] = 1; + } + } + //CRM-16116: get financial_type_id if (!empty($query->_returnProperties['financial_type_id'])) { $query->_select['financial_type_id'] = "civicrm_contribution.financial_type_id as financial_type_id"; diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 22cc3a22bb..812ec435ce 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1333,6 +1333,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP 'cancel_date_time' => '', 'hidden_Premium' => 1, ); + $this->_bltID = 5; if (!empty($params['id'])) { $existingContribution = civicrm_api3('contribution', 'getsingle', array( 'id' => $params['id'], diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 9d4f3d2825..256fc68aa1 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -258,6 +258,7 @@ function _civicrm_api3_contribution_get_spec(&$params) { 'title' => 'Get Test Contributions?', 'api.aliases' => array('is_test'), ); + $params['financial_type_id']['api.aliases'] = array('contribution_type_id'); $params['payment_instrument_id']['api.aliases'] = array('contribution_payment_instrument', 'payment_instrument'); $params['contact_id'] = $params['contribution_contact_id']; diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 185338d587..8410a75742 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -133,7 +133,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { */ public function tearDown() { $this->quickCleanUpFinancialEntities(); - $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match')); + $this->quickCleanup(array('civicrm_note', 'civicrm_uf_match', 'civicrm_address')); } /** @@ -202,7 +202,8 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), 'credit_card_number' => '411111111111111', ), CRM_Core_Action::ADD, - 'live'); + 'live' + ); } catch (\Civi\Payment\Exception\PaymentProcessorException $e) { $this->callAPISuccessGetCount('Contribution', array( @@ -225,6 +226,62 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $this->fail('An expected exception has not been raised.'); } + /** + * Test the submit function creates a billing address if provided. + */ + public function testSubmitCreditCardWithBillingAddress() { + $form = new CRM_Contribute_Form_Contribution(); + $form->testSubmit(array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), + 'payment_processor_id' => $this->paymentProcessor->id, + 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_number' => '411111111111111', + 'billing_city-5' => 'Vancouver', + ), CRM_Core_Action::ADD, + 'live' + ); + $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); + $this->assertNotEmpty($contribution['address_id']); + $this->callAPISuccessGetSingle('Address', array( + 'city' => 'Vancouver', + 'location_type_id' => 5, + 'id' => $contribution['address_id'], + )); + + } + + /** + * Test the submit function does not create a billing address if no details provided. + */ + public function testSubmitCreditCardWithNoBillingAddress() { + $form = new CRM_Contribute_Form_Contribution(); + $form->testSubmit(array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), + 'payment_processor_id' => $this->paymentProcessor->id, + 'credit_card_exp_date' => array('M' => 5, 'Y' => 2025), + 'credit_card_number' => '411111111111111', + ), CRM_Core_Action::ADD, + 'live' + ); + $contribution = $this->callAPISuccessGetSingle('Contribution', array('return' => 'address_id')); + $this->assertEmpty($contribution['address_id']); + $this->callAPISuccessGetCount('Address', array( + 'city' => 'Vancouver', + 'location_type_id' => 5, + ), 0); + + } + /** * Test the submit function on the contribution page. */