| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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_OnlineMembershipCreateTest |
| 31 | */ |
| 32 | class WebTest_Member_OnlineMembershipCreateTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | function testOnlineMembershipCreate() { |
| 39 | //check for online contribution and profile listings permissions |
| 40 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
| 41 | $this->changePermissions($permissions); |
| 42 | |
| 43 | // Log in as normal user |
| 44 | $this->webtestLogin(); |
| 45 | |
| 46 | // a random 7-char string and an even number to make this pass unique |
| 47 | $hash = substr(sha1(rand()), 0, 7); |
| 48 | $rand = 2 * rand(2, 50); |
| 49 | |
| 50 | // Use default payment processor |
| 51 | $processorName = 'Test Processor'; |
| 52 | |
| 53 | // create contribution page with randomized title and default params |
| 54 | $amountSection = TRUE; |
| 55 | $payLater = TRUE; |
| 56 | $allowOtherAmmount = FALSE; |
| 57 | $onBehalf = FALSE; |
| 58 | $pledges = FALSE; |
| 59 | $recurring = FALSE; |
| 60 | $memberships = TRUE; |
| 61 | $memPriceSetId = NULL; |
| 62 | $friend = TRUE; |
| 63 | $profilePreId = 1; |
| 64 | $profilePostId = NULL; |
| 65 | $premiums = TRUE; |
| 66 | $widget = FALSE; |
| 67 | $pcp = TRUE; |
| 68 | $isSeparatePayment = TRUE; |
| 69 | $contributionTitle = "Title $hash"; |
| 70 | $pageId = $this->webtestAddContributionPage($hash, |
| 71 | $rand, |
| 72 | $contributionTitle, |
| 73 | array($processorName => 'Dummy'), |
| 74 | $amountSection, |
| 75 | $payLater, |
| 76 | $onBehalf, |
| 77 | $pledges, |
| 78 | $recurring, |
| 79 | $memberships, |
| 80 | $memPriceSetId, |
| 81 | $friend, |
| 82 | $profilePreId, |
| 83 | $profilePostId, |
| 84 | $premiums, |
| 85 | $widget, |
| 86 | $pcp, |
| 87 | TRUE, |
| 88 | FALSE, |
| 89 | $isSeparatePayment, |
| 90 | TRUE, |
| 91 | FALSE |
| 92 | ); |
| 93 | |
| 94 | // create two new membership types |
| 95 | $memTypeParams1 = $this->webtestAddMembershipType(); |
| 96 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
| 97 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
| 98 | $memTypeId1 = $memTypeId1[1]; |
| 99 | |
| 100 | $memTypeParams2 = $this->webtestAddMembershipType(); |
| 101 | $memTypeTitle2 = $memTypeParams2['membership_type']; |
| 102 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href")); |
| 103 | $memTypeId2 = $memTypeId2[1]; |
| 104 | |
| 105 | // edit contribution page memberships tab to add two new membership types |
| 106 | $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom'); |
| 107 | $this->click("membership_type_$memTypeId1"); |
| 108 | $this->click("membership_type_$memTypeId2"); |
| 109 | $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom'); |
| 110 | $text = "'MembershipBlock' information has been saved."; |
| 111 | $this->waitForText('crm-notification-container', $text); |
| 112 | |
| 113 | //logout |
| 114 | $this->webtestLogout(); |
| 115 | |
| 116 | // signup for membership 1 |
| 117 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
| 118 | $lastName = 'An' . substr(sha1(rand()), 0, 7); |
| 119 | |
| 120 | $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash); |
| 121 | |
| 122 | // Log in using webtestLogin() method |
| 123 | $this->webtestLogin(); |
| 124 | |
| 125 | //Find Member |
| 126 | $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); |
| 127 | |
| 128 | $this->type("sort_name", "$firstName $lastName"); |
| 129 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr"); |
| 130 | $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']"); |
| 131 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 132 | |
| 133 | //View Membership Record |
| 134 | $verifyData = array( |
| 135 | 'Member' => $firstName . ' ' . $lastName, |
| 136 | 'Membership Type' => $memTypeTitle1, |
| 137 | 'Source' => 'Online Contribution:' . ' ' . $contributionTitle, |
| 138 | ); |
| 139 | if ($payLater) { |
| 140 | $verifyData['Status'] = 'Pending'; |
| 141 | } |
| 142 | else { |
| 143 | |
| 144 | $verifyData['Status'] = 'New'; |
| 145 | } |
| 146 | $this->webtestVerifyTabularData($verifyData); |
| 147 | |
| 148 | // Click View action link on associated contribution record |
| 149 | $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']"); |
| 150 | $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[1][text()='View']"); |
| 151 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]"); |
| 152 | //View Contribution Record |
| 153 | $verifyData = array( |
| 154 | 'From' => $firstName . ' ' . $lastName, |
| 155 | 'Total Amount' => '$ 100.00', |
| 156 | ); |
| 157 | if ($payLater) { |
| 158 | $verifyData['Contribution Status'] = 'Pending : Pay Later'; |
| 159 | } |
| 160 | else { |
| 161 | $verifyData['Contribution Status'] = 'Completed'; |
| 162 | } |
| 163 | $this->webtestVerifyTabularData($verifyData); |
| 164 | |
| 165 | // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different) |
| 166 | //logout |
| 167 | $this->webtestLogout(); |
| 168 | |
| 169 | $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash); |
| 170 | |
| 171 | // Log in using webtestLogin() method |
| 172 | $this->webtestLogin(); |
| 173 | |
| 174 | //Find Member |
| 175 | $this->openCiviPage("member/search", "reset=1", "member_end_date_high"); |
| 176 | |
| 177 | $this->type("sort_name", "$firstName $lastName"); |
| 178 | $this->click("_qf_Search_refresh"); |
| 179 | |
| 180 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 181 | $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results'); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @param int $pageId |
| 186 | * @param int $memTypeId |
| 187 | * @param string $firstName |
| 188 | * @param string $lastName |
| 189 | * @param $payLater |
| 190 | * @param $hash |
| 191 | * @param bool $otherAmount |
| 192 | */ |
| 193 | function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) { |
| 194 | //Open Live Contribution Page |
| 195 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); |
| 196 | // Select membership type 1 |
| 197 | $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label"); |
| 198 | if ($memTypeId != 'No thank you') { |
| 199 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]"); |
| 200 | } |
| 201 | |
| 202 | else { |
| 203 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]"); |
| 204 | |
| 205 | } |
| 206 | if (!$otherAmount) { |
| 207 | $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']"); |
| 208 | } |
| 209 | else { |
| 210 | $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount); |
| 211 | } |
| 212 | if ($payLater) { |
| 213 | $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']"); |
| 214 | } |
| 215 | $this->type("email-5", $firstName . "@example.com"); |
| 216 | $this->waitForElementPresent("first_name"); |
| 217 | $this->type("first_name", $firstName); |
| 218 | $this->waitForElementPresent("last_name"); |
| 219 | $this->type("last_name", $lastName); |
| 220 | |
| 221 | $streetAddress = "100 Main Street"; |
| 222 | $this->waitForElementPresent("street_address-1"); |
| 223 | $this->type("street_address-1", $streetAddress); |
| 224 | $this->type("city-1", "San Francisco"); |
| 225 | $this->type("postal_code-1", "94117"); |
| 226 | $this->select("country-1", "value=1228"); |
| 227 | $this->select("state_province-1", "value=1001"); |
| 228 | if (!$payLater) { |
| 229 | //Credit Card Info |
| 230 | $this->select("credit_card_type", "value=Visa"); |
| 231 | $this->type("credit_card_number", "4111111111111111"); |
| 232 | $this->type("cvv2", "000"); |
| 233 | $this->select("credit_card_exp_date[M]", "value=1"); |
| 234 | $this->select("credit_card_exp_date[Y]", "value=2020"); |
| 235 | |
| 236 | //Billing Info |
| 237 | $this->waitForElementPresent("billing_first_name"); |
| 238 | $this->type("billing_first_name", $firstName . "billing"); |
| 239 | $this->waitForElementPresent("billing_last_name"); |
| 240 | $this->type("billing_last_name", $lastName . "billing"); |
| 241 | $this->type("billing_street_address-5", "15 Main St."); |
| 242 | $this->type(" billing_city-5", "San Jose"); |
| 243 | $this->select("billing_country_id-5", "value=1228"); |
| 244 | $this->select("billing_state_province_id-5", "value=1004"); |
| 245 | $this->type("billing_postal_code-5", "94129"); |
| 246 | } |
| 247 | $this->click("_qf_Main_upload-bottom"); |
| 248 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); |
| 249 | |
| 250 | $this->click("_qf_Confirm_next-bottom"); |
| 251 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 252 | } |
| 253 | |
| 254 | function testOnlineMembershipCreateWithContribution() { |
| 255 | //login with admin credentials & make sure we do have required permissions. |
| 256 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
| 257 | $this->changePermissions($permissions); |
| 258 | |
| 259 | $hash = substr(sha1(rand()), 0, 7); |
| 260 | $rand = 2 * rand(2, 50); |
| 261 | // Use default payment processor |
| 262 | $processorName = 'Test Processor'; |
| 263 | $amountSection = TRUE; |
| 264 | $payLater = TRUE; |
| 265 | $allowOtherAmmount = TRUE; |
| 266 | $onBehalf = FALSE; |
| 267 | $pledges = FALSE; |
| 268 | $recurring = FALSE; |
| 269 | $memberships = TRUE; |
| 270 | $memPriceSetId = NULL; |
| 271 | $friend = FALSE; |
| 272 | $profilePreId = 1; |
| 273 | $profilePostId = NULL; |
| 274 | $premiums = FALSE; |
| 275 | $widget = FALSE; |
| 276 | $pcp = FALSE; |
| 277 | $isSeparatePayment = FALSE; |
| 278 | $membershipsRequired = FALSE; |
| 279 | $fixedAmount = FALSE; |
| 280 | $contributionTitle = "Title $hash"; |
| 281 | $pageId = $this->webtestAddContributionPage($hash, |
| 282 | $rand, |
| 283 | $contributionTitle, |
| 284 | array($processorName => 'Dummy'), |
| 285 | $amountSection, |
| 286 | $payLater, |
| 287 | $onBehalf, |
| 288 | $pledges, |
| 289 | $recurring, |
| 290 | $memberships, |
| 291 | $memPriceSetId, |
| 292 | $friend, |
| 293 | $profilePreId, |
| 294 | $profilePostId, |
| 295 | $premiums, |
| 296 | $widget, |
| 297 | $pcp, |
| 298 | TRUE, |
| 299 | FALSE, |
| 300 | $isSeparatePayment, |
| 301 | TRUE, |
| 302 | $allowOtherAmmount, |
| 303 | TRUE, |
| 304 | 'Donation', |
| 305 | $fixedAmount, |
| 306 | $membershipsRequired |
| 307 | ); |
| 308 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
| 309 | $lastName = 'An' . substr(sha1(rand()), 0, 7); |
| 310 | |
| 311 | //logout |
| 312 | $this->webtestLogout(); |
| 313 | |
| 314 | $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50); |
| 315 | |
| 316 | // Log in using webtestLogin() method |
| 317 | $this->webtestLogin(); |
| 318 | |
| 319 | //Find Contribution |
| 320 | $this->openCiviPage("contribute/search","reset=1", "contribution_date_low"); |
| 321 | |
| 322 | $this->type("sort_name", "$firstName $lastName"); |
| 323 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 324 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
| 325 | |
| 326 | //View Contribution Record and verify data |
| 327 | $expected = array( |
| 328 | 'From' => "{$firstName} {$lastName}", |
| 329 | 'Financial Type' => 'Donation', |
| 330 | 'Total Amount' => '50.00', |
| 331 | 'Contribution Status' => 'Completed', |
| 332 | 'Received Into' => 'Deposit Bank Account', |
| 333 | 'Source' => "Online Contribution: $contributionTitle", |
| 334 | 'Online Contribution Page' => $contributionTitle, |
| 335 | ); |
| 336 | $this->webtestVerifyTabularData($expected); |
| 337 | } |
| 338 | } |