| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 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_FixedMembershipTypeTest |
| 31 | */ |
| 32 | class WebTest_Member_FixedMembershipTypeTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testMembershipTypeScenario1() { |
| 39 | // Scenario 1 |
| 40 | // Rollover Date < Start Date |
| 41 | // Join Date > Rollover Date and Join Date < Start Date |
| 42 | |
| 43 | // Log in using webtestLogin() method |
| 44 | $this->webtestLogin(); |
| 45 | |
| 46 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
| 47 | |
| 48 | $title = substr(sha1(rand()), 0, 7); |
| 49 | $this->type('organization_name', "Organization $title"); |
| 50 | $this->type('email_1_email', "$title@org.com"); |
| 51 | $this->click('_qf_Contact_upload_view'); |
| 52 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 53 | |
| 54 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); |
| 55 | |
| 56 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
| 57 | |
| 58 | $this->click("link=Add Membership Type"); |
| 59 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); |
| 60 | |
| 61 | $this->type('name', "Membership Type $title"); |
| 62 | $this->select2('member_of_contact_id', $title); |
| 63 | |
| 64 | $this->type('minimum_fee', '100'); |
| 65 | $this->select('financial_type_id', 'value=2'); |
| 66 | $this->type('duration_interval', 1); |
| 67 | $this->select('duration_unit', "label=year"); |
| 68 | |
| 69 | $this->select('period_type', "value=fixed"); |
| 70 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
| 71 | |
| 72 | // fixed period start set to April 1 |
| 73 | $this->select('fixed_period_start_day[M]', 'value=4'); |
| 74 | // rollover date set to Jan 31 |
| 75 | $this->select('fixed_period_rollover_day[M]', 'value=1'); |
| 76 | |
| 77 | $this->click('relationship_type_id', 'value=4_b_a'); |
| 78 | |
| 79 | $this->click('_qf_MembershipType_upload-bottom'); |
| 80 | $this->waitForElementPresent('link=Add Membership Type'); |
| 81 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
| 82 | |
| 83 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 84 | |
| 85 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 86 | |
| 87 | //fill in first name |
| 88 | $this->type('first_name', $firstName); |
| 89 | |
| 90 | //fill in last name |
| 91 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; |
| 92 | $this->type('last_name', $lastName); |
| 93 | |
| 94 | //fill in email |
| 95 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 96 | $this->type('email_1_email', $email); |
| 97 | |
| 98 | // Clicking save. |
| 99 | $this->click('_qf_Contact_upload_view'); |
| 100 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 101 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); |
| 102 | |
| 103 | // click through to the membership view screen |
| 104 | $this->click('css=li#tab_member a'); |
| 105 | |
| 106 | $this->waitForElementPresent('link=Add Membership'); |
| 107 | $this->click('link=Add Membership'); |
| 108 | |
| 109 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 110 | |
| 111 | // fill in Membership Organization and Type |
| 112 | $this->select('membership_type_id[0]', "label=Organization $title"); |
| 113 | $this->select('membership_type_id[1]', "label=Membership Type $title"); |
| 114 | |
| 115 | $sourceText = "Membership ContactAddTest with Fixed Membership Type"; |
| 116 | // fill in Source |
| 117 | $this->type('source', $sourceText); |
| 118 | |
| 119 | //build the membership dates. |
| 120 | require_once 'CRM/Core/Config.php'; |
| 121 | require_once 'CRM/Utils/Array.php'; |
| 122 | require_once 'CRM/Utils/Date.php'; |
| 123 | $currentYear = date('Y'); |
| 124 | $currentMonth = date('m'); |
| 125 | $previousYear = $currentYear - 1; |
| 126 | $nextYear = $currentYear + 1; |
| 127 | |
| 128 | $todayDate = date('Y-m-d'); |
| 129 | |
| 130 | // the member-since date we will type in to membership form |
| 131 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 3, 25, $currentYear)); |
| 132 | |
| 133 | // expected calc'd start date |
| 134 | $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear)); |
| 135 | |
| 136 | // expected calc'd end date |
| 137 | $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear)); |
| 138 | |
| 139 | foreach (array( |
| 140 | 'joinDate', |
| 141 | 'startDate', |
| 142 | 'endDate', |
| 143 | ) as $date) { |
| 144 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
| 145 | } |
| 146 | |
| 147 | $query = " |
| 148 | SELECT end_event_adjust_interval |
| 149 | |
| 150 | FROM civicrm_membership_status |
| 151 | |
| 152 | WHERE start_event = 'join_date' |
| 153 | AND name = 'New'"; |
| 154 | $endInterval = CRM_Core_DAO::singleValueQuery($query); |
| 155 | |
| 156 | // Add endInterval to March 25 (join date month above) to get end of New status period |
| 157 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 3, 25, $currentYear)); |
| 158 | |
| 159 | $status = 'Current'; |
| 160 | // status will be 'New' if today is >= join date and <= endNewStatus date |
| 161 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { |
| 162 | $status = 'New'; |
| 163 | } |
| 164 | |
| 165 | // fill in Join Date |
| 166 | $this->webtestFillDate('join_date', $joinDate); |
| 167 | |
| 168 | // Clicking save. |
| 169 | $this->click('_qf_Membership_upload'); |
| 170 | |
| 171 | // page was loaded |
| 172 | $this->waitForTextPresent($sourceText); |
| 173 | |
| 174 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 175 | // Is status message correct? |
| 176 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), |
| 177 | "Status message didn't show up after saving!" |
| 178 | ); |
| 179 | |
| 180 | // click through to the membership view screen |
| 181 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 182 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 183 | |
| 184 | $this->webtestVerifyTabularData( |
| 185 | array( |
| 186 | 'Membership Type' => "Membership Type $title", |
| 187 | 'Status' => $status, |
| 188 | 'Source' => $sourceText, |
| 189 | 'Member Since' => $joinDate, |
| 190 | 'Start date' => $startDate, |
| 191 | 'End date' => $endDate, |
| 192 | ) |
| 193 | ); |
| 194 | } |
| 195 | |
| 196 | public function testMembershipTypeScenario2() { |
| 197 | // Scenario 2 |
| 198 | // Rollover Date < Join Date |
| 199 | |
| 200 | // Log in using webtestLogin() method |
| 201 | $this->webtestLogin(); |
| 202 | |
| 203 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
| 204 | |
| 205 | $title = substr(sha1(rand()), 0, 7); |
| 206 | $this->type('organization_name', "Organization $title"); |
| 207 | $this->type('email_1_email', "$title@org.com"); |
| 208 | $this->click('_qf_Contact_upload_view'); |
| 209 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 210 | |
| 211 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); |
| 212 | |
| 213 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
| 214 | |
| 215 | $this->click("link=Add Membership Type"); |
| 216 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); |
| 217 | |
| 218 | $this->type('name', "Membership Type $title"); |
| 219 | $this->select2('member_of_contact_id', $title); |
| 220 | |
| 221 | $this->type('minimum_fee', '100'); |
| 222 | $this->select('financial_type_id', 'value=2'); |
| 223 | |
| 224 | $this->type('duration_interval', 2); |
| 225 | $this->select('duration_unit', "label=year"); |
| 226 | |
| 227 | $this->select('period_type', "value=fixed"); |
| 228 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
| 229 | |
| 230 | $this->select('fixed_period_start_day[M]', 'value=9'); |
| 231 | $this->select('fixed_period_rollover_day[M]', 'value=6'); |
| 232 | $this->select('fixed_period_rollover_day[d]', 'value=30'); |
| 233 | |
| 234 | $this->click('relationship_type_id', 'value=4_b_a'); |
| 235 | |
| 236 | $this->click('_qf_MembershipType_upload-bottom'); |
| 237 | $this->waitForElementPresent('link=Add Membership Type'); |
| 238 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
| 239 | |
| 240 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 241 | |
| 242 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 243 | |
| 244 | //fill in first name |
| 245 | $this->type('first_name', $firstName); |
| 246 | |
| 247 | //fill in last name |
| 248 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; |
| 249 | $this->type('last_name', $lastName); |
| 250 | |
| 251 | //fill in email |
| 252 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 253 | $this->type('email_1_email', $email); |
| 254 | |
| 255 | // Clicking save. |
| 256 | $this->click('_qf_Contact_upload_view'); |
| 257 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 258 | |
| 259 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); |
| 260 | |
| 261 | // click through to the membership add screen |
| 262 | $this->click('css=li#tab_member a'); |
| 263 | |
| 264 | $this->waitForElementPresent('link=Add Membership'); |
| 265 | $this->click('link=Add Membership'); |
| 266 | |
| 267 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 268 | |
| 269 | // fill in Membership Organization and Type |
| 270 | $this->select('membership_type_id[0]', "label=Organization {$title}"); |
| 271 | // Wait for membership type select to reload |
| 272 | $this->waitForTextPresent("Membership Type {$title}"); |
| 273 | $this->select('membership_type_id[1]', "label=Membership Type {$title}"); |
| 274 | |
| 275 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2"; |
| 276 | // fill in Source |
| 277 | $this->type('source', $sourceText); |
| 278 | |
| 279 | //build the membership dates. |
| 280 | require_once 'CRM/Core/Config.php'; |
| 281 | require_once 'CRM/Utils/Array.php'; |
| 282 | require_once 'CRM/Utils/Date.php'; |
| 283 | $currentYear = date('Y'); |
| 284 | $currentMonth = date('m'); |
| 285 | $previousYear = $currentYear - 1; |
| 286 | |
| 287 | $todayDate = date('Y-m-d'); |
| 288 | |
| 289 | // the member-since date we will type in to membership form |
| 290 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 7, 15, $currentYear)); |
| 291 | |
| 292 | // expected calc'd start date |
| 293 | $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear)); |
| 294 | |
| 295 | // expected calc'd end date |
| 296 | $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear + 2)); |
| 297 | foreach (array( |
| 298 | 'joinDate', |
| 299 | 'startDate', |
| 300 | 'endDate', |
| 301 | ) as $date) { |
| 302 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
| 303 | } |
| 304 | |
| 305 | $query = " |
| 306 | SELECT end_event_adjust_interval |
| 307 | |
| 308 | FROM civicrm_membership_status |
| 309 | |
| 310 | WHERE start_event = 'join_date' |
| 311 | AND name = 'New'"; |
| 312 | $endInterval = CRM_Core_DAO::singleValueQuery($query); |
| 313 | |
| 314 | // Add endInterval to July 15 (join date month above) to get end of New status period |
| 315 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 7, 15, $currentYear)); |
| 316 | |
| 317 | $status = 'Current'; |
| 318 | // status will be 'New' if today is >= join date and <= endNewStatus date |
| 319 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { |
| 320 | $status = 'New'; |
| 321 | } |
| 322 | |
| 323 | // fill in Join Date |
| 324 | $this->webtestFillDate('join_date', $joinDate); |
| 325 | |
| 326 | // Clicking save. |
| 327 | $this->click('_qf_Membership_upload'); |
| 328 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 329 | |
| 330 | // page was loaded |
| 331 | $this->waitForTextPresent($sourceText); |
| 332 | |
| 333 | // Is status message correct? |
| 334 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), |
| 335 | "Status message didn't show up after saving!" |
| 336 | ); |
| 337 | |
| 338 | // click through to the membership view screen |
| 339 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 340 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 341 | |
| 342 | $this->webtestVerifyTabularData( |
| 343 | array( |
| 344 | 'Membership Type' => "Membership Type {$title}", |
| 345 | 'Status' => $status, |
| 346 | 'Source' => $sourceText, |
| 347 | 'Member Since' => $joinDate, |
| 348 | 'Start date' => $startDate, |
| 349 | 'End date' => $endDate, |
| 350 | ) |
| 351 | ); |
| 352 | } |
| 353 | |
| 354 | public function testMembershipTypeScenario3() { |
| 355 | // Scenario 3 |
| 356 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover |
| 357 | // Join Date is later than Rollover Date |
| 358 | |
| 359 | // Log in using webtestLogin() method |
| 360 | $this->webtestLogin(); |
| 361 | |
| 362 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
| 363 | |
| 364 | $title = substr(sha1(rand()), 0, 7); |
| 365 | $this->type('organization_name', "Organization $title"); |
| 366 | $this->type('email_1_email', "$title@org.com"); |
| 367 | $this->click('_qf_Contact_upload_view'); |
| 368 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 369 | |
| 370 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); |
| 371 | |
| 372 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
| 373 | |
| 374 | $this->click("link=Add Membership Type"); |
| 375 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); |
| 376 | |
| 377 | $this->type('name', "Membership Type $title"); |
| 378 | $this->select2('member_of_contact_id', $title); |
| 379 | |
| 380 | $this->type('minimum_fee', '100'); |
| 381 | $this->select('financial_type_id', 'value=2'); |
| 382 | $this->type('duration_interval', 1); |
| 383 | $this->select('duration_unit', "label=year"); |
| 384 | |
| 385 | $this->select('period_type', "value=fixed"); |
| 386 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
| 387 | |
| 388 | $this->select('fixed_period_rollover_day[M]', 'value=10'); |
| 389 | $this->select('fixed_period_rollover_day[d]', 'value=31'); |
| 390 | |
| 391 | $this->click('relationship_type_id', 'value=4_b_a'); |
| 392 | |
| 393 | $this->click('_qf_MembershipType_upload-bottom'); |
| 394 | $this->waitForElementPresent('link=Add Membership Type'); |
| 395 | |
| 396 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
| 397 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 398 | |
| 399 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 400 | |
| 401 | //fill in first name |
| 402 | $this->type('first_name', $firstName); |
| 403 | |
| 404 | //fill in last name |
| 405 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; |
| 406 | $this->type('last_name', $lastName); |
| 407 | |
| 408 | //fill in email |
| 409 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 410 | $this->type('email_1_email', $email); |
| 411 | |
| 412 | // Clicking save. |
| 413 | $this->click('_qf_Contact_upload_view'); |
| 414 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 415 | |
| 416 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); |
| 417 | |
| 418 | // click through to the membership view screen |
| 419 | $this->click('css=li#tab_member a'); |
| 420 | |
| 421 | $this->waitForElementPresent('link=Add Membership'); |
| 422 | $this->click('link=Add Membership'); |
| 423 | |
| 424 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 425 | |
| 426 | // fill in Membership Organization and Type |
| 427 | $this->select('membership_type_id[0]', "label=Organization {$title}"); |
| 428 | // Wait for membership type select to reload |
| 429 | $this->waitForTextPresent("Membership Type {$title}"); |
| 430 | $this->select('membership_type_id[1]', "label=Membership Type {$title}"); |
| 431 | |
| 432 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3"; |
| 433 | // fill in Source |
| 434 | $this->type('source', $sourceText); |
| 435 | |
| 436 | //build the membership dates. |
| 437 | require_once 'CRM/Core/Config.php'; |
| 438 | require_once 'CRM/Utils/Array.php'; |
| 439 | require_once 'CRM/Utils/Date.php'; |
| 440 | $currentYear = date('Y'); |
| 441 | $currentMonth = date('m'); |
| 442 | $previousYear = $currentYear - 1; |
| 443 | $nextYear = $currentYear + 1; |
| 444 | $todayDate = date('Y-m-d'); |
| 445 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear)); |
| 446 | $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear)); |
| 447 | $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear)); |
| 448 | foreach (array( |
| 449 | 'joinDate', |
| 450 | 'startDate', |
| 451 | 'endDate', |
| 452 | ) as $date) { |
| 453 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
| 454 | } |
| 455 | |
| 456 | $query = " |
| 457 | SELECT end_event_adjust_interval |
| 458 | |
| 459 | FROM civicrm_membership_status |
| 460 | |
| 461 | WHERE start_event = 'join_date' |
| 462 | AND name = 'New'"; |
| 463 | $endInterval = CRM_Core_DAO::singleValueQuery($query); |
| 464 | |
| 465 | // Add endInterval to Nov 15 (join date month above) to get end of New status period |
| 466 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear)); |
| 467 | |
| 468 | $status = 'Current'; |
| 469 | // status will be 'New' if today is >= join date and <= endNewStatus date |
| 470 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { |
| 471 | $status = 'New'; |
| 472 | } |
| 473 | |
| 474 | // fill in Join Date |
| 475 | $this->webtestFillDate('join_date', $joinDate); |
| 476 | |
| 477 | // Clicking save. |
| 478 | $this->click('_qf_Membership_upload'); |
| 479 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 480 | |
| 481 | // page was loaded |
| 482 | $this->waitForTextPresent($sourceText); |
| 483 | |
| 484 | // Is status message correct? |
| 485 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), |
| 486 | "Status message didn't show up after saving!" |
| 487 | ); |
| 488 | |
| 489 | // click through to the membership view screen |
| 490 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 491 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 492 | |
| 493 | $this->webtestVerifyTabularData( |
| 494 | array( |
| 495 | 'Membership Type' => "Membership Type {$title}", |
| 496 | 'Status' => $status, |
| 497 | 'Source' => $sourceText, |
| 498 | 'Member Since' => $joinDate, |
| 499 | 'Start date' => $startDate, |
| 500 | 'End date' => $endDate, |
| 501 | ) |
| 502 | ); |
| 503 | } |
| 504 | |
| 505 | public function testMembershipTypeScenario4() { |
| 506 | // Scenario 4 |
| 507 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover |
| 508 | // Join Date is earlier than Rollover Date |
| 509 | |
| 510 | // Log in using webtestLogin() method |
| 511 | $this->webtestLogin(); |
| 512 | |
| 513 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
| 514 | |
| 515 | $title = substr(sha1(rand()), 0, 7); |
| 516 | $this->type('organization_name', "Organization $title"); |
| 517 | $this->type('email_1_email', "$title@org.com"); |
| 518 | $this->click('_qf_Contact_upload_view'); |
| 519 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 520 | |
| 521 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); |
| 522 | |
| 523 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
| 524 | |
| 525 | $this->click("link=Add Membership Type"); |
| 526 | $this->waitForElementPresent("xpath=//button//span[contains(text(),'Cancel')]"); |
| 527 | |
| 528 | $this->type('name', "Membership Type $title"); |
| 529 | $this->select2('member_of_contact_id', $title); |
| 530 | |
| 531 | $this->type('minimum_fee', '100'); |
| 532 | $this->select('financial_type_id', 'value=2'); |
| 533 | $this->type('duration_interval', 1); |
| 534 | $this->select('duration_unit', "label=year"); |
| 535 | |
| 536 | $this->select('period_type', "value=fixed"); |
| 537 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
| 538 | |
| 539 | $this->select('fixed_period_start_day[M]', 'value=1'); |
| 540 | $this->select('fixed_period_rollover_day[M]', 'value=10'); |
| 541 | $this->select('fixed_period_rollover_day[d]', 'value=31'); |
| 542 | |
| 543 | $this->click('relationship_type_id', 'value=4_b_a'); |
| 544 | |
| 545 | $this->click('_qf_MembershipType_upload-bottom'); |
| 546 | $this->waitForElementPresent('link=Add Membership Type'); |
| 547 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
| 548 | |
| 549 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 550 | |
| 551 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 552 | |
| 553 | //fill in first name |
| 554 | $this->type('first_name', $firstName); |
| 555 | |
| 556 | //fill in last name |
| 557 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; |
| 558 | $this->type('last_name', $lastName); |
| 559 | |
| 560 | //fill in email |
| 561 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 562 | $this->type('email_1_email', $email); |
| 563 | |
| 564 | // Clicking save. |
| 565 | $this->click('_qf_Contact_upload_view'); |
| 566 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 567 | |
| 568 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); |
| 569 | |
| 570 | // click through to the membership view screen |
| 571 | $this->click('css=li#tab_member a'); |
| 572 | |
| 573 | $this->waitForElementPresent('link=Add Membership'); |
| 574 | $this->click('link=Add Membership'); |
| 575 | |
| 576 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); |
| 577 | |
| 578 | // fill in Membership Organization and Type |
| 579 | $this->select('membership_type_id[0]', "label=Organization $title"); |
| 580 | $this->select('membership_type_id[1]', "label=Membership Type $title"); |
| 581 | |
| 582 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4"; |
| 583 | // fill in Source |
| 584 | $this->type('source', $sourceText); |
| 585 | |
| 586 | //build the membership dates. |
| 587 | require_once 'CRM/Core/Config.php'; |
| 588 | require_once 'CRM/Utils/Array.php'; |
| 589 | require_once 'CRM/Utils/Date.php'; |
| 590 | $currentYear = date('Y'); |
| 591 | $currentMonth = date('m'); |
| 592 | $nextYear = $currentYear + 1; |
| 593 | $todayDate = date('Y-m-d'); |
| 594 | |
| 595 | // the member-since date we will type in to membership form |
| 596 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear)); |
| 597 | |
| 598 | // expected calc'd start and end dates |
| 599 | $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear)); |
| 600 | $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear)); |
| 601 | foreach (array( |
| 602 | 'joinDate', |
| 603 | 'startDate', |
| 604 | 'endDate', |
| 605 | ) as $date) { |
| 606 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
| 607 | } |
| 608 | |
| 609 | $query = " |
| 610 | SELECT end_event_adjust_interval |
| 611 | |
| 612 | FROM civicrm_membership_status |
| 613 | |
| 614 | WHERE start_event = 'join_date' |
| 615 | AND name = 'New'"; |
| 616 | $endInterval = CRM_Core_DAO::singleValueQuery($query); |
| 617 | |
| 618 | // Add endInterval to Jan 6 (join date month above) to get end of New status period |
| 619 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 1, 15, $currentYear)); |
| 620 | |
| 621 | $status = 'Current'; |
| 622 | // status will be 'New' if today is >= join date and <= endNewStatus date |
| 623 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { |
| 624 | $status = 'New'; |
| 625 | } |
| 626 | |
| 627 | // fill in Join Date |
| 628 | $this->webtestFillDate('join_date', $joinDate); |
| 629 | |
| 630 | // Clicking save. |
| 631 | $this->click('_qf_Membership_upload'); |
| 632 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 633 | |
| 634 | // page was loaded |
| 635 | $this->waitForTextPresent($sourceText); |
| 636 | |
| 637 | // Is status message correct? |
| 638 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), |
| 639 | "Status message didn't show up after saving!" |
| 640 | ); |
| 641 | |
| 642 | // click through to the membership view screen |
| 643 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 644 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 645 | |
| 646 | $this->webtestVerifyTabularData( |
| 647 | array( |
| 648 | 'Membership Type' => "Membership Type $title", |
| 649 | 'Status' => $status, |
| 650 | 'Source' => $sourceText, |
| 651 | 'Member Since' => $joinDate, |
| 652 | 'Start date' => $startDate, |
| 653 | 'End date' => $endDate, |
| 654 | ) |
| 655 | ); |
| 656 | } |
| 657 | |
| 658 | } |