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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Member_FixedMembershipTypeTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testMembershipTypeScenario1() {
37 // Rollover Date < Start Date
38 // Join Date > Rollover Date and Join Date < Start Date
41 // Log in using webtestLogin() method
42 $this->webtestLogin();
44 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
46 $title = substr(sha1(rand()), 0, 7);
47 $this->type('organization_name', "Organization $title");
48 $this->type('email_1_email', "$title@org.com");
49 $this->click('_qf_Contact_upload_view');
50 $this->waitForPageToLoad($this->getTimeoutMsec());
52 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
54 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
56 $this->click("link=Add Membership Type");
57 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
59 $this->type('name', "Membership Type $title");
60 $this->type('member_of_contact', $title);
61 $this->click('member_of_contact');
62 $this->waitForElementPresent("css=div.ac_results-inner li");
63 $this->click("css=div.ac_results-inner li");
65 $this->type('minimum_fee', '100');
66 $this->select( 'financial_type_id', 'value=2' );
67 $this->type('duration_interval', 1);
68 $this->select('duration_unit', "label=year");
70 $this->select('period_type', "label=fixed");
71 $this->waitForElementPresent('fixed_period_rollover_day[d]');
73 // fixed period start set to April 1
74 $this->select('fixed_period_start_day[M]', 'value=4');
75 // rollover date set to Jan 31
76 $this->select('fixed_period_rollover_day[M]', 'value=1');
78 $this->click('relationship_type_id', 'value=4_b_a');
80 $this->click('_qf_MembershipType_upload-bottom');
81 $this->waitForElementPresent('link=Add Membership Type');
82 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
84 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
86 $firstName = "John_" . substr(sha1(rand()), 0, 7);
89 $this->type('first_name', $firstName);
92 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
93 $this->type('last_name', $lastName);
96 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
97 $this->type('email_1_email', $email);
100 $this->click('_qf_Contact_upload_view');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
104 // click through to the membership view screen
105 $this->click('css=li#tab_member a');
107 $this->waitForElementPresent('link=Add Membership');
108 $this->click('link=Add Membership');
110 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
112 // fill in Membership Organization and Type
113 $this->select('membership_type_id[0]', "label=Organization $title");
114 $this->select('membership_type_id[1]', "label=Membership Type $title");
116 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
118 $this->type('source', $sourceText);
120 //build the membership dates.
121 require_once 'CRM/Core/Config.php';
122 require_once 'CRM/Utils/Array.php';
123 require_once 'CRM/Utils/Date.php';
124 $currentYear = date('Y');
125 $currentMonth = date('m');
126 $previousYear = $currentYear - 1;
127 $nextYear = $currentYear +
1;
129 $todayDate = date('Y-m-d');
131 // the member-since date we will type in to membership form
132 $joinDate = date('Y-m-d', mktime(0, 0, 0, 3, 25, $currentYear));
134 // expected calc'd start date
135 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
137 // expected calc'd end date
138 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
140 $configVars = new CRM_Core_Config_Variables();
142 'joinDate', 'startDate', 'endDate') as $date) {
143 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
147 SELECT end_event_adjust_interval
148 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
198 // Log in using webtestLogin() method
199 $this->webtestLogin();
201 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
203 $title = substr(sha1(rand()), 0, 7);
204 $this->type('organization_name', "Organization $title");
205 $this->type('email_1_email', "$title@org.com");
206 $this->click('_qf_Contact_upload_view');
207 $this->waitForPageToLoad($this->getTimeoutMsec());
209 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
211 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
213 $this->click("link=Add Membership Type");
214 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
216 $this->type('name', "Membership Type $title");
217 $this->type('member_of_contact', $title);
218 $this->click('member_of_contact');
219 $this->waitForElementPresent("css=div.ac_results-inner li");
220 $this->click("css=div.ac_results-inner li");
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', "label=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->assertTrue($this->isTextPresent("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();
300 'joinDate', 'startDate', 'endDate') as $date) {
301 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
305 SELECT end_event_adjust_interval
306 FROM civicrm_membership_status
307 WHERE start_event = 'join_date'
309 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
311 // Add endInterval to July 15 (join date month above) to get end of New status period
312 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
315 // status will be 'New' if today is >= join date and <= endNewStatus date
316 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
321 $this->webtestFillDate('join_date', $joinDate);
324 $this->click('_qf_Membership_upload');
325 $this->waitForPageToLoad($this->getTimeoutMsec());
328 $this->waitForTextPresent($sourceText);
330 // Is status message correct?
331 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
332 "Status message didn't show up after saving!"
335 // click through to the membership view screen
336 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
337 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
339 $this->webtestVerifyTabularData(
341 'Membership Type' => "Membership Type {$title}",
343 'Source' => $sourceText,
344 'Member Since' => $joinDate,
345 'Start date' => $startDate,
346 'End date' => $endDate,
351 function testMembershipTypeScenario3() {
353 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
354 // 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}");
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();
452 'joinDate', 'startDate', 'endDate') as $date) {
453 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
457 SELECT end_event_adjust_interval
458 FROM civicrm_membership_status
459 WHERE start_event = 'join_date'
461 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
463 // Add endInterval to Nov 15 (join date month above) to get end of New status period
464 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
467 // status will be 'New' if today is >= join date and <= endNewStatus date
468 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
473 $this->webtestFillDate('join_date', $joinDate);
476 $this->click('_qf_Membership_upload');
477 $this->waitForPageToLoad($this->getTimeoutMsec());
480 $this->waitForTextPresent($sourceText);
482 // Is status message correct?
483 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
484 "Status message didn't show up after saving!"
487 // click through to the membership view screen
488 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
489 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
491 $this->webtestVerifyTabularData(
493 'Membership Type' => "Membership Type {$title}",
495 'Source' => $sourceText,
496 'Member Since' => $joinDate,
497 'Start date' => $startDate,
498 'End date' => $endDate,
503 function testMembershipTypeScenario4() {
505 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
506 // 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
611 FROM civicrm_membership_status
612 WHERE start_event = 'join_date'
614 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
616 // Add endInterval to Jan 6 (join date month above) to get end of New status period
617 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
1, 15, $currentYear));
620 // status will be 'New' if today is >= join date and <= endNewStatus date
621 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
626 $this->webtestFillDate('join_date', $joinDate);
629 $this->click('_qf_Membership_upload');
630 $this->waitForPageToLoad($this->getTimeoutMsec());
633 $this->waitForTextPresent($sourceText);
635 // Is status message correct?
636 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
637 "Status message didn't show up after saving!"
640 // click through to the membership view screen
641 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
642 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
644 $this->webtestVerifyTabularData(
646 'Membership Type' => "Membership Type $title",
648 'Source' => $sourceText,
649 'Member Since' => $joinDate,
650 'Start date' => $startDate,
651 'End date' => $endDate,