| 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 | class WebTest_Member_OfflineMembershipRenewTest extends CiviSeleniumTestCase { |
| 29 | |
| 30 | protected function setUp() { |
| 31 | parent::setUp(); |
| 32 | } |
| 33 | |
| 34 | function testOfflineMembershipRenew() { |
| 35 | $this->webtestLogin(); |
| 36 | |
| 37 | // make sure period is correct for the membership type we testing for, |
| 38 | // since it might have been modified by other tests |
| 39 | // add membership type |
| 40 | $membershipTypes = $this->webtestAddMembershipType('rolling', 2); |
| 41 | |
| 42 | // quick create a contact |
| 43 | $firstName = substr(sha1(rand()), 0, 7); |
| 44 | $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com"); |
| 45 | $contactName = "$firstName Memberson"; |
| 46 | |
| 47 | // click through to the membership tab |
| 48 | $this->click('css=li#tab_member a'); |
| 49 | |
| 50 | $this->waitForElementPresent('link=Add Membership'); |
| 51 | $this->click('link=Add Membership'); |
| 52 | |
| 53 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 54 | |
| 55 | // fill in Membership Organization and Type |
| 56 | $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}"); |
| 57 | $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}"); |
| 58 | |
| 59 | // fill in Source |
| 60 | $sourceText = 'Offline Membership Renewal Webtest'; |
| 61 | $this->type('source', $sourceText); |
| 62 | |
| 63 | // Fill Member Since |
| 64 | $this->webtestFillDate('join_date', '-2 year'); |
| 65 | |
| 66 | // Let Start Date and End Date be auto computed |
| 67 | |
| 68 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 69 | // Sleep should never be used for wait for anything to load from the server |
| 70 | // Justification for this instance: make sure onchange for total_amount has a chance to fire |
| 71 | sleep(2); |
| 72 | |
| 73 | // Clicking save. |
| 74 | $this->click('_qf_Membership_upload-bottom'); |
| 75 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 76 | |
| 77 | // page was loaded |
| 78 | $this->waitForTextPresent($sourceText); |
| 79 | |
| 80 | // Is status message correct? |
| 81 | $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."); |
| 82 | |
| 83 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 84 | |
| 85 | // click through to the Membership Renewal Link |
| 86 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 87 | |
| 88 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
| 89 | |
| 90 | // save the renewed membership |
| 91 | $this->click('_qf_MembershipRenewal_upload-bottom'); |
| 92 | |
| 93 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 94 | |
| 95 | // page was loaded |
| 96 | $this->waitForTextPresent($sourceText); |
| 97 | |
| 98 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 99 | |
| 100 | // click through to the membership view screen |
| 101 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 102 | |
| 103 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); |
| 104 | |
| 105 | $joinDate = $startDate = date('F jS, Y', strtotime("-2 year")); |
| 106 | $endDate = date('F jS, Y', strtotime("+2 year -1 day")); |
| 107 | |
| 108 | // verify membership renewed |
| 109 | $verifyMembershipRenewData = array( |
| 110 | 'Member' => $contactName, |
| 111 | 'Membership Type' => $membershipTypes['membership_type'], |
| 112 | 'Status' => 'Current', |
| 113 | 'Source' => $sourceText, |
| 114 | 'Member Since' => $joinDate, |
| 115 | 'Start date' => $startDate, |
| 116 | 'End date' => $endDate, |
| 117 | ); |
| 118 | $this->webtestVerifyTabularData($verifyMembershipRenewData); |
| 119 | } |
| 120 | |
| 121 | function testOfflineMemberRenewOverride() { |
| 122 | $this->webtestLogin(); |
| 123 | |
| 124 | // add membership type |
| 125 | $membershipTypes = $this->webtestAddMembershipType('rolling', 2); |
| 126 | |
| 127 | $firstName = substr(sha1(rand()), 0, 7); |
| 128 | $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com"); |
| 129 | $contactName = "$firstName Memberson"; |
| 130 | |
| 131 | // click through to the membership tab |
| 132 | $this->click('css=li#tab_member a'); |
| 133 | |
| 134 | $this->waitForElementPresent('link=Add Membership'); |
| 135 | $this->click('link=Add Membership'); |
| 136 | |
| 137 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 138 | |
| 139 | // fill in Membership Organization and Type |
| 140 | $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}"); |
| 141 | $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}"); |
| 142 | |
| 143 | // fill in Source |
| 144 | $sourceText = 'Offline Membership Renewal Webtest'; |
| 145 | $this->type('source', $sourceText); |
| 146 | |
| 147 | // Let Join Date stay default |
| 148 | |
| 149 | // fill in Start Date |
| 150 | $this->webtestFillDate('start_date'); |
| 151 | |
| 152 | // Let End Date be auto computed |
| 153 | |
| 154 | // fill in Status Override? |
| 155 | $this->click('is_override', 'value=1'); |
| 156 | $this->waitForElementPresent('status_id'); |
| 157 | $this->select('status_id', 'value=3'); |
| 158 | |
| 159 | // fill in Record Membership Payment? |
| 160 | $this->click('record_contribution', 'value=1'); |
| 161 | $this->waitForElementPresent('contribution_status_id'); |
| 162 | |
| 163 | // select the financial type for the selected membership type |
| 164 | $this->select('financial_type_id', 'value=2'); |
| 165 | |
| 166 | // the amount for the selected membership type |
| 167 | $this->type('total_amount', '100.00'); |
| 168 | |
| 169 | // select payment instrument type = Check and enter chk number |
| 170 | $this->select("payment_instrument_id", "value=4"); |
| 171 | $this->waitForElementPresent("check_number"); |
| 172 | $this->type("check_number", "check #12345"); |
| 173 | $this->type("trxn_id", "P5476785" . rand(100, 10000)); |
| 174 | |
| 175 | // fill the payment status be default |
| 176 | $this->select("contribution_status_id", "value=2"); |
| 177 | |
| 178 | // Clicking save. |
| 179 | $this->click('_qf_Membership_upload-bottom'); |
| 180 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 181 | |
| 182 | // page was loaded |
| 183 | $this->waitForTextPresent($sourceText); |
| 184 | |
| 185 | // Is status message correct? |
| 186 | $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."); |
| 187 | |
| 188 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 189 | |
| 190 | // click through to the Membership Renewal Link |
| 191 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 192 | |
| 193 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
| 194 | |
| 195 | // save the renewed membership |
| 196 | $this->click('_qf_MembershipRenewal_upload-bottom'); |
| 197 | |
| 198 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 199 | |
| 200 | // page was loaded |
| 201 | $this->waitForTextPresent($sourceText); |
| 202 | |
| 203 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 204 | |
| 205 | // click through to the membership view screen |
| 206 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 207 | |
| 208 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); |
| 209 | |
| 210 | $joinDate = date('F jS, Y'); |
| 211 | $startDate = date('F jS, Y', strtotime("+1 month")); |
| 212 | $endDate = date('F jS, Y', strtotime("+4 year 1 month -1 day")); |
| 213 | |
| 214 | // verify membership renew override |
| 215 | $verifyMembershipRenewOverrideData = array( |
| 216 | 'Member' => $contactName, |
| 217 | 'Membership Type' => $membershipTypes['membership_type'], |
| 218 | 'Status' => 'New', |
| 219 | 'Source' => $sourceText, |
| 220 | 'Member Since' => $joinDate, |
| 221 | 'Start date' => $startDate, |
| 222 | 'End date' => $endDate, |
| 223 | ); |
| 224 | $this->webtestVerifyTabularData($verifyMembershipRenewOverrideData); |
| 225 | } |
| 226 | |
| 227 | function testOfflineMembershipRenewChangeType() { |
| 228 | $this->webtestLogin(); |
| 229 | |
| 230 | // make sure period is correct for the membership type we testing for, |
| 231 | // since it might have been modified by other tests |
| 232 | // add membership type |
| 233 | $membershipTypes = $this->webtestAddMembershipType('rolling', 1); |
| 234 | $newMembershipType = $this->webtestAddMembershipType('rolling', 1); |
| 235 | |
| 236 | $firstName = substr(sha1(rand()), 0, 7); |
| 237 | $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com"); |
| 238 | $contactName = "$firstName Memberson"; |
| 239 | |
| 240 | // click through to the membership tab |
| 241 | $this->click('css=li#tab_member a'); |
| 242 | |
| 243 | $this->waitForElementPresent('link=Add Membership'); |
| 244 | $this->click('link=Add Membership'); |
| 245 | |
| 246 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 247 | |
| 248 | // fill in Membership Organization and Type |
| 249 | $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}"); |
| 250 | $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}"); |
| 251 | |
| 252 | // fill in Source |
| 253 | $sourceText = 'Offline Membership Renewal Webtest'; |
| 254 | $this->type('source', $sourceText); |
| 255 | |
| 256 | // Fill Member Since |
| 257 | $this->webtestFillDate('join_date', '-2 year'); |
| 258 | |
| 259 | // Let Start Date and End Date be auto computed |
| 260 | |
| 261 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 262 | // Sleep should never be used for wait for anything to load from the server |
| 263 | // Justification for this instance: make sure onchange for total_amount has a chance to fire |
| 264 | sleep(2); |
| 265 | |
| 266 | // Clicking save. |
| 267 | $this->click('_qf_Membership_upload-bottom'); |
| 268 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 269 | |
| 270 | // page was loaded |
| 271 | $this->waitForTextPresent($sourceText); |
| 272 | |
| 273 | // Is status message correct? |
| 274 | $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."); |
| 275 | |
| 276 | $this->waitForElementPresent("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 277 | |
| 278 | // click through to the Membership Renewal Link |
| 279 | $this->click("xpath=//div[@id='inactive-memberships']//table/tbody/tr/td[7]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 280 | |
| 281 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
| 282 | |
| 283 | //change membership type |
| 284 | $this->click("changeMembershipOrgType"); |
| 285 | $this->waitForElementPresent('membership_type_id[1]'); |
| 286 | $this->select('membership_type_id[0]', "label={$newMembershipType['member_of_contact']}"); |
| 287 | $this->select('membership_type_id[1]', "label={$newMembershipType['membership_type']}"); |
| 288 | |
| 289 | $this->click('membership_type_id[0]'); |
| 290 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 291 | // Sleep should never be used for wait for anything to load from the server |
| 292 | // Justification for this instance: wait for onchange handler |
| 293 | sleep(2); |
| 294 | |
| 295 | // save the renewed membership |
| 296 | $this->click('_qf_MembershipRenewal_upload-bottom'); |
| 297 | |
| 298 | |
| 299 | // page was loaded |
| 300 | $this->waitForTextPresent($sourceText); |
| 301 | |
| 302 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 303 | |
| 304 | // click through to the membership view screen |
| 305 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 306 | |
| 307 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); |
| 308 | |
| 309 | $joinDate = date('F jS, Y', strtotime("-2 year")); |
| 310 | $startDate = date('F jS, Y'); |
| 311 | $endDate = date('F jS, Y', strtotime("+1 year -1 day")); |
| 312 | |
| 313 | // verify membership renewed and the membership type is changed |
| 314 | $verifyMembershipData = array( |
| 315 | 'Member' => $contactName, |
| 316 | 'Membership Type' => $newMembershipType['membership_type'], |
| 317 | 'Status' => 'Current', |
| 318 | 'Source' => $sourceText, |
| 319 | 'Member Since' => $joinDate, |
| 320 | 'Start date' => $startDate, |
| 321 | 'End date' => $endDate, |
| 322 | ); |
| 323 | $this->webtestVerifyTabularData($verifyMembershipData); |
| 324 | } |
| 325 | |
| 326 | function testOfflineMembershipRenewMultipleTerms() { |
| 327 | $this->webtestLogin(); |
| 328 | |
| 329 | // make sure period is correct for the membership type we testing for, |
| 330 | // since it might have been modified by other tests |
| 331 | // add membership type |
| 332 | $membershipTypes = $this->webtestAddMembershipType('rolling', 2); |
| 333 | |
| 334 | // quick create a contact |
| 335 | $firstName = substr(sha1(rand()), 0, 7); |
| 336 | $this->webtestAddContact($firstName, "Memberson", "{$firstName}@memberson.com"); |
| 337 | $contactName = "$firstName Memberson"; |
| 338 | |
| 339 | // click through to the membership tab |
| 340 | $this->click('css=li#tab_member a'); |
| 341 | |
| 342 | $this->waitForElementPresent('link=Add Membership'); |
| 343 | $this->click('link=Add Membership'); |
| 344 | |
| 345 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 346 | |
| 347 | // fill in Membership Organization and Type |
| 348 | $this->select('membership_type_id[0]', "label={$membershipTypes['member_of_contact']}"); |
| 349 | $this->select('membership_type_id[1]', "label={$membershipTypes['membership_type']}"); |
| 350 | |
| 351 | // fill in Source |
| 352 | $sourceText = 'Offline Membership Renewal Webtest'; |
| 353 | $this->type('source', $sourceText); |
| 354 | |
| 355 | // Fill Member Since |
| 356 | $this->webtestFillDate('join_date', '-2 year'); |
| 357 | |
| 358 | // Let Start Date and End Date be auto computed |
| 359 | |
| 360 | // Record contribution |
| 361 | $this->click('record_contribution'); |
| 362 | $this->waitForElementPresent( 'financial_type_id' ); |
| 363 | $this->select( 'financial_type_id', "label=Member Dues" ); |
| 364 | $this->select('payment_instrument_id', "label=Check"); |
| 365 | $this->waitForElementPresent('check_number'); |
| 366 | $this->type('check_number', '1023'); |
| 367 | $this->select('contribution_status_id', "label=Completed"); |
| 368 | $this->click('send_receipt'); |
| 369 | |
| 370 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 371 | // Sleep should never be used for wait for anything to load from the server |
| 372 | // Justification for this instance: make sure onchange for total_amount has a chance to fire |
| 373 | sleep(2); |
| 374 | |
| 375 | // Clicking save. |
| 376 | $this->click('_qf_Membership_upload-bottom'); |
| 377 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 378 | |
| 379 | // page was loaded |
| 380 | $this->waitForTextPresent($sourceText); |
| 381 | |
| 382 | // Is status message correct? |
| 383 | $this->waitForText('crm-notification-container', "{$membershipTypes['membership_type']} membership for $firstName Memberson has been added."); |
| 384 | $this->waitForText('crm-notification-container', "A membership confirmation and receipt has been sent to {$firstName}@memberson.com."); |
| 385 | |
| 386 | |
| 387 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 388 | // click through to the Membership Renewal Link |
| 389 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
| 390 | |
| 391 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
| 392 | // Record contribution and set number of terms to 2 |
| 393 | $this->click('record_contribution'); |
| 394 | $this->waitForElementPresent('financial_type_id'); |
| 395 | $this->click('changeTermsLink'); |
| 396 | $this->waitForElementPresent('num_terms'); |
| 397 | $this->type('num_terms', ''); |
| 398 | $this->type('num_terms', '2'); |
| 399 | |
| 400 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 401 | // Sleep should never be used for wait for anything to load from the server |
| 402 | // Justification for this instance: make sure onchange for total_amount has a chance to fire |
| 403 | sleep(2); |
| 404 | $this->click('total_amount'); |
| 405 | $this->verifyValue('total_amount', "200.00"); |
| 406 | $this->select('financial_type_id', "label=Member Dues"); |
| 407 | $this->select('payment_instrument_id', "label=Check"); |
| 408 | $this->waitForElementPresent('check_number'); |
| 409 | $this->type('check_number', '1024'); |
| 410 | $this->select('contribution_status_id', "label=Completed"); |
| 411 | $this->click('send_receipt'); |
| 412 | |
| 413 | // save the renewed membership |
| 414 | $this->click('_qf_MembershipRenewal_upload-bottom'); |
| 415 | |
| 416 | |
| 417 | // page was loaded |
| 418 | $this->waitForTextPresent($sourceText); |
| 419 | |
| 420 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 421 | |
| 422 | // click through to the membership view screen |
| 423 | $this->click("xpath=//div[@id='memberships']//table/tbody/tr/td[9]/span/a[text()='View']"); |
| 424 | |
| 425 | $this->waitForElementPresent('_qf_MembershipView_cancel-bottom'); |
| 426 | |
| 427 | $joinDate = $startDate = date('F jS, Y', strtotime("-2 year")); |
| 428 | // Adding 2 x 2 years renewal to initial membership. |
| 429 | $endDate = date('F jS, Y', strtotime("+4 year -1 day")); |
| 430 | |
| 431 | // verify membership renewed |
| 432 | $verifyMembershipRenewData = array( |
| 433 | 'Member' => $contactName, |
| 434 | 'Membership Type' => $membershipTypes['membership_type'], |
| 435 | 'Status' => 'Current', |
| 436 | 'Source' => $sourceText, |
| 437 | 'Member Since' => $joinDate, |
| 438 | 'Start date' => $startDate, |
| 439 | 'End date' => $endDate, |
| 440 | ); |
| 441 | $this->webtestVerifyTabularData($verifyMembershipRenewData); |
| 442 | } |
| 443 | } |