3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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));
144 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
148 SELECT end_event_adjust_interval
150 FROM civicrm_membership_status
152 WHERE start_event = 'join_date'
154 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
156 // Add endInterval to March 25 (join date month above) to get end of New status period
157 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
3, 25, $currentYear));
160 // status will be 'New' if today is >= join date and <= endNewStatus date
161 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
166 $this->webtestFillDate('join_date', $joinDate);
169 $this->click('_qf_Membership_upload');
172 $this->waitForTextPresent($sourceText);
174 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
175 // Is status message correct?
176 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
177 "Status message didn't show up after saving!"
180 // click through to the membership view screen
181 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
182 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
184 $this->webtestVerifyTabularData(
186 'Membership Type' => "Membership Type $title",
188 'Source' => $sourceText,
189 'Member Since' => $joinDate,
190 'Start date' => $startDate,
191 'End date' => $endDate,
196 public function testMembershipTypeScenario2() {
198 // Rollover Date < Join Date
200 // Log in using webtestLogin() method
201 $this->webtestLogin();
203 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
205 $title = substr(sha1(rand()), 0, 7);
206 $this->type('organization_name', "Organization $title");
207 $this->type('email_1_email', "$title@org.com");
208 $this->click('_qf_Contact_upload_view');
209 $this->waitForPageToLoad($this->getTimeoutMsec());
211 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
213 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
215 $this->click("link=Add Membership Type");
216 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
218 $this->type('name', "Membership Type $title");
219 $this->select2('member_of_contact_id', $title);
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', "value=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->waitForText('crm-notification-container', "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));
302 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
306 SELECT end_event_adjust_interval
308 FROM civicrm_membership_status
310 WHERE start_event = 'join_date'
312 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
314 // Add endInterval to July 15 (join date month above) to get end of New status period
315 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
318 // status will be 'New' if today is >= join date and <= endNewStatus date
319 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
324 $this->webtestFillDate('join_date', $joinDate);
327 $this->click('_qf_Membership_upload');
328 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
331 $this->waitForTextPresent($sourceText);
333 // Is status message correct?
334 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
335 "Status message didn't show up after saving!"
338 // click through to the membership view screen
339 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
340 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
342 $this->webtestVerifyTabularData(
344 'Membership Type' => "Membership Type {$title}",
346 'Source' => $sourceText,
347 'Member Since' => $joinDate,
348 'Start date' => $startDate,
349 'End date' => $endDate,
354 public function testMembershipTypeScenario3() {
356 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
357 // Join Date is later than Rollover Date
359 // Log in using webtestLogin() method
360 $this->webtestLogin();
362 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
364 $title = substr(sha1(rand()), 0, 7);
365 $this->type('organization_name', "Organization $title");
366 $this->type('email_1_email', "$title@org.com");
367 $this->click('_qf_Contact_upload_view');
368 $this->waitForPageToLoad($this->getTimeoutMsec());
370 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
372 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
374 $this->click("link=Add Membership Type");
375 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
377 $this->type('name', "Membership Type $title");
378 $this->select2('member_of_contact_id', $title);
380 $this->type('minimum_fee', '100');
381 $this->select('financial_type_id', 'value=2');
382 $this->type('duration_interval', 1);
383 $this->select('duration_unit', "label=year");
385 $this->select('period_type', "value=fixed");
386 $this->waitForElementPresent('fixed_period_rollover_day[d]');
388 $this->select('fixed_period_rollover_day[M]', 'value=10');
389 $this->select('fixed_period_rollover_day[d]', 'value=31');
391 $this->click('relationship_type_id', 'value=4_b_a');
393 $this->click('_qf_MembershipType_upload-bottom');
394 $this->waitForElementPresent('link=Add Membership Type');
396 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
397 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
399 $firstName = "John_" . substr(sha1(rand()), 0, 7);
402 $this->type('first_name', $firstName);
405 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
406 $this->type('last_name', $lastName);
409 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
410 $this->type('email_1_email', $email);
413 $this->click('_qf_Contact_upload_view');
414 $this->waitForPageToLoad($this->getTimeoutMsec());
416 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
418 // click through to the membership view screen
419 $this->click('css=li#tab_member a');
421 $this->waitForElementPresent('link=Add Membership');
422 $this->click('link=Add Membership');
424 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
426 // fill in Membership Organization and Type
427 $this->select('membership_type_id[0]', "label=Organization {$title}");
428 // Wait for membership type select to reload
429 $this->waitForTextPresent("Membership Type {$title}");
430 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
432 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
434 $this->type('source', $sourceText);
436 //build the membership dates.
437 require_once 'CRM/Core/Config.php';
438 require_once 'CRM/Utils/Array.php';
439 require_once 'CRM/Utils/Date.php';
440 $currentYear = date('Y');
441 $currentMonth = date('m');
442 $previousYear = $currentYear - 1;
443 $nextYear = $currentYear +
1;
444 $todayDate = date('Y-m-d');
445 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
446 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
447 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
453 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
457 SELECT end_event_adjust_interval
459 FROM civicrm_membership_status
461 WHERE start_event = 'join_date'
463 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
465 // Add endInterval to Nov 15 (join date month above) to get end of New status period
466 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
469 // status will be 'New' if today is >= join date and <= endNewStatus date
470 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
475 $this->webtestFillDate('join_date', $joinDate);
478 $this->click('_qf_Membership_upload');
479 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
482 $this->waitForTextPresent($sourceText);
484 // Is status message correct?
485 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
486 "Status message didn't show up after saving!"
489 // click through to the membership view screen
490 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
491 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
493 $this->webtestVerifyTabularData(
495 'Membership Type' => "Membership Type {$title}",
497 'Source' => $sourceText,
498 'Member Since' => $joinDate,
499 'Start date' => $startDate,
500 'End date' => $endDate,
505 public function testMembershipTypeScenario4() {
507 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
508 // Join Date is earlier than Rollover Date
510 // Log in using webtestLogin() method
511 $this->webtestLogin();
513 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
515 $title = substr(sha1(rand()), 0, 7);
516 $this->type('organization_name', "Organization $title");
517 $this->type('email_1_email', "$title@org.com");
518 $this->click('_qf_Contact_upload_view');
519 $this->waitForPageToLoad($this->getTimeoutMsec());
521 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
523 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
525 $this->click("link=Add Membership Type");
526 $this->waitForElementPresent("xpath=//button//span[contains(text(),'Cancel')]");
528 $this->type('name', "Membership Type $title");
529 $this->select2('member_of_contact_id', $title);
531 $this->type('minimum_fee', '100');
532 $this->select('financial_type_id', 'value=2');
533 $this->type('duration_interval', 1);
534 $this->select('duration_unit', "label=year");
536 $this->select('period_type', "value=fixed");
537 $this->waitForElementPresent('fixed_period_rollover_day[d]');
539 $this->select('fixed_period_start_day[M]', 'value=1');
540 $this->select('fixed_period_rollover_day[M]', 'value=10');
541 $this->select('fixed_period_rollover_day[d]', 'value=31');
543 $this->click('relationship_type_id', 'value=4_b_a');
545 $this->click('_qf_MembershipType_upload-bottom');
546 $this->waitForElementPresent('link=Add Membership Type');
547 $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
549 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
551 $firstName = "John_" . substr(sha1(rand()), 0, 7);
554 $this->type('first_name', $firstName);
557 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
558 $this->type('last_name', $lastName);
561 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
562 $this->type('email_1_email', $email);
565 $this->click('_qf_Contact_upload_view');
566 $this->waitForPageToLoad($this->getTimeoutMsec());
568 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
570 // click through to the membership view screen
571 $this->click('css=li#tab_member a');
573 $this->waitForElementPresent('link=Add Membership');
574 $this->click('link=Add Membership');
576 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
578 // fill in Membership Organization and Type
579 $this->select('membership_type_id[0]', "label=Organization $title");
580 $this->select('membership_type_id[1]', "label=Membership Type $title");
582 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
584 $this->type('source', $sourceText);
586 //build the membership dates.
587 require_once 'CRM/Core/Config.php';
588 require_once 'CRM/Utils/Array.php';
589 require_once 'CRM/Utils/Date.php';
590 $currentYear = date('Y');
591 $currentMonth = date('m');
592 $nextYear = $currentYear +
1;
593 $todayDate = date('Y-m-d');
595 // the member-since date we will type in to membership form
596 $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear));
598 // expected calc'd start and end dates
599 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
600 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear));
606 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('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->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
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,