3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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->select2('member_of_contact_id',$title);
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");
65 $this->select('period_type', "value=fixed");
66 $this->waitForElementPresent('fixed_period_rollover_day[d]');
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');
73 $this->click('relationship_type_id', 'value=4_b_a');
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.");
79 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
81 $firstName = "John_" . substr(sha1(rand()), 0, 7);
84 $this->type('first_name', $firstName);
87 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
88 $this->type('last_name', $lastName);
91 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
92 $this->type('email_1_email', $email);
95 $this->click('_qf_Contact_upload_view');
96 $this->waitForPageToLoad($this->getTimeoutMsec());
97 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
99 // click through to the membership view screen
100 $this->click('css=li#tab_member a');
102 $this->waitForElementPresent('link=Add Membership');
103 $this->click('link=Add Membership');
105 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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");
111 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
113 $this->type('source', $sourceText);
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;
124 $todayDate = date('Y-m-d');
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));
129 // expected calc'd start date
130 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
132 // expected calc'd end date
133 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
135 $configVars = new CRM_Core_Config_Variables();
137 'joinDate', 'startDate', 'endDate') as $date) {
138 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
142 SELECT end_event_adjust_interval
144 FROM civicrm_membership_status
146 WHERE start_event = 'join_date'
148 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
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));
154 // status will be 'New' if today is >= join date and <= endNewStatus date
155 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
160 $this->webtestFillDate('join_date', $joinDate);
163 $this->click('_qf_Membership_upload');
166 $this->waitForTextPresent($sourceText);
168 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
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!"
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");
178 $this->webtestVerifyTabularData(
180 'Membership Type' => "Membership Type $title",
182 'Source' => $sourceText,
183 'Member Since' => $joinDate,
184 'Start date' => $startDate,
185 'End date' => $endDate,
190 function testMembershipTypeScenario2() {
192 // Rollover Date < Join Date
194 // Log in using webtestLogin() method
195 $this->webtestLogin();
197 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
205 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
207 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
209 $this->click("link=Add Membership Type");
210 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
212 $this->type('name', "Membership Type $title");
213 $this->select2('member_of_contact_id',$title);
215 $this->type('minimum_fee', '100');
216 $this->select( 'financial_type_id', 'value=2' );
218 $this->type('duration_interval', 2);
219 $this->select('duration_unit', "label=year");
221 $this->select('period_type', "value=fixed");
222 $this->waitForElementPresent('fixed_period_rollover_day[d]');
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');
228 $this->click('relationship_type_id', 'value=4_b_a');
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.");
234 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
236 $firstName = "John_" . substr(sha1(rand()), 0, 7);
239 $this->type('first_name', $firstName);
242 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
243 $this->type('last_name', $lastName);
246 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
247 $this->type('email_1_email', $email);
250 $this->click('_qf_Contact_upload_view');
251 $this->waitForPageToLoad($this->getTimeoutMsec());
253 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
255 // click through to the membership add screen
256 $this->click('css=li#tab_member a');
258 $this->waitForElementPresent('link=Add Membership');
259 $this->click('link=Add Membership');
261 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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}");
269 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
271 $this->type('source', $sourceText);
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;
281 $todayDate = date('Y-m-d');
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));
286 // expected calc'd start date
287 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
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();
293 'joinDate', 'startDate', 'endDate') as $date) {
294 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
298 SELECT end_event_adjust_interval
300 FROM civicrm_membership_status
302 WHERE start_event = 'join_date'
304 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
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));
310 // status will be 'New' if today is >= join date and <= endNewStatus date
311 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
316 $this->webtestFillDate('join_date', $joinDate);
319 $this->click('_qf_Membership_upload');
320 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
323 $this->waitForTextPresent($sourceText);
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!"
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");
334 $this->webtestVerifyTabularData(
336 'Membership Type' => "Membership Type {$title}",
338 'Source' => $sourceText,
339 'Member Since' => $joinDate,
340 'Start date' => $startDate,
341 'End date' => $endDate,
346 function testMembershipTypeScenario3() {
348 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
349 // Join Date is later than Rollover Date
351 // Log in using webtestLogin() method
352 $this->webtestLogin();
354 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
362 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
364 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
366 $this->click("link=Add Membership Type");
367 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
369 $this->type('name', "Membership Type $title");
370 $this->select2('member_of_contact_id',$title);
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");
377 $this->select('period_type', "value=fixed");
378 $this->waitForElementPresent('fixed_period_rollover_day[d]');
380 $this->select('fixed_period_rollover_day[M]', 'value=10');
381 $this->select('fixed_period_rollover_day[d]', 'value=31');
383 $this->click('relationship_type_id', 'value=4_b_a');
385 $this->click('_qf_MembershipType_upload-bottom');
386 $this->waitForElementPresent('link=Add Membership Type');
388 $this->waitForText('crm-notification-container',"The membership type 'Membership Type $title' has been saved.");
389 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
391 $firstName = "John_" . substr(sha1(rand()), 0, 7);
394 $this->type('first_name', $firstName);
397 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
398 $this->type('last_name', $lastName);
401 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
402 $this->type('email_1_email', $email);
405 $this->click('_qf_Contact_upload_view');
406 $this->waitForPageToLoad($this->getTimeoutMsec());
408 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
410 // click through to the membership view screen
411 $this->click('css=li#tab_member a');
413 $this->waitForElementPresent('link=Add Membership');
414 $this->click('link=Add Membership');
416 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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}");
424 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
426 $this->type('source', $sourceText);
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();
442 'joinDate', 'startDate', 'endDate') as $date) {
443 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
447 SELECT end_event_adjust_interval
449 FROM civicrm_membership_status
451 WHERE start_event = 'join_date'
453 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
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));
459 // status will be 'New' if today is >= join date and <= endNewStatus date
460 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
465 $this->webtestFillDate('join_date', $joinDate);
468 $this->click('_qf_Membership_upload');
469 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
472 $this->waitForTextPresent($sourceText);
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!"
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");
483 $this->webtestVerifyTabularData(
485 'Membership Type' => "Membership Type {$title}",
487 'Source' => $sourceText,
488 'Member Since' => $joinDate,
489 'Start date' => $startDate,
490 'End date' => $endDate,
495 function testMembershipTypeScenario4() {
497 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
498 // Join Date is earlier than Rollover Date
500 // Log in using webtestLogin() method
501 $this->webtestLogin();
503 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
511 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
513 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
515 $this->click("link=Add Membership Type");
516 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
518 $this->type('name', "Membership Type $title");
519 $this->select2('member_of_contact_id',$title);
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");
526 $this->select('period_type', "value=fixed");
527 $this->waitForElementPresent('fixed_period_rollover_day[d]');
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');
533 $this->click('relationship_type_id', 'value=4_b_a');
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.");
539 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
541 $firstName = "John_" . substr(sha1(rand()), 0, 7);
544 $this->type('first_name', $firstName);
547 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
548 $this->type('last_name', $lastName);
551 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
552 $this->type('email_1_email', $email);
555 $this->click('_qf_Contact_upload_view');
556 $this->waitForPageToLoad($this->getTimeoutMsec());
558 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
560 // click through to the membership view screen
561 $this->click('css=li#tab_member a');
563 $this->waitForElementPresent('link=Add Membership');
564 $this->click('link=Add Membership');
566 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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");
572 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
574 $this->type('source', $sourceText);
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');
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));
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();
593 'joinDate', 'startDate', 'endDate') as $date) {
594 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
598 SELECT end_event_adjust_interval
600 FROM civicrm_membership_status
602 WHERE start_event = 'join_date'
604 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
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));
610 // status will be 'New' if today is >= join date and <= endNewStatus date
611 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
616 $this->webtestFillDate('join_date', $joinDate);
619 $this->click('_qf_Membership_upload');
620 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
623 $this->waitForTextPresent($sourceText);
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!"
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");
634 $this->webtestVerifyTabularData(
636 'Membership Type' => "Membership Type $title",
638 'Source' => $sourceText,
639 'Member Since' => $joinDate,
640 'Start date' => $startDate,
641 'End date' => $endDate,