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