| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.3 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License along with this program; if not, contact CiviCRM LLC | |
| 21 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 22 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 24 | +--------------------------------------------------------------------+ |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 29 | class WebTest_Member_SeperateMembershipPaymentTest extends CiviSeleniumTestCase { |
| 30 | |
| 31 | protected function setUp() { |
| 32 | parent::setUp(); |
| 33 | } |
| 34 | |
| 35 | function testSeperateMembershipCreate() { |
| 36 | // a random 7-char string and an even number to make this pass unique |
| 37 | $hash = substr(sha1(rand()), 0, 7); |
| 38 | $rand = 2 * rand(2, 50); |
| 39 | // Log in using webtestLogin() method |
| 40 | $this->webtestLogin(); |
| 41 | |
| 42 | $firstName1 = 'Ma_' . substr(sha1(rand()), 0, 7); |
| 43 | $lastName1 = 'An_' . substr(sha1(rand()), 0, 7); |
| 44 | $this->webtestAddContact($firstName1, $lastName1, TRUE); |
| 45 | $this->assertElementContainsText('crm-notification-container', "$firstName1 $lastName1 has been created."); |
| 46 | $url = explode('&cid=', $this->getLocation()); |
| 47 | $cid = $url[1]; |
| 48 | |
| 49 | // create contribution page with randomized title and default params |
| 50 | $amountSection = TRUE; |
| 51 | $payLater = TRUE; |
| 52 | $onBehalf = FALSE; |
| 53 | $pledges = FALSE; |
| 54 | $recurring = FALSE; |
| 55 | $memberships = TRUE; |
| 56 | $memPriceSetId = NULL; |
| 57 | $friend = TRUE; |
| 58 | $profilePreId = NULL; |
| 59 | $profilePostId = NULL; |
| 60 | $premiums = FALSE; |
| 61 | $widget = FALSE; |
| 62 | $pcp = FALSE; |
| 63 | $isAddPaymentProcessor = FALSE; |
| 64 | $isSeparatePayment = TRUE; |
| 65 | |
| 66 | $contributionTitle = "Title $hash"; |
| 67 | $pageId = $this->webtestAddContributionPage($hash, |
| 68 | $rand, |
| 69 | $contributionTitle, |
| 70 | NULL, |
| 71 | $amountSection, |
| 72 | $payLater, |
| 73 | $onBehalf, |
| 74 | $pledges, |
| 75 | $recurring, |
| 76 | $memberships, |
| 77 | $memPriceSetId, |
| 78 | $friend, |
| 79 | $profilePreId, |
| 80 | $profilePostId, |
| 81 | $premiums, |
| 82 | $widget, |
| 83 | $pcp, |
| 84 | $isAddPaymentProcessor, |
| 85 | FALSE, |
| 86 | $isSeparatePayment, |
| 87 | FALSE |
| 88 | ); |
| 89 | |
| 90 | |
| 91 | // create new membership types |
| 92 | $memTypeParams1 = $this->webtestAddMembershipType(); |
| 93 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
| 94 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
| 95 | $memTypeId1 = $memTypeId1[1]; |
| 96 | |
| 97 | $memTypeParams2 = $this->webtestAddMembershipType(); |
| 98 | $memTypeTitle2 = $memTypeParams2['membership_type']; |
| 99 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href")); |
| 100 | $memTypeId2 = $memTypeId2[1]; |
| 101 | |
| 102 | // edit contribution page memberships tab to add two new membership types |
| 103 | $this->openCiviPage('admin/contribute/membership', "reset=1&action=update&id={$pageId}", "_qf_MembershipBlock_next-bottom"); |
| 104 | $this->click("membership_type_$memTypeId1"); |
| 105 | $this->click("membership_type_$memTypeId2"); |
| 106 | $this->click('_qf_MembershipBlock_next'); |
| 107 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 108 | $this->waitForElementPresent('_qf_MembershipBlock_next-bottom'); |
| 109 | $text = "'MembershipBlock' information has been saved."; |
| 110 | $this->assertElementContainsText('crm-notification-container', $text, 'Missing text: ' . $text); |
| 111 | $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $cid); |
| 112 | |
| 113 | //Find Member |
| 114 | $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high'); |
| 115 | $this->type("sort_name", "$firstName1 $lastName1"); |
| 116 | $this->click("_qf_Search_refresh"); |
| 117 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 118 | $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr"); |
| 119 | $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']"); |
| 120 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 121 | |
| 122 | //View Membership Record |
| 123 | $verifyData = array( |
| 124 | 'Member' => $firstName1 . ' ' . $lastName1, |
| 125 | 'Membership Type' => $memTypeTitle1, |
| 126 | 'Status' => 'Pending', |
| 127 | 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, |
| 128 | ); |
| 129 | |
| 130 | $this->webtestVerifyTabularData($verifyData); |
| 131 | |
| 132 | // Click View action link on associated contribution record |
| 133 | $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 134 | $this->click("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']"); |
| 135 | $this->waitForElementPresent("_qf_ContributionView_cancel-bottom"); |
| 136 | |
| 137 | //View Contribution Record |
| 138 | $verifyData = array( |
| 139 | 'From' => $firstName1 . ' ' . $lastName1, |
| 140 | 'Total Amount' => '$ 100.00', |
| 141 | ); |
| 142 | $this->webtestVerifyTabularData($verifyData); |
| 143 | |
| 144 | $this->click("_qf_ContributionView_cancel-bottom"); |
| 145 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 146 | } |
| 147 | |
| 148 | function _testOnlineMembershipSignup($pageId, $memTypeId, $cid = NULL) { |
| 149 | //Open Live Contribution Page |
| 150 | $args = array('reset' => 1, 'id' => $pageId); |
| 151 | if ($cid) { |
| 152 | $args['cid'] = $cid; |
| 153 | } |
| 154 | $this->openCiviPage("contribute/transact", $args, '_qf_Main_upload-bottom'); |
| 155 | |
| 156 | // Select membership type 1 |
| 157 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]"); |
| 158 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 60); |
| 159 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 160 | $this->clickLink("_qf_Confirm_next-bottom", NULL); |
| 161 | } |
| 162 | } |