changePermissions($permissions); // Log in as normal user $this->webtestLogin(); // a random 7-char string and an even number to make this pass unique $hash = substr(sha1(rand()), 0, 7); $rand = 2 * rand(2, 50); // Use default payment processor $processorName = 'Test Processor'; // create contribution page with randomized title and default params $amountSection = TRUE; $payLater = TRUE; $allowOtherAmount = FALSE; $onBehalf = FALSE; $pledges = FALSE; $recurring = FALSE; $memberships = TRUE; $memPriceSetId = NULL; $friend = TRUE; $profilePreId = 1; $profilePostId = NULL; $premiums = TRUE; $widget = FALSE; $pcp = TRUE; $isSeparatePayment = TRUE; $contributionTitle = "Title $hash"; $pageId = $this->webtestAddContributionPage($hash, $rand, $contributionTitle, array($processorName => 'Dummy'), $amountSection, $payLater, $onBehalf, $pledges, $recurring, $memberships, $memPriceSetId, $friend, $profilePreId, $profilePostId, $premiums, $widget, $pcp, TRUE, FALSE, $isSeparatePayment, TRUE, FALSE ); // create two new membership types $memTypeParams1 = $this->webtestAddMembershipType(); $memTypeTitle1 = $memTypeParams1['membership_type']; $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href")); $memTypeId1 = $memTypeId1[1]; $memTypeParams2 = $this->webtestAddMembershipType(); $memTypeTitle2 = $memTypeParams2['membership_type']; $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle2}']/../../td[12]/span/a[3]@href")); $memTypeId2 = $memTypeId2[1]; // edit contribution page memberships tab to add two new membership types $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom'); $this->click("membership_type_$memTypeId1"); $this->click("membership_type_$memTypeId2"); $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom'); $text = "'MembershipBlock' information has been saved."; $this->waitForText('crm-notification-container', $text); //logout $this->webtestLogout(); // signup for membership 1 $firstName = 'Ma' . substr(sha1(rand()), 0, 4); $lastName = 'An' . substr(sha1(rand()), 0, 7); $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash); // Log in using webtestLogin() method $this->webtestLogin(); //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' => $memTypeTitle1, 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, ); if ($payLater) { $verifyData['Status'] = 'Pending'; } else { $verifyData['Status'] = 'New'; } $this->webtestVerifyTabularData($verifyData); // Click View action link on associated contribution record $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']"); $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']"); $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]"); //View Contribution Record $verifyData = array( 'From' => $firstName . ' ' . $lastName, 'Total Amount' => '$ 100.00', ); 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); } // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different) //logout $this->webtestLogout(); $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash); // Log in using webtestLogin() method $this->webtestLogin(); //Find Member $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); $this->type("sort_name", "$lastName $firstName"); $this->click("_qf_Search_refresh"); $this->waitForPageToLoad($this->getTimeoutMsec()); $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results'); } /** * @param int $pageId * @param int $memTypeId * @param string $firstName * @param string $lastName * @param $payLater * @param $hash * @param bool $otherAmount */ public function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE, $amountSection = TRUE, $freeMembership = FALSE) { //Open Live Contribution Page $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); // Select membership type 1 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label"); if ($memTypeId != 'No thank you') { $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//div/span/label/span[1][contains(text(),'$memTypeId')]"); } else { $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]"); } if (!$otherAmount && $amountSection) { $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']"); } elseif ($amountSection) { $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount); } if ($payLater) { $this->waitForAjaxContent(); $this->click("xpath=//label[text()='Pay later label {$hash}']"); } $this->type("email-5", $firstName . "@example.com"); $this->waitForElementPresent("first_name"); $this->type("first_name", $firstName); $this->waitForElementPresent("last_name"); $this->type("last_name", $lastName); $streetAddress = "100 Main Street"; $this->waitForElementPresent("street_address-1"); $this->type("street_address-1", $streetAddress); $this->type("city-1", "San Francisco"); $this->type("postal_code-1", "94117"); $this->select("country-1", "value=1228"); $this->select("state_province-1", "value=1001"); if ($freeMembership) { $this->waitForElementPresent("xpath=//div[@id='payment_information'][@style='display: none;']"); } else { if (!$payLater && $amountSection) { //Credit Card Info $this->select("credit_card_type", "value=Visa"); $this->type("credit_card_number", "4111111111111111"); $this->type("cvv2", "000"); $this->select("credit_card_exp_date[M]", "value=1"); $this->select("credit_card_exp_date[Y]", "value=2020"); //Billing Info $this->waitForElementPresent("billing_first_name"); $this->type("billing_first_name", $firstName . "billing"); $this->waitForElementPresent("billing_last_name"); $this->type("billing_last_name", $lastName . "billing"); $this->type("billing_street_address-5", "15 Main St."); $this->type(" billing_city-5", "San Jose"); $this->select("billing_country_id-5", "value=1228"); $this->select("billing_state_province_id-5", "value=1004"); $this->type("billing_postal_code-5", "94129"); } } $this->click("_qf_Main_upload-bottom"); $this->waitForElementPresent("_qf_Confirm_next-bottom"); $this->click("_qf_Confirm_next-bottom"); $this->waitForPageToLoad($this->getTimeoutMsec()); } public function testOnlineMembershipCreateWithContribution() { //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); // Use default payment processor $processorName = 'Test Processor'; $amountSection = TRUE; $payLater = TRUE; $allowOtherAmount = TRUE; $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, array($processorName => 'Dummy'), $amountSection, $payLater, $onBehalf, $pledges, $recurring, $memberships, $memPriceSetId, $friend, $profilePreId, $profilePostId, $premiums, $widget, $pcp, TRUE, FALSE, $isSeparatePayment, TRUE, $allowOtherAmount, TRUE, 'Donation', $fixedAmount, $membershipsRequired ); $firstName = 'Ma' . substr(sha1(rand()), 0, 4); $lastName = 'An' . substr(sha1(rand()), 0, 7); //logout $this->webtestLogout(); $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50); // 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' => 'Donation', 'Total Amount' => '50.00', 'Contribution Status' => 'Completed', 'Received Into' => 'Deposit Bank Account', 'Source' => "Online Contribution: $contributionTitle", 'Online Contribution Page' => $contributionTitle, ); $this->webtestVerifyTabularData($expected); } /** * CRM-16302 - To check whether membership, contribution are * created for free membership signup. */ 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 = $payLater = $allowOtherAmount = $onBehalf = $pledges = $recurring = FALSE; $premiums = $widget = $pcp = $isSeparatePayment = $membershipsRequired = $fixedAmount = $friend = FALSE; $memberships = TRUE; $memPriceSetId = NULL; $profilePreId = 1; $profilePostId = NULL; $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); $processors = array( 'Test Processor', 'AuthNet', 'PayPal', 'PayPal_Standard', ); foreach ($processors as $processor) { if ($processor == 'Test Processor') { $processorName = $processor; } else { $processorName = $processor . substr(sha1(rand()), 0, 7); $this->webtestAddPaymentProcessor($processorName, $processor); } $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id={$pageId}", '_qf_Amount_upload_done-bottom'); $this->assertTrue($this->isTextPresent($processorName)); $this->check("xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]"); $this->clickLink('_qf_Amount_upload_done-bottom'); $this->waitForText('crm-notification-container', "'Amount' information has been saved."); $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, TRUE); // 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' => 'Payment Processor 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); } } }