CRM-17863 -- Payments don't appear to be linked to Contribution when re: Membership
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Thu, 28 Jan 2016 12:04:59 +0000 (17:34 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Thu, 28 Jan 2016 12:04:59 +0000 (17:34 +0530)
CRM/Contribute/BAO/Contribution.php
tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php

index 27e8e9b9b4ba83af7b396b9cb4d7df979c9b44f0..0835aeb00ad5d2d204c1e39870feace04ca17c94 100644 (file)
@@ -3411,21 +3411,12 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
         $params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
       }
     }
-    $trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
-    $params['entity_id'] = $trxn->id;
 
     if ($context == 'changedStatus') {
       if (($params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus)
           || $params['prevContribution']->contribution_status_id == array_search('In Progress', $contributionStatus))
         && ($params['contribution']->contribution_status_id == array_search('Completed', $contributionStatus))
       ) {
-        $query = "UPDATE civicrm_financial_item SET status_id = %1 WHERE entity_id = %2 and entity_table = 'civicrm_line_item'";
-        $sql = "SELECT id, amount FROM civicrm_financial_item WHERE entity_id = %1 and entity_table = 'civicrm_line_item'";
-
-        $entityParams = array(
-          'entity_table' => 'civicrm_financial_item',
-          'financial_trxn_id' => $trxn->id,
-        );
         if (empty($params['line_item'])) {
           //CRM-15296
           //@todo - check with Joe regarding this situation - payment processors create pending transactions with no line items
@@ -3433,6 +3424,15 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
           // & this can be removed
           return;
         }
+        $trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
+        $params['entity_id'] = $trxn->id;
+        $query = "UPDATE civicrm_financial_item SET status_id = %1 WHERE entity_id = %2 and entity_table = 'civicrm_line_item'";
+        $sql = "SELECT id, amount FROM civicrm_financial_item WHERE entity_id = %1 and entity_table = 'civicrm_line_item'";
+
+        $entityParams = array(
+          'entity_table' => 'civicrm_financial_item',
+          'financial_trxn_id' => $trxn->id,
+        );
         foreach ($params['line_item'] as $fieldId => $fields) {
           foreach ($fields as $fieldValueId => $fieldValues) {
             $fparams = array(
@@ -3454,6 +3454,9 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
         return;
       }
     }
+
+    $trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
+    $params['entity_id'] = $trxn->id;
     if ($context != 'changePaymentInstrument') {
       $itemParams['entity_table'] = 'civicrm_line_item';
       $trxnIds['id'] = $params['entity_id'];
@@ -4487,10 +4490,6 @@ LIMIT 1;";
     if ((empty($input['prevContribution']) && $paymentProcessorId) || (!$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == $contributionStatuses['Pending'])) {
       $input['payment_processor'] = $paymentProcessorId;
     }
-    $input['contribution_status_id'] = $contributionStatuses['Completed'];
-    $input['total_amount'] = $input['amount'];
-    $input['contribution'] = $contribution;
-    $input['financial_type_id'] = $contribution->financial_type_id;
 
     if (!empty($contribution->_relatedObjects['participant'])) {
       $input['contribution_mode'] = 'participant';
@@ -4500,7 +4499,14 @@ LIMIT 1;";
     elseif (!empty($contribution->_relatedObjects['membership'])) {
       $input['skipLineItem'] = TRUE;
       $input['contribution_mode'] = 'membership';
+      $contribution->contribution_status_id = $contributionStatuses['Completed'];
+      $contribution->trxn_id = CRM_Utils_Array::value('trxn_id', $input);
+      $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date);
     }
+    $input['contribution_status_id'] = $contributionStatuses['Completed'];
+    $input['total_amount'] = $input['amount'];
+    $input['contribution'] = $contribution;
+    $input['financial_type_id'] = $contribution->financial_type_id;
     //@todo writing a unit test I was unable to create a scenario where this line did not fatal on second
     // and subsequent payments. In this case the line items are created at
     // CRM_Contribute_BAO_ContributionRecur::addRecurLineItems
@@ -4750,8 +4756,8 @@ LIMIT 1;";
    */
   public static function addPayments($lineItems, $contributions) {
     // get financial trxn which is a payment
-    $ftSql = "SELECT ft.id 
-      FROM civicrm_financial_trxn ft 
+    $ftSql = "SELECT ft.id
+      FROM civicrm_financial_trxn ft
       INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution'
       WHERE eft.entity_id = %1 AND ft.is_payment = 1";
     $sql = "SELECT fi.id, li.price_field_value_id
index bbdc4b2331dd618e311374e7d1317146c47ed632..77039c757406f455ef5a1419c10dee4b19d1b86e 100644 (file)
@@ -135,14 +135,8 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
       'Member' => $firstName . ' ' . $lastName,
       'Membership Type' => $memTypeTitle1,
       'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
+      'Status' => 'Pending',
     );
-    if ($payLater) {
-      $verifyData['Status'] = 'Pending';
-    }
-    else {
-
-      $verifyData['Status'] = 'New';
-    }
     $this->webtestVerifyTabularData($verifyData);
 
     // Click View action link on associated contribution record
@@ -153,31 +147,24 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
     $verifyData = array(
       'From' => $firstName . ' ' . $lastName,
       'Total Amount' => '$ 100.00',
+      'Contribution Status' => 'Pending : Pay Later',
     );
-    if ($payLater) {
-      $verifyData['Contribution Status'] = 'Pending : Pay Later';
-    }
-    else {
-      $verifyData['Contribution Status'] = 'Completed';
-    }
     $this->webtestVerifyTabularData($verifyData);
 
     //CRM-15735 - verify membership dates gets changed w.r.t receive_date of contribution.
-    if ($payLater) {
-      $receiveDate = date('F jS, Y', strtotime("-1 month"));
-      $endDate = date('F jS, Y', strtotime("+1 year -1 month -1 day"));
-      $this->clickAjaxLink("xpath=//button//span[contains(text(),'Edit')]", 'receive_date');
-      $this->select('contribution_status_id', 'Completed');
-      $this->webtestFillDate('receive_date', '-1 month');
-      $this->clickAjaxLink("xpath=//button//span[contains(text(),'Save')]", "xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
-      $updatedData = array(
-        'Status' => 'New',
-        'Member Since' => $receiveDate,
-        'Start date' => $receiveDate,
-        'End date' => $endDate,
-      );
-      $this->webtestVerifyTabularData($updatedData);
-    }
+    $receiveDate = date('F jS, Y', strtotime("-1 month"));
+    $endDate = date('F jS, Y', strtotime("+1 year -1 month -1 day"));
+    $this->clickAjaxLink("xpath=//button//span[contains(text(),'Edit')]", 'receive_date');
+    $this->select('contribution_status_id', 'Completed');
+    $this->webtestFillDate('receive_date', '-1 month');
+    $this->clickAjaxLink("xpath=//button//span[contains(text(),'Save')]", "xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
+    $updatedData = array(
+      'Status' => 'New',
+      'Member Since' => $receiveDate,
+      'Start date' => $receiveDate,
+      'End date' => $endDate,
+    );
+    $this->webtestVerifyTabularData($updatedData);
 
     // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
     //logout
@@ -229,11 +216,14 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
       $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
     }
     elseif ($amountSection) {
+      $this->clickAt("xpath=//div[@class='content other_amount-content']/input");
+      $this->keyDown("xpath=//div[@class='content other_amount-content']/input", " ");
       $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
+      $this->typeKeys("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
     }
     if ($payLater) {
       $this->waitForAjaxContent();
-      $this->click("xpath=//div[@class='payment_processor-section']/div[2]/label[text()='Pay later label {$hash}']");
+      $this->click("xpath=//label[text()='Pay later label {$hash}']");
     }
     $this->type("email-5", $firstName . "@example.com");
     $this->waitForElementPresent("first_name");
@@ -254,6 +244,8 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
     }
     else {
       if (!$payLater && $amountSection) {
+        $this->click("xpath=//label[text()='Test Processor']");
+        $this->waitForAjaxContent();
         //Credit Card Info
         $this->select("credit_card_type", "value=Visa");
         $this->type("credit_card_number", "4111111111111111");
@@ -351,6 +343,19 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
     $this->type("sort_name", "$lastName $firstName");
     $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
     $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
+
+    // assert financial data - CRM-17863
+    $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
+    $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
+    $this->waitForAjaxContent();
+    $verifyFinancialData = array(
+      1 => '50.00',
+      2 => 'Donation',
+      6 => 'Completed',
+    );
+    foreach($verifyFinancialData as $col => $data) {
+      $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
+    }
     $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
 
     //View Contribution Record and verify data
@@ -459,6 +464,20 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
       $this->type("sort_name", "$lastName $firstName");
       $this->click("xpath=//tr/td[1]/label[contains(text(), 'Contribution is a Test?')]/../../td[2]/label[contains(text(), 'Yes')]/preceding-sibling::input[1]");
       $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']");
+
+      // assert financial data - CRM-17863
+      $this->waitForElementPresent("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
+      $this->click("xpath=//tr/td[@class='crm-contribution-amount']/a[@title='view payments']");
+      $this->waitForAjaxContent();
+      $verifyFinancialData = array(
+        1 => '0.00',
+        2 => 'Member Dues',
+        3 => 'Credit Card',
+        6 => 'Completed',
+      );
+      foreach($verifyFinancialData as $col => $data) {
+        $this->verifyText("xpath=//tr[@class='crm-child-row']/td/div/table/tbody/tr[2]/td[{$col}]", $data);
+      }
       $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[10]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
 
       //View Contribution Record and verify data