| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
| 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 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Member_OnlineAutoRenewMembershipTest |
| 31 | */ |
| 32 | class WebTest_Member_OnlineAutoRenewMembershipTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testOnlineAutoRenewMembershipAnonymous() { |
| 39 | //configure membership signup page. |
| 40 | $pageId = $this->_configureMembershipPage(); |
| 41 | |
| 42 | //now do the test membership signup. |
| 43 | $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom"); |
| 44 | |
| 45 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]"); |
| 46 | |
| 47 | $this->click("auto_renew"); |
| 48 | |
| 49 | $this->webtestAddCreditCardDetails(); |
| 50 | |
| 51 | list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails(); |
| 52 | |
| 53 | $this->type('email-5', "{$lastName}@example.com"); |
| 54 | |
| 55 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 56 | |
| 57 | $text = 'I want this membership to be renewed automatically every 1 year(s).'; |
| 58 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[2]", $text, 'Missing text: ' . $text); |
| 59 | |
| 60 | $this->click("_qf_Confirm_next-bottom"); |
| 61 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 62 | |
| 63 | $text = 'This membership will be renewed automatically every year.'; |
| 64 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[3]", $text, 'Missing text: ' . $text); |
| 65 | } |
| 66 | |
| 67 | public function testOnlineAutoRenewMembershipAuthenticated() { |
| 68 | //configure membership signup page. |
| 69 | $pageId = $this->_configureMembershipPage(); |
| 70 | |
| 71 | $this->webtestLogin(); |
| 72 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 73 | |
| 74 | //now do the test membership signup. |
| 75 | $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom"); |
| 76 | |
| 77 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]"); |
| 78 | |
| 79 | $this->click("auto_renew"); |
| 80 | |
| 81 | $this->webtestAddCreditCardDetails(); |
| 82 | |
| 83 | list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails(); |
| 84 | |
| 85 | $this->type('email-5', "{$lastName}@example.com"); |
| 86 | |
| 87 | $this->click("_qf_Main_upload-bottom"); |
| 88 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); |
| 89 | |
| 90 | $text = 'I want this membership to be renewed automatically every 1 year(s).'; |
| 91 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[2]", $text, 'Missing text: ' . $text); |
| 92 | |
| 93 | $this->click("_qf_Confirm_next-bottom"); |
| 94 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 95 | |
| 96 | $text = 'This membership will be renewed automatically every year.'; |
| 97 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[3]", $text, 'Missing text: ' . $text); |
| 98 | } |
| 99 | |
| 100 | public function testOnlinePendingAutoRenewMembershipAnonymous() { |
| 101 | //configure membership signup page. |
| 102 | $pageId = $this->_configureMembershipPage(); |
| 103 | |
| 104 | //now do the test membership signup. |
| 105 | $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom"); |
| 106 | |
| 107 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]/div[2]/span/label/span[1][contains(text(),'Student')]"); |
| 108 | |
| 109 | $this->click("auto_renew"); |
| 110 | |
| 111 | $this->webtestAddCreditCardDetails(); |
| 112 | list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails(); |
| 113 | $this->type('email-5', "{$lastName}@example.com"); |
| 114 | |
| 115 | $this->click("_qf_Main_upload-bottom"); |
| 116 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); |
| 117 | |
| 118 | $text = 'I want this membership to be renewed automatically every 1 year(s).'; |
| 119 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[2]", $text, 'Missing text: ' . $text); |
| 120 | |
| 121 | $this->click("_qf_Confirm_next-bottom"); |
| 122 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 123 | |
| 124 | $text = 'This membership will be renewed automatically every year.'; |
| 125 | $this->assertElementContainsText("xpath=//div[@class='crm-group amount_display-group']/div[2]/strong[3]", $text, 'Missing text: ' . $text); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @return null |
| 130 | */ |
| 131 | public function _configureMembershipPage() { |
| 132 | static $pageId = NULL; |
| 133 | |
| 134 | if (!$pageId) { |
| 135 | $this->webtestLogin(); |
| 136 | |
| 137 | //add payment processor. |
| 138 | $hash = substr(sha1(rand()), 0, 7); |
| 139 | $rand = 2 * rand(2, 50); |
| 140 | $processorName = "Webtest Auto Renew AuthNet" . $hash; |
| 141 | $this->webtestAddPaymentProcessor($processorName, 'AuthNet'); |
| 142 | |
| 143 | // -- start updating membership types |
| 144 | $this->openCiviPage('admin/member/membershipType/add', "action=update&id=1&reset=1", "_qf_MembershipType_upload-bottom"); |
| 145 | |
| 146 | $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]"); |
| 147 | |
| 148 | $this->type("duration_interval", "1"); |
| 149 | $this->select("duration_unit", "label=year"); |
| 150 | |
| 151 | $this->click("_qf_MembershipType_upload-bottom"); |
| 152 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 153 | |
| 154 | $this->openCiviPage('admin/member/membershipType/add', "action=update&id=2&reset=1", "_qf_MembershipType_upload-bottom"); |
| 155 | |
| 156 | $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]"); |
| 157 | |
| 158 | $this->type("duration_interval", "1"); |
| 159 | $this->select("duration_unit", "label=year"); |
| 160 | |
| 161 | $this->click("_qf_MembershipType_upload-bottom"); |
| 162 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 163 | |
| 164 | // create contribution page with randomized title and default params |
| 165 | $amountSection = FALSE; |
| 166 | $payLater = TRUE; |
| 167 | $onBehalf = FALSE; |
| 168 | $pledges = FALSE; |
| 169 | $recurring = TRUE; |
| 170 | $membershipTypes = array( |
| 171 | array('id' => 1, 'auto_renew' => 1), |
| 172 | array('id' => 2, 'auto_renew' => 1), |
| 173 | ); |
| 174 | $memPriceSetId = NULL; |
| 175 | $friend = TRUE; |
| 176 | $profilePreId = NULL; |
| 177 | $profilePostId = NULL; |
| 178 | $premiums = TRUE; |
| 179 | $widget = TRUE; |
| 180 | $pcp = TRUE; |
| 181 | |
| 182 | $contributionTitle = "Title $hash"; |
| 183 | $pageId = $this->webtestAddContributionPage($hash, |
| 184 | $rand, |
| 185 | $contributionTitle, |
| 186 | array($processorName => 'AuthNet'), |
| 187 | $amountSection, |
| 188 | $payLater, |
| 189 | $onBehalf, |
| 190 | $pledges, |
| 191 | $recurring, |
| 192 | $membershipTypes, |
| 193 | $memPriceSetId, |
| 194 | $friend, |
| 195 | $profilePreId, |
| 196 | $profilePostId, |
| 197 | $premiums, |
| 198 | $widget, |
| 199 | $pcp, |
| 200 | FALSE |
| 201 | ); |
| 202 | |
| 203 | //make sure we do have required permissions. |
| 204 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
| 205 | $this->changePermissions($permissions); |
| 206 | |
| 207 | // now logout and do membership test that way |
| 208 | $this->webtestLogout(); |
| 209 | } |
| 210 | |
| 211 | return $pageId; |
| 212 | } |
| 213 | |
| 214 | } |