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->open($this->sboxPath
. "civicrm/admin/member/membershipType?reset=1&action=browse");
55 $this->waitForPageToLoad($this->getTimeoutMsec());
57 $this->click("link=Add Membership Type");
58 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
60 $this->type('name', "Membership Type $title");
61 $this->type('member_of_contact', $title);
62 $this->click('member_of_contact');
63 $this->waitForElementPresent("css=div.ac_results-inner li");
64 $this->click("css=div.ac_results-inner li");
66 $this->type('minimum_fee', '100');
67 $this->select( 'financial_type_id', 'value=2' );
68 $this->type('duration_interval', 1);
69 $this->select('duration_unit', "label=year");
71 $this->select('period_type', "label=fixed");
72 $this->waitForElementPresent('fixed_period_rollover_day[d]');
74 // fixed period start set to April 1
75 $this->select('fixed_period_start_day[M]', 'value=4');
76 // rollover date set to Jan 31
77 $this->select('fixed_period_rollover_day[M]', 'value=1');
79 $this->click('relationship_type_id', 'value=4_b_a');
81 $this->click('_qf_MembershipType_upload-bottom');
82 $this->waitForElementPresent('link=Add Membership Type');
83 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
85 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Individual");
87 $firstName = "John_" . substr(sha1(rand()), 0, 7);
90 $this->type('first_name', $firstName);
93 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
94 $this->type('last_name', $lastName);
97 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
98 $this->type('email_1_email', $email);
101 $this->click('_qf_Contact_upload_view');
102 $this->waitForPageToLoad($this->getTimeoutMsec());
103 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
105 // click through to the membership view screen
106 $this->click('css=li#tab_member a');
108 $this->waitForElementPresent('link=Add Membership');
109 $this->click('link=Add Membership');
111 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
113 // fill in Membership Organization and Type
114 $this->select('membership_type_id[0]', "label=Organization $title");
115 $this->select('membership_type_id[1]', "label=Membership Type $title");
117 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
119 $this->type('source', $sourceText);
121 //build the membership dates.
122 require_once 'CRM/Core/Config.php';
123 require_once 'CRM/Utils/Array.php';
124 require_once 'CRM/Utils/Date.php';
125 $currentYear = date('Y');
126 $currentMonth = date('m');
127 $previousYear = $currentYear - 1;
128 $nextYear = $currentYear +
1;
130 $todayDate = date('Y-m-d');
132 // the member-since date we will type in to membership form
133 $joinDate = date('Y-m-d', mktime(0, 0, 0, 3, 25, $currentYear));
135 // expected calc'd start date
136 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
138 // expected calc'd end date
139 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
141 $configVars = new CRM_Core_Config_Variables();
143 'joinDate', 'startDate', 'endDate') as $date) {
144 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
148 SELECT end_event_adjust_interval
149 FROM civicrm_membership_status
150 WHERE start_event = 'join_date'
152 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
154 // Add endInterval to March 25 (join date month above) to get end of New status period
155 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
3, 25, $currentYear));
158 // status will be 'New' if today is >= join date and <= endNewStatus date
159 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
164 $this->webtestFillDate('join_date', $joinDate);
167 $this->click('_qf_Membership_upload');
168 $this->waitForPageToLoad($this->getTimeoutMsec());
171 $this->waitForTextPresent($sourceText);
173 // Is status message correct?
174 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
175 "Status message didn't show up after saving!"
178 // click through to the membership view screen
179 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
180 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
182 $this->webtestVerifyTabularData(
184 'Membership Type' => "Membership Type $title",
186 'Source' => $sourceText,
187 'Member Since' => $joinDate,
188 'Start date' => $startDate,
189 'End date' => $endDate,
194 function testMembershipTypeScenario2() {
196 // Rollover Date < Join Date
199 // Log in using webtestLogin() method
200 $this->webtestLogin();
202 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
204 $title = substr(sha1(rand()), 0, 7);
205 $this->type('organization_name', "Organization $title");
206 $this->type('email_1_email', "$title@org.com");
207 $this->click('_qf_Contact_upload_view');
208 $this->waitForPageToLoad($this->getTimeoutMsec());
210 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
212 $this->open($this->sboxPath
. "civicrm/admin/member/membershipType?reset=1&action=browse");
213 $this->waitForPageToLoad($this->getTimeoutMsec());
215 $this->click("link=Add Membership Type");
216 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
218 $this->type('name', "Membership Type $title");
219 $this->type('member_of_contact', $title);
220 $this->click('member_of_contact');
221 $this->waitForElementPresent("css=div.ac_results-inner li");
222 $this->click("css=div.ac_results-inner li");
224 $this->type('minimum_fee', '100');
225 $this->select( 'financial_type_id', 'value=2' );
227 $this->type('duration_interval', 2);
228 $this->select('duration_unit', "label=year");
230 $this->select('period_type', "label=fixed");
231 $this->waitForElementPresent('fixed_period_rollover_day[d]');
233 $this->select('fixed_period_start_day[M]', 'value=9');
234 $this->select('fixed_period_rollover_day[M]', 'value=6');
235 $this->select('fixed_period_rollover_day[d]', 'value=30');
237 $this->click('relationship_type_id', 'value=4_b_a');
239 $this->click('_qf_MembershipType_upload-bottom');
240 $this->waitForElementPresent('link=Add Membership Type');
241 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
243 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Individual");
245 $firstName = "John_" . substr(sha1(rand()), 0, 7);
248 $this->type('first_name', $firstName);
251 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
252 $this->type('last_name', $lastName);
255 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
256 $this->type('email_1_email', $email);
259 $this->click('_qf_Contact_upload_view');
260 $this->waitForPageToLoad($this->getTimeoutMsec());
262 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
264 // click through to the membership add screen
265 $this->click('css=li#tab_member a');
267 $this->waitForElementPresent('link=Add Membership');
268 $this->click('link=Add Membership');
270 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
272 // fill in Membership Organization and Type
273 $this->select('membership_type_id[0]', "label=Organization {$title}");
274 // Wait for membership type select to reload
275 $this->waitForTextPresent("Membership Type {$title}");
276 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
278 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
280 $this->type('source', $sourceText);
282 //build the membership dates.
283 require_once 'CRM/Core/Config.php';
284 require_once 'CRM/Utils/Array.php';
285 require_once 'CRM/Utils/Date.php';
286 $currentYear = date('Y');
287 $currentMonth = date('m');
288 $previousYear = $currentYear - 1;
290 $todayDate = date('Y-m-d');
292 // the member-since date we will type in to membership form
293 $joinDate = date('Y-m-d', mktime(0, 0, 0, 7, 15, $currentYear));
295 // expected calc'd start date
296 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
298 // expected calc'd end date
299 $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear +
2));
300 $configVars = new CRM_Core_Config_Variables();
302 'joinDate', 'startDate', 'endDate') as $date) {
303 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
307 SELECT end_event_adjust_interval
308 FROM civicrm_membership_status
309 WHERE start_event = 'join_date'
311 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
313 // Add endInterval to July 15 (join date month above) to get end of New status period
314 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
317 // status will be 'New' if today is >= join date and <= endNewStatus date
318 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
323 $this->webtestFillDate('join_date', $joinDate);
326 $this->click('_qf_Membership_upload');
327 $this->waitForPageToLoad($this->getTimeoutMsec());
330 $this->waitForTextPresent($sourceText);
332 // Is status message correct?
333 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
334 "Status message didn't show up after saving!"
337 // click through to the membership view screen
338 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
339 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
341 $this->webtestVerifyTabularData(
343 'Membership Type' => "Membership Type {$title}",
345 'Source' => $sourceText,
346 'Member Since' => $joinDate,
347 'Start date' => $startDate,
348 'End date' => $endDate,
353 function testMembershipTypeScenario3() {
355 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
356 // 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->open($this->sboxPath
. "civicrm/admin/member/membershipType?reset=1&action=browse");
373 $this->waitForPageToLoad($this->getTimeoutMsec());
375 $this->click("link=Add Membership Type");
376 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
378 $this->type('name', "Membership Type $title");
379 $this->type('member_of_contact', $title);
380 $this->click('member_of_contact');
381 $this->waitForElementPresent("css=div.ac_results-inner li");
382 $this->click("css=div.ac_results-inner li");
384 $this->type('minimum_fee', '100');
385 $this->select( 'financial_type_id', 'value=2' );
386 $this->type('duration_interval', 1);
387 $this->select('duration_unit', "label=year");
389 $this->select('period_type', "label=fixed");
390 $this->waitForElementPresent('fixed_period_rollover_day[d]');
392 $this->select('fixed_period_rollover_day[M]', 'value=10');
393 $this->select('fixed_period_rollover_day[d]', 'value=31');
395 $this->click('relationship_type_id', 'value=4_b_a');
397 $this->click('_qf_MembershipType_upload-bottom');
398 $this->waitForElementPresent('link=Add Membership Type');
399 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
401 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Individual");
403 $firstName = "John_" . substr(sha1(rand()), 0, 7);
406 $this->type('first_name', $firstName);
409 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
410 $this->type('last_name', $lastName);
413 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
414 $this->type('email_1_email', $email);
417 $this->click('_qf_Contact_upload_view');
418 $this->waitForPageToLoad($this->getTimeoutMsec());
420 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
422 // click through to the membership view screen
423 $this->click('css=li#tab_member a');
425 $this->waitForElementPresent('link=Add Membership');
426 $this->click('link=Add Membership');
428 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
430 // fill in Membership Organization and Type
431 $this->select('membership_type_id[0]', "label=Organization {$title}");
432 // Wait for membership type select to reload
433 $this->waitForTextPresent("Membership Type {$title}");
434 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
437 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
439 $this->type('source', $sourceText);
441 //build the membership dates.
442 require_once 'CRM/Core/Config.php';
443 require_once 'CRM/Utils/Array.php';
444 require_once 'CRM/Utils/Date.php';
445 $currentYear = date('Y');
446 $currentMonth = date('m');
447 $previousYear = $currentYear - 1;
448 $nextYear = $currentYear +
1;
449 $todayDate = date('Y-m-d');
450 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
451 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
452 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
453 $configVars = new CRM_Core_Config_Variables();
455 'joinDate', 'startDate', 'endDate') as $date) {
456 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
460 SELECT end_event_adjust_interval
461 FROM civicrm_membership_status
462 WHERE start_event = 'join_date'
464 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
466 // Add endInterval to Nov 15 (join date month above) to get end of New status period
467 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
470 // status will be 'New' if today is >= join date and <= endNewStatus date
471 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
476 $this->webtestFillDate('join_date', $joinDate);
479 $this->click('_qf_Membership_upload');
480 $this->waitForPageToLoad($this->getTimeoutMsec());
483 $this->waitForTextPresent($sourceText);
485 // Is status message correct?
486 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
487 "Status message didn't show up after saving!"
490 // click through to the membership view screen
491 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
492 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
494 $this->webtestVerifyTabularData(
496 'Membership Type' => "Membership Type {$title}",
498 'Source' => $sourceText,
499 'Member Since' => $joinDate,
500 'Start date' => $startDate,
501 'End date' => $endDate,
506 function testMembershipTypeScenario4() {
508 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
509 // Join Date is earlier than Rollover Date
512 // Log in using webtestLogin() method
513 $this->webtestLogin();
515 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
517 $title = substr(sha1(rand()), 0, 7);
518 $this->type('organization_name', "Organization $title");
519 $this->type('email_1_email', "$title@org.com");
520 $this->click('_qf_Contact_upload_view');
521 $this->waitForPageToLoad($this->getTimeoutMsec());
523 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
525 $this->open($this->sboxPath
. "civicrm/admin/member/membershipType?reset=1&action=browse");
526 $this->waitForPageToLoad($this->getTimeoutMsec());
528 $this->click("link=Add Membership Type");
529 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
531 $this->type('name', "Membership Type $title");
532 $this->type('member_of_contact', $title);
533 $this->click('member_of_contact');
534 $this->waitForElementPresent("css=div.ac_results-inner li");
535 $this->click("css=div.ac_results-inner li");
537 $this->type('minimum_fee', '100');
538 $this->select( 'financial_type_id', 'value=2' );
539 $this->type('duration_interval', 1);
540 $this->select('duration_unit', "label=year");
542 $this->select('period_type', "label=fixed");
543 $this->waitForElementPresent('fixed_period_rollover_day[d]');
545 $this->select('fixed_period_start_day[M]', 'value=1');
546 $this->select('fixed_period_rollover_day[M]', 'value=10');
547 $this->select('fixed_period_rollover_day[d]', 'value=31');
549 $this->click('relationship_type_id', 'value=4_b_a');
551 $this->click('_qf_MembershipType_upload-bottom');
552 $this->waitForElementPresent('link=Add Membership Type');
553 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
555 $this->open($this->sboxPath
. "civicrm/contact/add?reset=1&ct=Individual");
557 $firstName = "John_" . substr(sha1(rand()), 0, 7);
560 $this->type('first_name', $firstName);
563 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
564 $this->type('last_name', $lastName);
567 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
568 $this->type('email_1_email', $email);
571 $this->click('_qf_Contact_upload_view');
572 $this->waitForPageToLoad($this->getTimeoutMsec());
574 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
576 // click through to the membership view screen
577 $this->click('css=li#tab_member a');
579 $this->waitForElementPresent('link=Add Membership');
580 $this->click('link=Add Membership');
582 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
584 // fill in Membership Organization and Type
585 $this->select('membership_type_id[0]', "label=Organization $title");
586 $this->select('membership_type_id[1]', "label=Membership Type $title");
588 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
590 $this->type('source', $sourceText);
592 //build the membership dates.
593 require_once 'CRM/Core/Config.php';
594 require_once 'CRM/Utils/Array.php';
595 require_once 'CRM/Utils/Date.php';
596 $currentYear = date('Y');
597 $currentMonth = date('m');
598 $nextYear = $currentYear +
1;
599 $todayDate = date('Y-m-d');
601 // the member-since date we will type in to membership form
602 $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear));
604 // expected calc'd start and end dates
605 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
606 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear));
607 $configVars = new CRM_Core_Config_Variables();
609 'joinDate', 'startDate', 'endDate') as $date) {
610 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
614 SELECT end_event_adjust_interval
615 FROM civicrm_membership_status
616 WHERE start_event = 'join_date'
618 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
620 // Add endInterval to Jan 6 (join date month above) to get end of New status period
621 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
1, 15, $currentYear));
624 // status will be 'New' if today is >= join date and <= endNewStatus date
625 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
630 $this->webtestFillDate('join_date', $joinDate);
633 $this->click('_qf_Membership_upload');
634 $this->waitForPageToLoad($this->getTimeoutMsec());
637 $this->waitForTextPresent($sourceText);
639 // Is status message correct?
640 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
641 "Status message didn't show up after saving!"
644 // click through to the membership view screen
645 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
646 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
648 $this->webtestVerifyTabularData(
650 'Membership Type' => "Membership Type $title",
652 'Source' => $sourceText,
653 'Member Since' => $joinDate,
654 'Start date' => $startDate,
655 'End date' => $endDate,