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