CRM-17417 and CRM-17418 fixes
authormonishdeb <monish.deb@webaccessglobal.com>
Thu, 19 Nov 2015 14:03:38 +0000 (19:33 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Thu, 19 Nov 2015 14:03:38 +0000 (19:33 +0530)
----------------------------------------
* CRM-17417: Tax is reapplied when editing a contribution associated with a membership or participant entity unless the status is changed.
  https://issues.civicrm.org/jira/browse/CRM-17417
* CRM-17418: Cancelling a taxable contribution writes incorrect values to the database
  https://issues.civicrm.org/jira/browse/CRM-17418

tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/WebTest/Contribute/StandaloneAddTest.php
tests/phpunit/WebTest/Member/EditMembershipTest.php

index e8eeb48d17741544f765e0d34bf414ba9f49ebb2..b80a67390961146b9469ec286e4b293ea7619afd 100644 (file)
@@ -1473,10 +1473,12 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param int $duration_interval
    * @param string $duration_unit
    * @param string $auto_renew
+   * @param string $auto_renew
+
    *
    * @return array
    */
-  public function webtestAddMembershipType($period_type = 'rolling', $duration_interval = 1, $duration_unit = 'year', $auto_renew = 'no', $minimumFee = 100) {
+  public function webtestAddMembershipType($period_type = 'rolling', $duration_interval = 1, $duration_unit = 'year', $auto_renew = 'no', $minimumFee = 100, $financialType = 'Member Dues') {
     $membershipTitle = substr(sha1(rand()), 0, 7);
     $membershipOrg = $membershipTitle . ' memorg';
     $this->webtestAddOrganization($membershipOrg, TRUE);
@@ -1485,7 +1487,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     $memTypeParams = array(
       'membership_type' => $title,
       'member_of_contact' => $membershipOrg,
-      'financial_type' => 2,
+      'financial_type' => $financialType,
       'period_type' => $period_type,
     );
 
@@ -1515,7 +1517,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     $this->select2('member_of_contact_id', $membershipTitle);
 
     $this->type('minimum_fee', $minimumFee);
-    $this->select('financial_type_id', "value={$memTypeParams['financial_type']}");
+    $this->select('financial_type_id', "label={$memTypeParams['financial_type']}");
 
     $this->type('duration_interval', $duration_interval);
     $this->select('duration_unit', "label={$duration_unit}");
index df15c94a9dc8706dd890c99d14d355f2b62e401a..27bdcf162d7666bb88f34a53638bd3094ecd5c70 100644 (file)
@@ -48,17 +48,15 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
     $financialAccountDescription = "{$financialAccountTitle} Description";
     $accountingCode = 1033;
-    $financialAccountType = 'Asset';
-    $taxDeductible = FALSE;
+    $financialAccountType = 'Liability';
+    $taxDeductible = TRUE;
     $isActive = FALSE;
     $isTax = TRUE;
-    $taxRate = 9.9999999;
+    $taxRate = 10.00;
     $isDefault = FALSE;
 
     //Add new organisation
-    if ($orgName) {
-      $this->webtestAddOrganization($orgName);
-    }
+    $this->webtestAddOrganization($orgName);
 
     $this->_testAddFinancialAccount($financialAccountTitle,
       $financialAccountDescription,
@@ -72,13 +70,29 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
       $isDefault
     );
 
+    //Add new Financial Type
+    $financialType['name'] = 'Taxable FinancialType ' . substr(sha1(rand()), 0, 4);
+    $financialType['is_deductible'] = TRUE;
+    $financialType['is_reserved'] = FALSE;
+    $this->addeditFinancialType($financialType);
+
+    // Assign the created Financial Account $financialAccountTitle to $financialType
+    $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[name]']/../../td[7]/span/a[text()='Accounts']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+    $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
+    $this->select('account_relationship', "label=Sales Tax Account is");
+    $this->select('financial_account_id', "label=" . $financialAccountTitle);
+    $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+
     $this->openCiviPage("contribute/add", "reset=1&context=standalone", "_qf_Contribution_upload");
 
     // create new contact using dialog
     $contact = $this->createDialogContact();
 
     // select financial type
-    $this->select("financial_type_id", "value=1");
+    $this->select("financial_type_id", "label=" .  $financialType['name']);
 
     // fill in Received Date
     $this->webtestFillDate('receive_date');
@@ -90,9 +104,7 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->type("total_amount", "100");
 
     // select payment instrument type = Check and enter chk number
-    $this->select("payment_instrument_id", "value=4");
-    $this->waitForElementPresent("check_number");
-    $this->type("check_number", "check #1041");
+    $this->select("payment_instrument_id", "label=Cash");
     $this->click("is_email_receipt");
     $this->assertTrue($this->isChecked("is_email_receipt"), 'Send Receipt checkbox should be checked.');
     $this->type("trxn_id", "P20901X1" . rand(100, 10000));
@@ -101,17 +113,11 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1');
     $this->type("soft_credit_amount_1", "100");
 
-    //Custom Data
-    //$this->click('CIVICRM_QFID_3_6');
-
     //Additional Detail section
     $this->click("AdditionalDetail");
     $this->waitForElementPresent("thankyou_date");
 
     $this->type("note", "This is a test note.");
-    $this->type("non_deductible_amount", "10");
-    $this->type("fee_amount", "0");
-    $this->type("net_amount", "0");
     $this->type("invoice_id", time());
     $this->webtestFillDate('thankyou_date');
 
@@ -135,16 +141,18 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     // verify if Membership is created
     $this->waitForElementPresent("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
 
+    $contriID = $this->urlArg('id', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
+    $contactID = $this->urlArg('cid', $this->getAttribute("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='Edit']@href"));
+
     //click through to the Membership view screen
     $this->click("xpath=//div[@class='view-content']//table[@class='selector row-highlight']//tbody/tr[1]/td[8]/span/a[text()='View']");
     $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
 
     $expected = array(
-      'Financial Type' => 'Donation',
-      'Total Amount' => '$ 100.00',
+      'Financial Type' => $financialType['name'],
+      'Total Amount' => '$ 110.00',
       'Contribution Status' => 'Completed',
-      'Paid By' => 'Check',
-      'Check Number' => 'check #1041',
+      'Paid By' => 'Cash',
     );
 
     foreach ($expected as $label => $value) {
@@ -171,13 +179,28 @@ class WebTest_Contribute_StandaloneAddTest extends CiviSeleniumTestCase {
     $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[1]/a", preg_quote($contact['display_name']));
     // verify soft credit details
     $expected = array(
-      4 => 'Donation',
+      4 => $financialType['name'],
       2 => '100.00',
       6 => 'Completed',
     );
     foreach ($expected as $value => $label) {
       $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody/tr[2]/td[$value]", preg_quote($label));
     }
+
+    // CRM-17418 fix: Now cancel the contribution
+    $this->openCiviPage("contact/view/contribution", "reset=1&action=update&id=$contriID&cid=$contactID&context=contribution", "_qf_Contribution_upload");
+    $this->select('contribution_status_id', 'label=Cancelled');
+    $this->waitForElementPresent('cancel_reason');
+    $this->click("_qf_Contribution_upload");
+    // Is status message correct?
+    $this->waitForText("crm-notification-container", "The contribution record has been saved.");
+
+    // 1. On first completed contribution the contribution_amount = 100 and Tax Amount = 10
+    // 2. After Cancellation contribution_amount = -100 and Tax Amount = -10
+    // So the sum of all the 4 created financial item's amount would be 0
+    $query = "SELECT SUM( amount ) FROM `civicrm_financial_item` WHERE entity_id = %1";
+    $sum = CRM_Core_DAO::singleValueQuery($query, array(1 => array($contriID, 'Integer')));
+    $this->assertEquals($sum, 0.00);
   }
 
   public function testfinancialTypeSearch() {
index a3cfbe83fb93b98c210024a2313ee8f4dbb38c21..efc824d2359900e50165d6454cc4a9826b1b2e74 100644 (file)
@@ -43,8 +43,51 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     $contactName = "Memberson, {$firstName}";
     $displayName = "{$firstName} Memberson";
 
+    // Add new Financial Account
+    $orgName = 'Alberta ' . substr(sha1(rand()), 0, 7);
+    $financialAccountTitle = 'Financial Account ' . substr(sha1(rand()), 0, 4);
+    $financialAccountDescription = "{$financialAccountTitle} Description";
+    $accountingCode = 1033;
+    $financialAccountType = 'Liability';
+    $taxDeductible = TRUE;
+    $isActive = FALSE;
+    $isTax = TRUE;
+    $taxRate = 10.00;
+    $isDefault = FALSE;
+
+    //Add new organisation
+    $this->webtestAddOrganization($orgName);
+
+    $this->_testAddFinancialAccount($financialAccountTitle,
+      $financialAccountDescription,
+      $accountingCode,
+      $orgName,
+      $financialAccountType,
+      $taxDeductible,
+      $isActive,
+      $isTax,
+      $taxRate,
+      $isDefault
+    );
+
+    //Add new Financial Type
+    $financialType['name'] = 'Taxable FinancialType ' . substr(sha1(rand()), 0, 4);
+    $financialType['is_deductible'] = TRUE;
+    $financialType['is_reserved'] = FALSE;
+    $this->addeditFinancialType($financialType);
+
+    // Assign the created Financial Account $financialAccountTitle to $financialType
+    $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[name]']/../../td[7]/span/a[text()='Accounts']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+    $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
+    $this->select('account_relationship', "label=Sales Tax Account is");
+    $this->select('financial_account_id', "label=" . $financialAccountTitle);
+    $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
+    $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()=' Assign Account']");
+
     // add membership type
-    $membershipTypes = $this->webtestAddMembershipType();
+    $membershipTypes = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 100, $financialType['name']);
 
     // now add membership
     $this->openCiviPage("member/add", "reset=1&action=add&context=standalone", "_qf_Membership_upload");
@@ -64,10 +107,20 @@ class WebTest_Member_EditMembershipTest extends CiviSeleniumTestCase {
     // Let Join Date and Start Date stay default
     $this->click("_qf_Membership_upload");
 
-    //View Membership
+    //Open related 'Edit Contribution' form
     $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
     $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
     $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
+    //CRM-17417, Simply open and save edit contribution form to check that tax shouldn't be reapplied
+    $this->clickLink("xpath=//a[@title='Edit Contribution']", "_qf_Contribution_upload", FALSE);
+    $this->click("_qf_Contribution_upload");
+    $this->waitForAjaxContent();
+    $this->assertTrue($this->isTextPresent("$ 110.00"), "Contribution Amount got updated as Sale Tax got reapplied which is wrong");
+
+    //View Membership
+    $this->click("css=li#tab_member a");
+    $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
+    $this->click("xpath=//div[@id='memberships']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
     $expected = array(
       'Membership Type' => $membershipTypes['membership_type'],
       'Status' => 'New',