CRM-16302 Free memberships are broken fix
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 17 Apr 2015 11:31:37 +0000 (17:01 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 17 Apr 2015 11:31:37 +0000 (17:01 +0530)
CRM/Contribute/Form/Contribution/Confirm.php
tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php

index c9f12e5ab9fabad280a85e358fe882c84919410a..1183dcaad09d330926095259e066514c81ddb869 100644 (file)
@@ -679,7 +679,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
   public function postProcess() {
     $contactID = $this->getContactID();
     $isPayLater = $this->_params['is_pay_later'];
-    if ($this->_params['payment_processor'] == 0) {
+    if (isset($this->_params['payment_processor']) && $this->_params['payment_processor'] == 0) {
       $this->_params['is_pay_later'] = $isPayLater = TRUE;
     }
     // add a description field at the very beginning
index 83b654f622fd6fef5e0b75e459ef849a073a21e9..dd6366b6f602a5ae08b4d9270ca137f95596cad0 100644 (file)
@@ -1474,7 +1474,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    *
    * @return array
    */
-  public function webtestAddMembershipType($period_type = 'rolling', $duration_interval = 1, $duration_unit = 'year', $auto_renew = 'no') {
+  public function webtestAddMembershipType($period_type = 'rolling', $duration_interval = 1, $duration_unit = 'year', $auto_renew = 'no', $minimumFee = 100) {
     $membershipTitle = substr(sha1(rand()), 0, 7);
     $membershipOrg = $membershipTitle . ' memorg';
     $this->webtestAddOrganization($membershipOrg, TRUE);
@@ -1512,7 +1512,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
     $this->select2('member_of_contact_id', $membershipTitle);
 
-    $this->type('minimum_fee', '100');
+    $this->type('minimum_fee', $minimumFee);
     $this->select('financial_type_id', "value={$memTypeParams['financial_type']}");
 
     $this->type('duration_interval', $duration_interval);
index af869d92302c2abfb8b3cec17e5c7ea3d578b7e4..50273b02a315dd21cd4bd8635f0da2eaa9409f1a 100644 (file)
@@ -207,7 +207,7 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
    * @param $hash
    * @param bool $otherAmount
    */
-  public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) {
+  public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE) {
     //Open Live Contribution Page
     $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
     // Select membership type 1
@@ -220,10 +220,10 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
       $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
 
     }
-    if (!$otherAmount) {
+    if (!$otherAmount && $amountSection) {
       $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
     }
-    else {
+    elseif ($amountSection) {
       $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
     }
     if ($payLater) {
@@ -242,7 +242,7 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
     $this->type("postal_code-1", "94117");
     $this->select("country-1", "value=1228");
     $this->select("state_province-1", "value=1001");
-    if (!$payLater) {
+    if (!$payLater && $amountSection) {
       //Credit Card Info
       $this->select("credit_card_type", "value=Visa");
       $this->type("credit_card_number", "4111111111111111");
@@ -353,4 +353,123 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase {
     $this->webtestVerifyTabularData($expected);
   }
 
+
+  public function testOnlineMembershipCreateWithZeroContribution() {
+    //login with admin credentials & make sure we do have required permissions.
+    $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
+    $this->changePermissions($permissions);
+
+    $hash = substr(sha1(rand()), 0, 7);
+    $rand = 2 * rand(2, 50);
+    $amountSection = FALSE;
+    $payLater = FALSE;
+    $allowOtherAmount = FALSE;
+    $onBehalf = FALSE;
+    $pledges = FALSE;
+    $recurring = FALSE;
+    $memberships = TRUE;
+    $memPriceSetId = NULL;
+    $friend = FALSE;
+    $profilePreId = 1;
+    $profilePostId = NULL;
+    $premiums = FALSE;
+    $widget = FALSE;
+    $pcp = FALSE;
+    $isSeparatePayment = FALSE;
+    $membershipsRequired = FALSE;
+    $fixedAmount = FALSE;
+    $contributionTitle = "Title $hash";
+    $pageId = $this->webtestAddContributionPage($hash,
+      $rand,
+      $contributionTitle,
+      NULL,
+      $amountSection,
+      $payLater,
+      $onBehalf,
+      $pledges,
+      $recurring,
+      $memberships,
+      $memPriceSetId,
+      $friend,
+      $profilePreId,
+      $profilePostId,
+      $premiums,
+      $widget,
+      $pcp,
+      FALSE,
+      FALSE,
+      $isSeparatePayment,
+      FALSE,
+      $allowOtherAmount,
+      TRUE,
+      'Member Dues',
+      $fixedAmount,
+      $membershipsRequired
+    );
+    $memTypeParams = $this->webtestAddMembershipType('rolling', 1, 'year', 'no', 0);
+    $memTypeTitle = $memTypeParams['membership_type'];
+    $memTypeId = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle}']/../../td[12]/span/a[3]@href"));
+    $memTypeId = $memTypeId[1];
+
+    // edit contribution page amounts tab to uncheck real time monetary transaction
+    $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
+    $this->click("membership_type_$memTypeId");
+    $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
+    $text = "'MembershipBlock' information has been saved.";
+    $this->waitForText('crm-notification-container', $text);
+    $this->click('link=Amounts');
+    $this->waitForElementPresent('_qf_Amount_cancel-bottom');
+    $this->click('is_monetary');
+    $this->clickLink('_qf_Amount_upload_done-bottom');
+    $text = "'Amount' information has been saved.";
+    $this->waitForText('crm-notification-container', $text);
+
+    $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
+    $lastName = 'An' . substr(sha1(rand()), 0, 7);
+
+    //logout
+    $this->webtestLogout();
+
+    $this->_testOnlineMembershipSignup($pageId, $memTypeTitle, $firstName, $lastName, $payLater, $hash, $allowOtherAmount, $amountSection);
+
+    // Log in using webtestLogin() method
+    $this->webtestLogin();
+
+    //Find Contribution
+    $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
+    $this->type("sort_name", "$lastName $firstName");
+    $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
+    $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE);
+
+    //View Contribution Record and verify data
+    $expected = array(
+      'From' => "{$firstName} {$lastName}",
+      'Financial Type' => 'Member Dues',
+      'Total Amount' => '0.00',
+      'Contribution Status' => 'Completed',
+      'Received Into' => 'Deposit Bank Account',
+      'Source' => "Online Contribution: $contributionTitle",
+      'Online Contribution Page' => $contributionTitle,
+    );
+    $this->webtestVerifyTabularData($expected);
+
+    //Find Member
+    $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
+
+    $this->type("sort_name", "$lastName $firstName");
+    $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
+    $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
+    $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
+
+    //View Membership Record
+    $verifyData = array(
+      'Member' => $firstName . ' ' . $lastName,
+      'Membership Type' => $memTypeTitle,
+      'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
+      'Status' => 'New',
+    );
+
+    $this->webtestVerifyTabularData($verifyData);
+  }
+
 }