CRM-16367 (Backoffice Contribution Form) centralisation & testing of setting premium...
authorEileen McNaughton <eileen@fuzion.co.nz>
Sun, 3 May 2015 11:50:06 +0000 (23:50 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Sun, 3 May 2015 11:50:06 +0000 (23:50 +1200)
CRM/Contribute/Form/AdditionalInfo.php
CRM/Contribute/Form/Contribution.php
CRM/Core/BAO/Note.php
tests/phpunit/CRM/Contribute/Form/ContributionTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 448f05bc4deace7554924cb1a4154231f51fb668..74f53f0c3e24c7855fe75f36b230f0ef6811b470 100644 (file)
@@ -263,7 +263,7 @@ class CRM_Contribute_Form_AdditionalInfo {
    *
    * @return void
    */
-  public static function processNote(&$params, $contactID, $contributionID, $contributionNoteID = NULL) {
+  public static function processNote($params, $contactID, $contributionID, $contributionNoteID = NULL) {
     //process note
     $noteParams = array(
       'entity_table' => 'civicrm_contribution',
index 0352c12d0238ceb449efb8cd2b79b13bd402e9e3..5c27b2671e534f8cf110366a3cf34f91eff2b0b8 100644 (file)
@@ -1294,11 +1294,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE);
     }
 
-    //process the note
-    if ($contribution->id && isset($params['note'])) {
-      CRM_Contribute_Form_AdditionalInfo::processNote($params, $contactID, $contribution->id, NULL);
-    }
-
     if ($contribution->id) {
       array_unshift($this->statusMessage, ts('The contribution record has been processed.'));
       if (!empty($this->_params['is_email_receipt']) && $sendReceipt) {
@@ -1772,17 +1767,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
         );
       }
 
-      //process  note
-      if ($contribution->id && isset($formValues['note'])) {
-        CRM_Contribute_Form_AdditionalInfo::processNote($formValues, $this->_contactID, $contribution->id, $this->_noteID);
-      }
-
-      //process premium
-      if ($contribution->id && isset($formValues['product_name'][0])) {
-        CRM_Contribute_Form_AdditionalInfo::processPremium($formValues, $contribution->id,
-          $this->_premiumID, $this->_options
-        );
-      }
       array_unshift($this->statusMessage, ts('The contribution record has been saved.'));
 
       $this->invoicingPostProcessHook($submittedValues, $action, $lineItem);
@@ -1805,6 +1789,16 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
 
     }
 
+    if ($contribution->id && isset($formValues['product_name'][0])) {
+      CRM_Contribute_Form_AdditionalInfo::processPremium($formValues, $contribution->id,
+        $this->_premiumID, $this->_options
+      );
+    }
+
+    if ($contribution->id && isset($submittedValues['note'])) {
+      CRM_Contribute_Form_AdditionalInfo::processNote($submittedValues, $this->_contactID, $contribution->id, $this->_noteID);
+    }
+
     CRM_Core_Session::setStatus(implode(' ', $this->statusMessage), $this->statusMessageTitle, 'success');
 
     CRM_Contribute_BAO_Contribution::updateRelatedPledge(
index 94b973708dac23b8a6b54a7797783846fea14389..038dbf77447c936bcd1448192ae887ec99c40a47 100644 (file)
@@ -139,7 +139,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @return object
    *   $note CRM_Core_BAO_Note object
    */
-  public static function &add(&$params, $ids = array()) {
+  public static function add(&$params, $ids = array()) {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
       return CRM_Core_DAO::$_nullObject;
index 0208520707d258d2951b5232a6285b7d9c53ed58..ef4cfc26b7e682be1e750c5963546f9b41d42dc5 100644 (file)
@@ -144,6 +144,7 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
    */
   public function tearDown() {
     $this->quickCleanUpFinancialEntities();
+    $this->quickCleanup(array('civicrm_note'));
   }
 
   /**
@@ -308,4 +309,61 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
     $mut->stop();
   }
 
+  /**
+   * Test the submit function on the contribution page.
+   */
+  public function testSubmitWithNote() {
+    $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('Check', $this->paymentInstruments),
+      'contribution_status_id' => 1,
+      'note' => 'Super cool and interesting stuff',
+    ),
+      CRM_Core_Action::ADD);
+    $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
+    $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
+    $this->assertEquals($note['note'], 'Super cool and interesting stuff');
+  }
+
+  /**
+   * Test the submit function on the contribution page.
+   */
+  public function testSubmitWithNoteCreditCard() {
+    $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('Check', $this->paymentInstruments),
+      'contribution_status_id' => 1,
+      'note' => 'Super cool and interesting stuff',
+    ) + $this->getCreditCardParams (),
+      CRM_Core_Action::ADD);
+    $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
+    $note = $this->callAPISuccessGetSingle('note', array('entity_table' => 'civicrm_contribution'));
+    $this->assertEquals($note['note'], 'Super cool and interesting stuff');
+  }
+
+  /**
+   * Get parameters for credit card submit calls.
+   *
+   * @return array
+   *   Credit card specific parameters.
+   */
+  function getCreditCardParams() {
+    return array(
+      'payment_processor_id' => $this->paymentProcessor->id,
+      'credit_card_exp_date' => array('M' => 5, 'Y' => 2012),
+      'credit_card_number' => '411111111111111',
+    );
+  }
 }
+
index 10388ebc58e0565ec0d343635be4acd2ea7279e1..b9ebdd5738a1f3d2e039f86f33584897bca1e767 100755 (executable)
@@ -2515,6 +2515,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
     $tablesToTruncate = array(
       'civicrm_contribution',
       'civicrm_contribution_soft',
+      'civicrm_contribution_product',
       'civicrm_financial_trxn',
       'civicrm_financial_item',
       'civicrm_contribution_recur',