3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Member_FixedMembershipTypeTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testMembershipTypeScenario1() {
36 // Rollover Date < Start Date
37 // Join Date > Rollover Date and Join Date < Start Date
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
50 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
52 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
54 $this->click("link=Add Membership Type");
55 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
57 $this->type('name', "Membership Type $title");
58 $this->type('member_of_contact', $title);
59 $this->click('member_of_contact');
60 $this->waitForElementPresent("css=div.ac_results-inner li");
61 $this->click("css=div.ac_results-inner li");
63 $this->type('minimum_fee', '100');
64 $this->select( 'financial_type_id', 'value=2' );
65 $this->type('duration_interval', 1);
66 $this->select('duration_unit', "label=year");
68 $this->select('period_type', "label=fixed");
69 $this->waitForElementPresent('fixed_period_rollover_day[d]');
71 // fixed period start set to April 1
72 $this->select('fixed_period_start_day[M]', 'value=4');
73 // rollover date set to Jan 31
74 $this->select('fixed_period_rollover_day[M]', 'value=1');
76 $this->click('relationship_type_id', 'value=4_b_a');
78 $this->click('_qf_MembershipType_upload-bottom');
79 $this->waitForElementPresent('link=Add Membership Type');
80 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
82 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
84 $firstName = "John_" . substr(sha1(rand()), 0, 7);
87 $this->type('first_name', $firstName);
90 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
91 $this->type('last_name', $lastName);
94 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
95 $this->type('email_1_email', $email);
98 $this->click('_qf_Contact_upload_view');
99 $this->waitForPageToLoad($this->getTimeoutMsec());
100 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
102 // click through to the membership view screen
103 $this->click('css=li#tab_member a');
105 $this->waitForElementPresent('link=Add Membership');
106 $this->click('link=Add Membership');
108 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
110 // fill in Membership Organization and Type
111 $this->select('membership_type_id[0]', "label=Organization $title");
112 $this->select('membership_type_id[1]', "label=Membership Type $title");
114 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
116 $this->type('source', $sourceText);
118 //build the membership dates.
119 require_once 'CRM/Core/Config.php';
120 require_once 'CRM/Utils/Array.php';
121 require_once 'CRM/Utils/Date.php';
122 $currentYear = date('Y');
123 $currentMonth = date('m');
124 $previousYear = $currentYear - 1;
125 $nextYear = $currentYear +
1;
127 $todayDate = date('Y-m-d');
129 // the member-since date we will type in to membership form
130 $joinDate = date('Y-m-d', mktime(0, 0, 0, 3, 25, $currentYear));
132 // expected calc'd start date
133 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
135 // expected calc'd end date
136 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
138 $configVars = new CRM_Core_Config_Variables();
140 'joinDate', 'startDate', 'endDate') as $date) {
141 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
145 SELECT end_event_adjust_interval
147 FROM civicrm_membership_status
149 WHERE start_event = 'join_date'
151 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
153 // Add endInterval to March 25 (join date month above) to get end of New status period
154 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
3, 25, $currentYear));
157 // status will be 'New' if today is >= join date and <= endNewStatus date
158 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
163 $this->webtestFillDate('join_date', $joinDate);
166 $this->click('_qf_Membership_upload');
167 $this->waitForPageToLoad($this->getTimeoutMsec());
170 $this->waitForTextPresent($sourceText);
172 // Is status message correct?
173 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
174 "Status message didn't show up after saving!"
177 // click through to the membership view screen
178 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
179 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
181 $this->webtestVerifyTabularData(
183 'Membership Type' => "Membership Type $title",
185 'Source' => $sourceText,
186 'Member Since' => $joinDate,
187 'Start date' => $startDate,
188 'End date' => $endDate,
193 function testMembershipTypeScenario2() {
195 // Rollover Date < Join Date
197 // Log in using webtestLogin() method
198 $this->webtestLogin();
200 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
202 $title = substr(sha1(rand()), 0, 7);
203 $this->type('organization_name', "Organization $title");
204 $this->type('email_1_email', "$title@org.com");
205 $this->click('_qf_Contact_upload_view');
206 $this->waitForPageToLoad($this->getTimeoutMsec());
208 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
210 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
212 $this->click("link=Add Membership Type");
213 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
215 $this->type('name', "Membership Type $title");
216 $this->type('member_of_contact', $title);
217 $this->click('member_of_contact');
218 $this->waitForElementPresent("css=div.ac_results-inner li");
219 $this->click("css=div.ac_results-inner li");
221 $this->type('minimum_fee', '100');
222 $this->select( 'financial_type_id', 'value=2' );
224 $this->type('duration_interval', 2);
225 $this->select('duration_unit', "label=year");
227 $this->select('period_type', "label=fixed");
228 $this->waitForElementPresent('fixed_period_rollover_day[d]');
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');
234 $this->click('relationship_type_id', 'value=4_b_a');
236 $this->click('_qf_MembershipType_upload-bottom');
237 $this->waitForElementPresent('link=Add Membership Type');
238 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
240 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
242 $firstName = "John_" . substr(sha1(rand()), 0, 7);
245 $this->type('first_name', $firstName);
248 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
249 $this->type('last_name', $lastName);
252 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
253 $this->type('email_1_email', $email);
256 $this->click('_qf_Contact_upload_view');
257 $this->waitForPageToLoad($this->getTimeoutMsec());
259 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
261 // click through to the membership add screen
262 $this->click('css=li#tab_member a');
264 $this->waitForElementPresent('link=Add Membership');
265 $this->click('link=Add Membership');
267 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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}");
275 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
277 $this->type('source', $sourceText);
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;
287 $todayDate = date('Y-m-d');
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));
292 // expected calc'd start date
293 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
295 // expected calc'd end date
296 $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear +
2));
297 $configVars = new CRM_Core_Config_Variables();
299 'joinDate', 'startDate', 'endDate') as $date) {
300 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
304 SELECT end_event_adjust_interval
306 FROM civicrm_membership_status
308 WHERE start_event = 'join_date'
310 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
312 // Add endInterval to July 15 (join date month above) to get end of New status period
313 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
316 // status will be 'New' if today is >= join date and <= endNewStatus date
317 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
322 $this->webtestFillDate('join_date', $joinDate);
325 $this->click('_qf_Membership_upload');
326 $this->waitForPageToLoad($this->getTimeoutMsec());
329 $this->waitForTextPresent($sourceText);
331 // Is status message correct?
332 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
333 "Status message didn't show up after saving!"
336 // click through to the membership view screen
337 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
338 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
340 $this->webtestVerifyTabularData(
342 'Membership Type' => "Membership Type {$title}",
344 'Source' => $sourceText,
345 'Member Since' => $joinDate,
346 'Start date' => $startDate,
347 'End date' => $endDate,
352 function testMembershipTypeScenario3() {
354 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
355 // Join Date is later than Rollover Date
357 // Log in using webtestLogin() method
358 $this->webtestLogin();
360 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
362 $title = substr(sha1(rand()), 0, 7);
363 $this->type('organization_name', "Organization $title");
364 $this->type('email_1_email', "$title@org.com");
365 $this->click('_qf_Contact_upload_view');
366 $this->waitForPageToLoad($this->getTimeoutMsec());
368 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
370 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
372 $this->click("link=Add Membership Type");
373 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
375 $this->type('name', "Membership Type $title");
376 $this->type('member_of_contact', $title);
377 $this->click('member_of_contact');
378 $this->waitForElementPresent("css=div.ac_results-inner li");
379 $this->click("css=div.ac_results-inner li");
381 $this->type('minimum_fee', '100');
382 $this->select( 'financial_type_id', 'value=2' );
383 $this->type('duration_interval', 1);
384 $this->select('duration_unit', "label=year");
386 $this->select('period_type', "label=fixed");
387 $this->waitForElementPresent('fixed_period_rollover_day[d]');
389 $this->select('fixed_period_rollover_day[M]', 'value=10');
390 $this->select('fixed_period_rollover_day[d]', 'value=31');
392 $this->click('relationship_type_id', 'value=4_b_a');
394 $this->click('_qf_MembershipType_upload-bottom');
395 $this->waitForElementPresent('link=Add Membership Type');
396 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
398 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
400 $firstName = "John_" . substr(sha1(rand()), 0, 7);
403 $this->type('first_name', $firstName);
406 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
407 $this->type('last_name', $lastName);
410 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
411 $this->type('email_1_email', $email);
414 $this->click('_qf_Contact_upload_view');
415 $this->waitForPageToLoad($this->getTimeoutMsec());
417 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
419 // click through to the membership view screen
420 $this->click('css=li#tab_member a');
422 $this->waitForElementPresent('link=Add Membership');
423 $this->click('link=Add Membership');
425 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
427 // fill in Membership Organization and Type
428 $this->select('membership_type_id[0]', "label=Organization {$title}");
429 // Wait for membership type select to reload
430 $this->waitForTextPresent("Membership Type {$title}");
431 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
433 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
435 $this->type('source', $sourceText);
437 //build the membership dates.
438 require_once 'CRM/Core/Config.php';
439 require_once 'CRM/Utils/Array.php';
440 require_once 'CRM/Utils/Date.php';
441 $currentYear = date('Y');
442 $currentMonth = date('m');
443 $previousYear = $currentYear - 1;
444 $nextYear = $currentYear +
1;
445 $todayDate = date('Y-m-d');
446 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
447 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
448 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
449 $configVars = new CRM_Core_Config_Variables();
451 'joinDate', 'startDate', 'endDate') as $date) {
452 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
456 SELECT end_event_adjust_interval
458 FROM civicrm_membership_status
460 WHERE start_event = 'join_date'
462 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
464 // Add endInterval to Nov 15 (join date month above) to get end of New status period
465 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
468 // status will be 'New' if today is >= join date and <= endNewStatus date
469 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
474 $this->webtestFillDate('join_date', $joinDate);
477 $this->click('_qf_Membership_upload');
478 $this->waitForPageToLoad($this->getTimeoutMsec());
481 $this->waitForTextPresent($sourceText);
483 // Is status message correct?
484 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
485 "Status message didn't show up after saving!"
488 // click through to the membership view screen
489 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
490 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
492 $this->webtestVerifyTabularData(
494 'Membership Type' => "Membership Type {$title}",
496 'Source' => $sourceText,
497 'Member Since' => $joinDate,
498 'Start date' => $startDate,
499 'End date' => $endDate,
504 function testMembershipTypeScenario4() {
506 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
507 // Join Date is earlier than Rollover Date
509 // Log in using webtestLogin() method
510 $this->webtestLogin();
512 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
514 $title = substr(sha1(rand()), 0, 7);
515 $this->type('organization_name', "Organization $title");
516 $this->type('email_1_email', "$title@org.com");
517 $this->click('_qf_Contact_upload_view');
518 $this->waitForPageToLoad($this->getTimeoutMsec());
520 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
522 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
524 $this->click("link=Add Membership Type");
525 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
527 $this->type('name', "Membership Type $title");
528 $this->type('member_of_contact', $title);
529 $this->click('member_of_contact');
530 $this->waitForElementPresent("css=div.ac_results-inner li");
531 $this->click("css=div.ac_results-inner li");
533 $this->type('minimum_fee', '100');
534 $this->select( 'financial_type_id', 'value=2' );
535 $this->type('duration_interval', 1);
536 $this->select('duration_unit', "label=year");
538 $this->select('period_type', "label=fixed");
539 $this->waitForElementPresent('fixed_period_rollover_day[d]');
541 $this->select('fixed_period_start_day[M]', 'value=1');
542 $this->select('fixed_period_rollover_day[M]', 'value=10');
543 $this->select('fixed_period_rollover_day[d]', 'value=31');
545 $this->click('relationship_type_id', 'value=4_b_a');
547 $this->click('_qf_MembershipType_upload-bottom');
548 $this->waitForElementPresent('link=Add Membership Type');
549 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
551 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
553 $firstName = "John_" . substr(sha1(rand()), 0, 7);
556 $this->type('first_name', $firstName);
559 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
560 $this->type('last_name', $lastName);
563 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
564 $this->type('email_1_email', $email);
567 $this->click('_qf_Contact_upload_view');
568 $this->waitForPageToLoad($this->getTimeoutMsec());
570 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
572 // click through to the membership view screen
573 $this->click('css=li#tab_member a');
575 $this->waitForElementPresent('link=Add Membership');
576 $this->click('link=Add Membership');
578 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
580 // fill in Membership Organization and Type
581 $this->select('membership_type_id[0]', "label=Organization $title");
582 $this->select('membership_type_id[1]', "label=Membership Type $title");
584 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
586 $this->type('source', $sourceText);
588 //build the membership dates.
589 require_once 'CRM/Core/Config.php';
590 require_once 'CRM/Utils/Array.php';
591 require_once 'CRM/Utils/Date.php';
592 $currentYear = date('Y');
593 $currentMonth = date('m');
594 $nextYear = $currentYear +
1;
595 $todayDate = date('Y-m-d');
597 // the member-since date we will type in to membership form
598 $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear));
600 // expected calc'd start and end dates
601 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
602 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear));
603 $configVars = new CRM_Core_Config_Variables();
605 'joinDate', 'startDate', 'endDate') as $date) {
606 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
610 SELECT end_event_adjust_interval
612 FROM civicrm_membership_status
614 WHERE start_event = 'join_date'
616 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
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));
622 // status will be 'New' if today is >= join date and <= endNewStatus date
623 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
628 $this->webtestFillDate('join_date', $joinDate);
631 $this->click('_qf_Membership_upload');
632 $this->waitForPageToLoad($this->getTimeoutMsec());
635 $this->waitForTextPresent($sourceText);
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!"
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");
646 $this->webtestVerifyTabularData(
648 'Membership Type' => "Membership Type $title",
650 'Source' => $sourceText,
651 'Member Since' => $joinDate,
652 'Start date' => $startDate,
653 'End date' => $endDate,