Fix e-notice & add tests around where e-notice was
authoreileenmcnaughton <eileen@fuzion.co.nz>
Wed, 8 Jul 2015 07:48:51 +0000 (07:48 +0000)
committereileenmcnaughton <eileen@fuzion.co.nz>
Wed, 8 Jul 2015 07:48:51 +0000 (07:48 +0000)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/BAO/Query.php
CRM/Contribute/Form/Contribution.php
api/v3/Contribution.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php

index adaae8a4137427912d181f62280250a973518b41..e77ff097e441a1c7fd065465fa5ab3f36417ddf0 100644 (file)
@@ -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;
   }
 
   /**
index 8461b9d31bc56fb345d085eb0e1384dc29baffb0..20be35a0a1ac7ee63aa9380aa24e111c78c2db2b 100644 (file)
@@ -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";
index 22cc3a22bbfbe4c17b148b8d285673cdffb85111..812ec435cef4a5e236bafdcc4d1f15bd3e6efaa4 100644 (file)
@@ -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'],
index 9d4f3d2825a8ea99c2b35ad268c28d112bd4d727..256fc68aa1236b42f00add9fa822d88e01e06ea7 100644 (file)
@@ -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'];
index 185338d58764ffe2794dee29ed5b540dc14e9a3c..8410a75742f45d7bd5f873a8b16b478e7218a850 100644 (file)
@@ -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.
    */