3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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';
30 * Class WebTest_Member_FixedMembershipTypeTest
32 class WebTest_Member_FixedMembershipTypeTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testMembershipTypeScenario1() {
40 // Rollover Date < Start Date
41 // Join Date > Rollover Date and Join Date < Start Date
43 // Log in using webtestLogin() method
44 $this->webtestLogin();
46 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
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());
54 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
56 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
58 $this->click("link=Add Membership Type");
59 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
61 $this->type('name', "Membership Type $title");
62 $this->select2('member_of_contact_id', $title);
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");
69 $this->select('period_type', "value=fixed");
70 $this->waitForElementPresent('fixed_period_rollover_day[d]');
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');
77 $this->click('relationship_type_id', 'value=4_b_a');
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.");
83 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
85 $firstName = "John_" . substr(sha1(rand()), 0, 7);
88 $this->type('first_name', $firstName);
91 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
92 $this->type('last_name', $lastName);
95 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
96 $this->type('email_1_email', $email);
99 $this->click('_qf_Contact_upload_view');
100 $this->waitForPageToLoad($this->getTimeoutMsec());
101 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
103 // click through to the membership view screen
104 $this->click('css=li#tab_member a');
106 $this->waitForElementPresent('link=Add Membership');
107 $this->click('link=Add Membership');
109 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
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");
115 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
117 $this->type('source', $sourceText);
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;
128 $todayDate = date('Y-m-d');
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));
133 // expected calc'd start date
134 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
136 // expected calc'd end date
137 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
139 $configVars = new CRM_Core_Config_Variables();
145 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
149 SELECT end_event_adjust_interval
151 FROM civicrm_membership_status
153 WHERE start_event = 'join_date'
155 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
157 // Add endInterval to March 25 (join date month above) to get end of New status period
158 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
3, 25, $currentYear));
161 // status will be 'New' if today is >= join date and <= endNewStatus date
162 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
167 $this->webtestFillDate('join_date', $joinDate);
170 $this->click('_qf_Membership_upload');
173 $this->waitForTextPresent($sourceText);
175 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
176 // Is status message correct?
177 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
178 "Status message didn't show up after saving!"
181 // click through to the membership view screen
182 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
183 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
185 $this->webtestVerifyTabularData(
187 'Membership Type' => "Membership Type $title",
189 'Source' => $sourceText,
190 'Member Since' => $joinDate,
191 'Start date' => $startDate,
192 'End date' => $endDate,
197 public function testMembershipTypeScenario2() {
199 // Rollover Date < Join Date
201 // Log in using webtestLogin() method
202 $this->webtestLogin();
204 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
206 $title = substr(sha1(rand()), 0, 7);
207 $this->type('organization_name', "Organization $title");
208 $this->type('email_1_email', "$title@org.com");
209 $this->click('_qf_Contact_upload_view');
210 $this->waitForPageToLoad($this->getTimeoutMsec());
212 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
214 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
216 $this->click("link=Add Membership Type");
217 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
219 $this->type('name', "Membership Type $title");
220 $this->select2('member_of_contact_id', $title);
222 $this->type('minimum_fee', '100');
223 $this->select('financial_type_id', 'value=2');
225 $this->type('duration_interval', 2);
226 $this->select('duration_unit', "label=year");
228 $this->select('period_type', "value=fixed");
229 $this->waitForElementPresent('fixed_period_rollover_day[d]');
231 $this->select('fixed_period_start_day[M]', 'value=9');
232 $this->select('fixed_period_rollover_day[M]', 'value=6');
233 $this->select('fixed_period_rollover_day[d]', 'value=30');
235 $this->click('relationship_type_id', 'value=4_b_a');
237 $this->click('_qf_MembershipType_upload-bottom');
238 $this->waitForElementPresent('link=Add Membership Type');
239 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
241 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
243 $firstName = "John_" . substr(sha1(rand()), 0, 7);
246 $this->type('first_name', $firstName);
249 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
250 $this->type('last_name', $lastName);
253 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
254 $this->type('email_1_email', $email);
257 $this->click('_qf_Contact_upload_view');
258 $this->waitForPageToLoad($this->getTimeoutMsec());
260 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
262 // click through to the membership add screen
263 $this->click('css=li#tab_member a');
265 $this->waitForElementPresent('link=Add Membership');
266 $this->click('link=Add Membership');
268 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
270 // fill in Membership Organization and Type
271 $this->select('membership_type_id[0]', "label=Organization {$title}");
272 // Wait for membership type select to reload
273 $this->waitForTextPresent("Membership Type {$title}");
274 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
276 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
278 $this->type('source', $sourceText);
280 //build the membership dates.
281 require_once 'CRM/Core/Config.php';
282 require_once 'CRM/Utils/Array.php';
283 require_once 'CRM/Utils/Date.php';
284 $currentYear = date('Y');
285 $currentMonth = date('m');
286 $previousYear = $currentYear - 1;
288 $todayDate = date('Y-m-d');
290 // the member-since date we will type in to membership form
291 $joinDate = date('Y-m-d', mktime(0, 0, 0, 7, 15, $currentYear));
293 // expected calc'd start date
294 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
296 // expected calc'd end date
297 $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear +
2));
298 $configVars = new CRM_Core_Config_Variables();
304 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
308 SELECT end_event_adjust_interval
310 FROM civicrm_membership_status
312 WHERE start_event = 'join_date'
314 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
316 // Add endInterval to July 15 (join date month above) to get end of New status period
317 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
320 // status will be 'New' if today is >= join date and <= endNewStatus date
321 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
326 $this->webtestFillDate('join_date', $joinDate);
329 $this->click('_qf_Membership_upload');
330 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
333 $this->waitForTextPresent($sourceText);
335 // Is status message correct?
336 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
337 "Status message didn't show up after saving!"
340 // click through to the membership view screen
341 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
342 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
344 $this->webtestVerifyTabularData(
346 'Membership Type' => "Membership Type {$title}",
348 'Source' => $sourceText,
349 'Member Since' => $joinDate,
350 'Start date' => $startDate,
351 'End date' => $endDate,
356 public function testMembershipTypeScenario3() {
358 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
359 // Join Date is later than Rollover Date
361 // Log in using webtestLogin() method
362 $this->webtestLogin();
364 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
366 $title = substr(sha1(rand()), 0, 7);
367 $this->type('organization_name', "Organization $title");
368 $this->type('email_1_email', "$title@org.com");
369 $this->click('_qf_Contact_upload_view');
370 $this->waitForPageToLoad($this->getTimeoutMsec());
372 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
374 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
376 $this->click("link=Add Membership Type");
377 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
379 $this->type('name', "Membership Type $title");
380 $this->select2('member_of_contact_id', $title);
382 $this->type('minimum_fee', '100');
383 $this->select('financial_type_id', 'value=2');
384 $this->type('duration_interval', 1);
385 $this->select('duration_unit', "label=year");
387 $this->select('period_type', "value=fixed");
388 $this->waitForElementPresent('fixed_period_rollover_day[d]');
390 $this->select('fixed_period_rollover_day[M]', 'value=10');
391 $this->select('fixed_period_rollover_day[d]', 'value=31');
393 $this->click('relationship_type_id', 'value=4_b_a');
395 $this->click('_qf_MembershipType_upload-bottom');
396 $this->waitForElementPresent('link=Add Membership Type');
398 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
399 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
401 $firstName = "John_" . substr(sha1(rand()), 0, 7);
404 $this->type('first_name', $firstName);
407 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
408 $this->type('last_name', $lastName);
411 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
412 $this->type('email_1_email', $email);
415 $this->click('_qf_Contact_upload_view');
416 $this->waitForPageToLoad($this->getTimeoutMsec());
418 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
420 // click through to the membership view screen
421 $this->click('css=li#tab_member a');
423 $this->waitForElementPresent('link=Add Membership');
424 $this->click('link=Add Membership');
426 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
428 // fill in Membership Organization and Type
429 $this->select('membership_type_id[0]', "label=Organization {$title}");
430 // Wait for membership type select to reload
431 $this->waitForTextPresent("Membership Type {$title}");
432 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
434 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
436 $this->type('source', $sourceText);
438 //build the membership dates.
439 require_once 'CRM/Core/Config.php';
440 require_once 'CRM/Utils/Array.php';
441 require_once 'CRM/Utils/Date.php';
442 $currentYear = date('Y');
443 $currentMonth = date('m');
444 $previousYear = $currentYear - 1;
445 $nextYear = $currentYear +
1;
446 $todayDate = date('Y-m-d');
447 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
448 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
449 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
450 $configVars = new CRM_Core_Config_Variables();
456 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
460 SELECT end_event_adjust_interval
462 FROM civicrm_membership_status
464 WHERE start_event = 'join_date'
466 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
468 // Add endInterval to Nov 15 (join date month above) to get end of New status period
469 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
472 // status will be 'New' if today is >= join date and <= endNewStatus date
473 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
478 $this->webtestFillDate('join_date', $joinDate);
481 $this->click('_qf_Membership_upload');
482 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
485 $this->waitForTextPresent($sourceText);
487 // Is status message correct?
488 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
489 "Status message didn't show up after saving!"
492 // click through to the membership view screen
493 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
494 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
496 $this->webtestVerifyTabularData(
498 'Membership Type' => "Membership Type {$title}",
500 'Source' => $sourceText,
501 'Member Since' => $joinDate,
502 'Start date' => $startDate,
503 'End date' => $endDate,
508 public function testMembershipTypeScenario4() {
510 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
511 // Join Date is earlier than Rollover Date
513 // Log in using webtestLogin() method
514 $this->webtestLogin();
516 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
518 $title = substr(sha1(rand()), 0, 7);
519 $this->type('organization_name', "Organization $title");
520 $this->type('email_1_email', "$title@org.com");
521 $this->click('_qf_Contact_upload_view');
522 $this->waitForPageToLoad($this->getTimeoutMsec());
524 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
526 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
528 $this->click("link=Add Membership Type");
529 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Cancel')]");
531 $this->type('name', "Membership Type $title");
532 $this->select2('member_of_contact_id', $title);
534 $this->type('minimum_fee', '100');
535 $this->select('financial_type_id', 'value=2');
536 $this->type('duration_interval', 1);
537 $this->select('duration_unit', "label=year");
539 $this->select('period_type', "value=fixed");
540 $this->waitForElementPresent('fixed_period_rollover_day[d]');
542 $this->select('fixed_period_start_day[M]', 'value=1');
543 $this->select('fixed_period_rollover_day[M]', 'value=10');
544 $this->select('fixed_period_rollover_day[d]', 'value=31');
546 $this->click('relationship_type_id', 'value=4_b_a');
548 $this->click('_qf_MembershipType_upload-bottom');
549 $this->waitForElementPresent('link=Add Membership Type');
550 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
552 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
554 $firstName = "John_" . substr(sha1(rand()), 0, 7);
557 $this->type('first_name', $firstName);
560 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
561 $this->type('last_name', $lastName);
564 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
565 $this->type('email_1_email', $email);
568 $this->click('_qf_Contact_upload_view');
569 $this->waitForPageToLoad($this->getTimeoutMsec());
571 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
573 // click through to the membership view screen
574 $this->click('css=li#tab_member a');
576 $this->waitForElementPresent('link=Add Membership');
577 $this->click('link=Add Membership');
579 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
581 // fill in Membership Organization and Type
582 $this->select('membership_type_id[0]', "label=Organization $title");
583 $this->select('membership_type_id[1]', "label=Membership Type $title");
585 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
587 $this->type('source', $sourceText);
589 //build the membership dates.
590 require_once 'CRM/Core/Config.php';
591 require_once 'CRM/Utils/Array.php';
592 require_once 'CRM/Utils/Date.php';
593 $currentYear = date('Y');
594 $currentMonth = date('m');
595 $nextYear = $currentYear +
1;
596 $todayDate = date('Y-m-d');
598 // the member-since date we will type in to membership form
599 $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear));
601 // expected calc'd start and end dates
602 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
603 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear));
604 $configVars = new CRM_Core_Config_Variables();
610 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
614 SELECT end_event_adjust_interval
616 FROM civicrm_membership_status
618 WHERE start_event = 'join_date'
620 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
622 // Add endInterval to Jan 6 (join date month above) to get end of New status period
623 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
1, 15, $currentYear));
626 // status will be 'New' if today is >= join date and <= endNewStatus date
627 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
632 $this->webtestFillDate('join_date', $joinDate);
635 $this->click('_qf_Membership_upload');
636 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
639 $this->waitForTextPresent($sourceText);
641 // Is status message correct?
642 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
643 "Status message didn't show up after saving!"
646 // click through to the membership view screen
647 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
648 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
650 $this->webtestVerifyTabularData(
652 'Membership Type' => "Membership Type $title",
654 'Source' => $sourceText,
655 'Member Since' => $joinDate,
656 'Start date' => $startDate,
657 'End date' => $endDate,