From: deb.monish Date: Wed, 13 Apr 2016 15:32:20 +0000 (+0530) Subject: added unit test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2a0df9d9355f6420492bf89d96eb7f6c55918006;p=civicrm-core.git added unit test --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index f8cc5df3ef..acd9d3e56e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2552,17 +2552,18 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac $addressParams = array('id' => $this->address_id); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); $addressDetails = array_values($addressDetails); - $values['address'] = $addressDetails[0]['display']; } // Else we assign the billing address of the contribution contact. else { $addressParams = array('contact_id' => $this->contact_id, 'is_billing' => 1); - $addressDetails = CRM_Core_BAO_Address::getValues($addressParams); - if (!is_null($addressDetails)) { - $addressDetails = array_values($addressDetails); - $values['address'] = $addressDetails[0]['display']; - } + $addressDetails = (array) CRM_Core_BAO_Address::getValues($addressParams); + $addressDetails = array_values($addressDetails); } + + if (!empty($addressDetails[0]['display'])) { + $values['address'] = $addressDetails[0]['display']; + } + if ($this->_component == 'contribute') { //get soft contributions $softContributions = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->id, TRUE); diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 7d48202230..fa90194452 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -1603,6 +1603,61 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->revertTemplateToReservedTemplate(); } + /** + * Test to check whether contact billing address is used when no contribution address + */ + public function testBillingAddress() { + $mut = new CiviMailUtils($this, TRUE); + $this->swapMessageTemplateForTestTemplate(); + $this->createLoggedInUser(); + + //Scenario 1: When Contact don't have any address + $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $contribution = $this->callAPISuccess('contribution', 'create', $params); + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + )); + $mut->checkMailLog(array( + 'address:::', + )); + + // Scenario 2: Contribution using address + $address = $this->callAPISuccess('address', 'create', array( + 'street_address' => 'contribution billing st', + 'location_type_id' => 2, + 'contact_id' => $this->_params['contact_id'], + )); + $params = array_merge($this->_params, array('contribution_status_id' => 2, + 'address_id' => $address['id'], + ) + ); + $contribution = $this->callAPISuccess('contribution', 'create', $params); + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + )); + $mut->checkMailLog(array( + 'address:::contribution billing st', + )); + + // Scenario 3: Contribution wtth no address but contact has a billing address + $this->callAPISuccess('address', 'create', array( + 'id' => $address['id'], + 'street_address' => 'is billing st', + 'contact_id' => $this->_params['contact_id'], + )); + $params = array_merge($this->_params, array('contribution_status_id' => 2)); + $contribution = $this->callAPISuccess('contribution', 'create', $params); + $this->callAPISuccess('contribution', 'completetransaction', array( + 'id' => $contribution['id'], + )); + $mut->checkMailLog(array( + 'address:::is billing st', + )); + + $mut->stop(); + $this->revertTemplateToReservedTemplate(); + } + /** * Test completing a transaction via the API. *