From 599e7e41573aed88002de79933bbb10b57081505 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Mon, 10 Aug 2015 16:01:22 +0530 Subject: [PATCH] Webtests and improvisations --- .../CRM/Contribute/Form/Contribution/Main.tpl | 17 +- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 4 + .../Member/OnlineMembershipCreateTest.php | 153 ++++++++++-------- 3 files changed, 101 insertions(+), 73 deletions(-) diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 934a6dedd2..219189c3e2 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -480,19 +480,22 @@ function skipPaymentMethod() { var flag = false; + // If price-set is used then calculate the Total Amount if (cj('#pricevalue').length !== 0) { - currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); - flag = (currentTotal == 0) ? true : false; + currentTotal = cj('#pricevalue').text().replace(/[^\/\d]/g,''); + flag = (currentTotal == 0) ? true : false; } + // Else quick-config w/o other-amount scenarios else { - cj('.price-set-option-content input').each( function(){ - currentTotal = cj(this).attr('data-amount').replace(/[^\/\d]/g,''); - if( cj(this).is(':checked') && currentTotal == 0 ) { + cj('.price-set-option-content input').each( function() { + currentTotal = cj(this).is('[data-amount]') ? cj(this).attr('data-amount').replace(/[^\/\d]/g,'') : 0; + if( cj(this).is(':checked') && currentTotal == 0 ) { flag = true; } }); - cj('.price-set-option-content input').change( function () { - if (cj(this).attr('data-amount').replace(/[^\/\d]/g,'') == 0 ) { + cj('.price-set-option-content input, .other_amount-content input').change( function () { + currentTotal = cj(this).is('[data-amount]') ? cj(this).attr('data-amount').replace(/[^\/\d]/g,'') : (cj(this).val() ? cj(this).val() : 0); + if (currentTotal == 0 ) { flag = true; } else { flag = false; diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index dd6366b6f6..832843f3c5 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -852,6 +852,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { elseif ($processorType == 'AuthNet') { // FIXME: we 'll need to make a new separate account for testing $processorSettings = array( + //dummy live username/password are passed to bypass processor validation on live credential + 'user_name' => '3HcY62mY', + 'password' => '69943NrwaQA92b8J', 'test_user_name' => '5ULu56ex', 'test_password' => '7ARxW575w736eF5p', ); @@ -875,6 +878,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } elseif ($processorType == 'PayPal_Standard') { $processorSettings = array( + 'user_name' => 'V18ki@9r5Bf.org', 'test_user_name' => 'V18ki@9r5Bf.org', ); } diff --git a/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php b/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php index 0641939c38..eda26ef030 100644 --- a/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php +++ b/tests/phpunit/WebTest/Member/OnlineMembershipCreateTest.php @@ -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, $amountSection = TRUE) { + 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 @@ -242,24 +242,30 @@ 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 && $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"); + + 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"); @@ -409,59 +415,74 @@ class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase { $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, + $processors = array( + 'Test Processor', + 'AuthNet', + 'PayPal', + 'PayPal_Standard', ); - $this->webtestVerifyTabularData($expected); + 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"); + //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"); + $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', - ); + //View Membership Record + $verifyData = array( + 'Member' => $firstName . ' ' . $lastName, + 'Membership Type' => $memTypeTitle, + 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, + 'Status' => 'New', + ); - $this->webtestVerifyTabularData($verifyData); + $this->webtestVerifyTabularData($verifyData); + } } } -- 2.25.1