3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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';
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();
141 'joinDate', 'startDate', 'endDate') as $date) {
142 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
146 SELECT end_event_adjust_interval
148 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');
170 $this->waitForTextPresent($sourceText);
172 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
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 public function testMembershipTypeScenario2() {
196 // 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->select2('member_of_contact_id',$title);
219 $this->type('minimum_fee', '100');
220 $this->select( 'financial_type_id', 'value=2' );
222 $this->type('duration_interval', 2);
223 $this->select('duration_unit', "label=year");
225 $this->select('period_type', "value=fixed");
226 $this->waitForElementPresent('fixed_period_rollover_day[d]');
228 $this->select('fixed_period_start_day[M]', 'value=9');
229 $this->select('fixed_period_rollover_day[M]', 'value=6');
230 $this->select('fixed_period_rollover_day[d]', 'value=30');
232 $this->click('relationship_type_id', 'value=4_b_a');
234 $this->click('_qf_MembershipType_upload-bottom');
235 $this->waitForElementPresent('link=Add Membership Type');
236 $this->waitForText('crm-notification-container',"The membership type 'Membership Type $title' has been saved.");
238 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
240 $firstName = "John_" . substr(sha1(rand()), 0, 7);
243 $this->type('first_name', $firstName);
246 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
247 $this->type('last_name', $lastName);
250 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
251 $this->type('email_1_email', $email);
254 $this->click('_qf_Contact_upload_view');
255 $this->waitForPageToLoad($this->getTimeoutMsec());
257 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
259 // click through to the membership add screen
260 $this->click('css=li#tab_member a');
262 $this->waitForElementPresent('link=Add Membership');
263 $this->click('link=Add Membership');
265 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
267 // fill in Membership Organization and Type
268 $this->select('membership_type_id[0]', "label=Organization {$title}");
269 // Wait for membership type select to reload
270 $this->waitForTextPresent("Membership Type {$title}");
271 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
273 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
275 $this->type('source', $sourceText);
277 //build the membership dates.
278 require_once 'CRM/Core/Config.php';
279 require_once 'CRM/Utils/Array.php';
280 require_once 'CRM/Utils/Date.php';
281 $currentYear = date('Y');
282 $currentMonth = date('m');
283 $previousYear = $currentYear - 1;
285 $todayDate = date('Y-m-d');
287 // the member-since date we will type in to membership form
288 $joinDate = date('Y-m-d', mktime(0, 0, 0, 7, 15, $currentYear));
290 // expected calc'd start date
291 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
293 // expected calc'd end date
294 $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear +
2));
295 $configVars = new CRM_Core_Config_Variables();
297 'joinDate', 'startDate', 'endDate') as $date) {
298 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
302 SELECT end_event_adjust_interval
304 FROM civicrm_membership_status
306 WHERE start_event = 'join_date'
308 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
310 // Add endInterval to July 15 (join date month above) to get end of New status period
311 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
7, 15, $currentYear));
314 // status will be 'New' if today is >= join date and <= endNewStatus date
315 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
320 $this->webtestFillDate('join_date', $joinDate);
323 $this->click('_qf_Membership_upload');
324 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
327 $this->waitForTextPresent($sourceText);
329 // Is status message correct?
330 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
331 "Status message didn't show up after saving!"
334 // click through to the membership view screen
335 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
336 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
338 $this->webtestVerifyTabularData(
340 'Membership Type' => "Membership Type {$title}",
342 'Source' => $sourceText,
343 'Member Since' => $joinDate,
344 'Start date' => $startDate,
345 'End date' => $endDate,
350 public function testMembershipTypeScenario3() {
352 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
353 // Join Date is later than Rollover Date
355 // Log in using webtestLogin() method
356 $this->webtestLogin();
358 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
360 $title = substr(sha1(rand()), 0, 7);
361 $this->type('organization_name', "Organization $title");
362 $this->type('email_1_email', "$title@org.com");
363 $this->click('_qf_Contact_upload_view');
364 $this->waitForPageToLoad($this->getTimeoutMsec());
366 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
368 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
370 $this->click("link=Add Membership Type");
371 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
373 $this->type('name', "Membership Type $title");
374 $this->select2('member_of_contact_id',$title);
376 $this->type('minimum_fee', '100');
377 $this->select( 'financial_type_id', 'value=2' );
378 $this->type('duration_interval', 1);
379 $this->select('duration_unit', "label=year");
381 $this->select('period_type', "value=fixed");
382 $this->waitForElementPresent('fixed_period_rollover_day[d]');
384 $this->select('fixed_period_rollover_day[M]', 'value=10');
385 $this->select('fixed_period_rollover_day[d]', 'value=31');
387 $this->click('relationship_type_id', 'value=4_b_a');
389 $this->click('_qf_MembershipType_upload-bottom');
390 $this->waitForElementPresent('link=Add Membership Type');
392 $this->waitForText('crm-notification-container',"The membership type 'Membership Type $title' has been saved.");
393 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
395 $firstName = "John_" . substr(sha1(rand()), 0, 7);
398 $this->type('first_name', $firstName);
401 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
402 $this->type('last_name', $lastName);
405 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
406 $this->type('email_1_email', $email);
409 $this->click('_qf_Contact_upload_view');
410 $this->waitForPageToLoad($this->getTimeoutMsec());
412 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
414 // click through to the membership view screen
415 $this->click('css=li#tab_member a');
417 $this->waitForElementPresent('link=Add Membership');
418 $this->click('link=Add Membership');
420 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
422 // fill in Membership Organization and Type
423 $this->select('membership_type_id[0]', "label=Organization {$title}");
424 // Wait for membership type select to reload
425 $this->waitForTextPresent("Membership Type {$title}");
426 $this->select('membership_type_id[1]', "label=Membership Type {$title}");
428 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
430 $this->type('source', $sourceText);
432 //build the membership dates.
433 require_once 'CRM/Core/Config.php';
434 require_once 'CRM/Utils/Array.php';
435 require_once 'CRM/Utils/Date.php';
436 $currentYear = date('Y');
437 $currentMonth = date('m');
438 $previousYear = $currentYear - 1;
439 $nextYear = $currentYear +
1;
440 $todayDate = date('Y-m-d');
441 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
442 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
443 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
444 $configVars = new CRM_Core_Config_Variables();
446 'joinDate', 'startDate', 'endDate') as $date) {
447 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
451 SELECT end_event_adjust_interval
453 FROM civicrm_membership_status
455 WHERE start_event = 'join_date'
457 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
459 // Add endInterval to Nov 15 (join date month above) to get end of New status period
460 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
463 // status will be 'New' if today is >= join date and <= endNewStatus date
464 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
469 $this->webtestFillDate('join_date', $joinDate);
472 $this->click('_qf_Membership_upload');
473 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
476 $this->waitForTextPresent($sourceText);
478 // Is status message correct?
479 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
480 "Status message didn't show up after saving!"
483 // click through to the membership view screen
484 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
485 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
487 $this->webtestVerifyTabularData(
489 'Membership Type' => "Membership Type {$title}",
491 'Source' => $sourceText,
492 'Member Since' => $joinDate,
493 'Start date' => $startDate,
494 'End date' => $endDate,
499 public function testMembershipTypeScenario4() {
501 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
502 // Join Date is earlier than Rollover Date
504 // Log in using webtestLogin() method
505 $this->webtestLogin();
507 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
509 $title = substr(sha1(rand()), 0, 7);
510 $this->type('organization_name', "Organization $title");
511 $this->type('email_1_email', "$title@org.com");
512 $this->click('_qf_Contact_upload_view');
513 $this->waitForPageToLoad($this->getTimeoutMsec());
515 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
517 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
519 $this->click("link=Add Membership Type");
520 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
522 $this->type('name', "Membership Type $title");
523 $this->select2('member_of_contact_id',$title);
525 $this->type('minimum_fee', '100');
526 $this->select( 'financial_type_id', 'value=2' );
527 $this->type('duration_interval', 1);
528 $this->select('duration_unit', "label=year");
530 $this->select('period_type', "value=fixed");
531 $this->waitForElementPresent('fixed_period_rollover_day[d]');
533 $this->select('fixed_period_start_day[M]', 'value=1');
534 $this->select('fixed_period_rollover_day[M]', 'value=10');
535 $this->select('fixed_period_rollover_day[d]', 'value=31');
537 $this->click('relationship_type_id', 'value=4_b_a');
539 $this->click('_qf_MembershipType_upload-bottom');
540 $this->waitForElementPresent('link=Add Membership Type');
541 $this->waitForText('crm-notification-container',"The membership type 'Membership Type $title' has been saved.");
543 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
545 $firstName = "John_" . substr(sha1(rand()), 0, 7);
548 $this->type('first_name', $firstName);
551 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
552 $this->type('last_name', $lastName);
555 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
556 $this->type('email_1_email', $email);
559 $this->click('_qf_Contact_upload_view');
560 $this->waitForPageToLoad($this->getTimeoutMsec());
562 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
564 // click through to the membership view screen
565 $this->click('css=li#tab_member a');
567 $this->waitForElementPresent('link=Add Membership');
568 $this->click('link=Add Membership');
570 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
572 // fill in Membership Organization and Type
573 $this->select('membership_type_id[0]', "label=Organization $title");
574 $this->select('membership_type_id[1]', "label=Membership Type $title");
576 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
578 $this->type('source', $sourceText);
580 //build the membership dates.
581 require_once 'CRM/Core/Config.php';
582 require_once 'CRM/Utils/Array.php';
583 require_once 'CRM/Utils/Date.php';
584 $currentYear = date('Y');
585 $currentMonth = date('m');
586 $nextYear = $currentYear +
1;
587 $todayDate = date('Y-m-d');
589 // the member-since date we will type in to membership form
590 $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear));
592 // expected calc'd start and end dates
593 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
594 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear));
595 $configVars = new CRM_Core_Config_Variables();
597 'joinDate', 'startDate', 'endDate') as $date) {
598 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
602 SELECT end_event_adjust_interval
604 FROM civicrm_membership_status
606 WHERE start_event = 'join_date'
608 $endInterval = CRM_Core_DAO
::singleValueQuery($query);
610 // Add endInterval to Jan 6 (join date month above) to get end of New status period
611 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval +
1, 15, $currentYear));
614 // status will be 'New' if today is >= join date and <= endNewStatus date
615 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
620 $this->webtestFillDate('join_date', $joinDate);
623 $this->click('_qf_Membership_upload');
624 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
627 $this->waitForTextPresent($sourceText);
629 // Is status message correct?
630 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
631 "Status message didn't show up after saving!"
634 // click through to the membership view screen
635 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
636 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
638 $this->webtestVerifyTabularData(
640 'Membership Type' => "Membership Type $title",
642 'Source' => $sourceText,
643 'Member Since' => $joinDate,
644 'Start date' => $startDate,
645 'End date' => $endDate,