Merge pull request #2804 from atif-shaikh/webtest_fixes
[civicrm-core.git] / tests / phpunit / WebTest / Member / FixedMembershipTypeTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Member_FixedMembershipTypeTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testMembershipTypeScenario1() {
35 // Scenario 1
36 // Rollover Date < Start Date
37 // Join Date > Rollover Date and Join Date < Start Date
38
6a488035
TO
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42daf119 42 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
6a488035
TO
43
44 $title = substr(sha1(rand()), 0, 7);
45 $this->type('organization_name', "Organization $title");
46 $this->type('email_1_email', "$title@org.com");
47 $this->click('_qf_Contact_upload_view');
48 $this->waitForPageToLoad($this->getTimeoutMsec());
49
50 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
51
071a6d2e 52 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
53
54 $this->click("link=Add Membership Type");
55 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
56
57 $this->type('name', "Membership Type $title");
58 $this->type('member_of_contact', $title);
59 $this->click('member_of_contact');
60 $this->waitForElementPresent("css=div.ac_results-inner li");
61 $this->click("css=div.ac_results-inner li");
62
63 $this->type('minimum_fee', '100');
64 $this->select( 'financial_type_id', 'value=2' );
65 $this->type('duration_interval', 1);
66 $this->select('duration_unit', "label=year");
67
68 $this->select('period_type', "label=fixed");
69 $this->waitForElementPresent('fixed_period_rollover_day[d]');
70
71 // fixed period start set to April 1
72 $this->select('fixed_period_start_day[M]', 'value=4');
73 // rollover date set to Jan 31
74 $this->select('fixed_period_rollover_day[M]', 'value=1');
75
76 $this->click('relationship_type_id', 'value=4_b_a');
77
78 $this->click('_qf_MembershipType_upload-bottom');
79 $this->waitForElementPresent('link=Add Membership Type');
80 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
81
071a6d2e 82 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
83
84 $firstName = "John_" . substr(sha1(rand()), 0, 7);
85
86 //fill in first name
87 $this->type('first_name', $firstName);
88
89 //fill in last name
90 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
91 $this->type('last_name', $lastName);
92
93 //fill in email
94 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
95 $this->type('email_1_email', $email);
96
97 // Clicking save.
98 $this->click('_qf_Contact_upload_view');
99 $this->waitForPageToLoad($this->getTimeoutMsec());
100 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
101
102 // click through to the membership view screen
103 $this->click('css=li#tab_member a');
104
105 $this->waitForElementPresent('link=Add Membership');
106 $this->click('link=Add Membership');
107
108 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
109
110 // fill in Membership Organization and Type
111 $this->select('membership_type_id[0]', "label=Organization $title");
112 $this->select('membership_type_id[1]', "label=Membership Type $title");
113
114 $sourceText = "Membership ContactAddTest with Fixed Membership Type";
115 // fill in Source
116 $this->type('source', $sourceText);
117
118 //build the membership dates.
119 require_once 'CRM/Core/Config.php';
120 require_once 'CRM/Utils/Array.php';
121 require_once 'CRM/Utils/Date.php';
122 $currentYear = date('Y');
123 $currentMonth = date('m');
124 $previousYear = $currentYear - 1;
125 $nextYear = $currentYear + 1;
126
127 $todayDate = date('Y-m-d');
128
129 // the member-since date we will type in to membership form
130 $joinDate = date('Y-m-d', mktime(0, 0, 0, 3, 25, $currentYear));
131
132 // expected calc'd start date
133 $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear));
134
135 // expected calc'd end date
136 $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear));
137
138 $configVars = new CRM_Core_Config_Variables();
139 foreach (array(
140 'joinDate', 'startDate', 'endDate') as $date) {
141 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
142 }
143
144 $query = "
76e86fd8
CW
145SELECT end_event_adjust_interval
146
147 FROM civicrm_membership_status
148
6a488035
TO
149 WHERE start_event = 'join_date'
150 AND name = 'New'";
151 $endInterval = CRM_Core_DAO::singleValueQuery($query);
152
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));
155
156 $status = 'Current';
157 // status will be 'New' if today is >= join date and <= endNewStatus date
158 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
159 $status = 'New';
160 }
161
162 // fill in Join Date
163 $this->webtestFillDate('join_date', $joinDate);
164
165 // Clicking save.
166 $this->click('_qf_Membership_upload');
167 $this->waitForPageToLoad($this->getTimeoutMsec());
168
169 // page was loaded
170 $this->waitForTextPresent($sourceText);
171
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!"
175 );
176
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");
180
181 $this->webtestVerifyTabularData(
182 array(
183 'Membership Type' => "Membership Type $title",
184 'Status' => $status,
185 'Source' => $sourceText,
186 'Member Since' => $joinDate,
187 'Start date' => $startDate,
188 'End date' => $endDate,
189 )
190 );
191 }
192
193 function testMembershipTypeScenario2() {
194 // Scenario 2
195 // Rollover Date < Join Date
196
6a488035
TO
197 // Log in using webtestLogin() method
198 $this->webtestLogin();
199
42daf119 200 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
6a488035
TO
201
202 $title = substr(sha1(rand()), 0, 7);
203 $this->type('organization_name', "Organization $title");
204 $this->type('email_1_email', "$title@org.com");
205 $this->click('_qf_Contact_upload_view');
206 $this->waitForPageToLoad($this->getTimeoutMsec());
207
208 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
209
071a6d2e 210 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
211
212 $this->click("link=Add Membership Type");
213 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
214
215 $this->type('name', "Membership Type $title");
216 $this->type('member_of_contact', $title);
217 $this->click('member_of_contact');
218 $this->waitForElementPresent("css=div.ac_results-inner li");
219 $this->click("css=div.ac_results-inner li");
220
221 $this->type('minimum_fee', '100');
222 $this->select( 'financial_type_id', 'value=2' );
223
224 $this->type('duration_interval', 2);
225 $this->select('duration_unit', "label=year");
226
227 $this->select('period_type', "label=fixed");
228 $this->waitForElementPresent('fixed_period_rollover_day[d]');
229
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');
233
234 $this->click('relationship_type_id', 'value=4_b_a');
235
236 $this->click('_qf_MembershipType_upload-bottom');
237 $this->waitForElementPresent('link=Add Membership Type');
238 $this->assertTrue($this->isTextPresent("The membership type 'Membership Type $title' has been saved."));
239
071a6d2e 240 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
241
242 $firstName = "John_" . substr(sha1(rand()), 0, 7);
243
244 //fill in first name
245 $this->type('first_name', $firstName);
246
247 //fill in last name
248 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
249 $this->type('last_name', $lastName);
250
251 //fill in email
252 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
253 $this->type('email_1_email', $email);
254
255 // Clicking save.
256 $this->click('_qf_Contact_upload_view');
257 $this->waitForPageToLoad($this->getTimeoutMsec());
258
259 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
260
261 // click through to the membership add screen
262 $this->click('css=li#tab_member a');
263
264 $this->waitForElementPresent('link=Add Membership');
265 $this->click('link=Add Membership');
266
267 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
268
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}");
274
275 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2";
276 // fill in Source
277 $this->type('source', $sourceText);
278
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;
286
287 $todayDate = date('Y-m-d');
288
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));
291
292 // expected calc'd start date
293 $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear));
294
295 // expected calc'd end date
296 $endDate = date('Y-m-d', mktime(0, 0, 0, 8, 31, $currentYear + 2));
297 $configVars = new CRM_Core_Config_Variables();
298 foreach (array(
299 'joinDate', 'startDate', 'endDate') as $date) {
300 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
301 }
302
303 $query = "
76e86fd8
CW
304SELECT end_event_adjust_interval
305
306 FROM civicrm_membership_status
307
6a488035
TO
308 WHERE start_event = 'join_date'
309 AND name = 'New'";
310 $endInterval = CRM_Core_DAO::singleValueQuery($query);
311
312 // Add endInterval to July 15 (join date month above) to get end of New status period
313 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 7, 15, $currentYear));
314
315 $status = 'Current';
316 // status will be 'New' if today is >= join date and <= endNewStatus date
317 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
318 $status = 'New';
319 }
320
321 // fill in Join Date
322 $this->webtestFillDate('join_date', $joinDate);
323
324 // Clicking save.
325 $this->click('_qf_Membership_upload');
326 $this->waitForPageToLoad($this->getTimeoutMsec());
327
328 // page was loaded
329 $this->waitForTextPresent($sourceText);
330
331 // Is status message correct?
332 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
333 "Status message didn't show up after saving!"
334 );
335
336 // click through to the membership view screen
337 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
338 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
339
340 $this->webtestVerifyTabularData(
341 array(
342 'Membership Type' => "Membership Type {$title}",
343 'Status' => $status,
344 'Source' => $sourceText,
345 'Member Since' => $joinDate,
346 'Start date' => $startDate,
347 'End date' => $endDate,
348 )
349 );
350 }
351
352 function testMembershipTypeScenario3() {
353 // Scenario 3
354 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
355 // Join Date is later than Rollover Date
356
6a488035
TO
357 // Log in using webtestLogin() method
358 $this->webtestLogin();
359
42daf119 360 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
6a488035
TO
361
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());
367
368 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
369
071a6d2e 370 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
371
372 $this->click("link=Add Membership Type");
373 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
374
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");
380
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");
385
386 $this->select('period_type', "label=fixed");
387 $this->waitForElementPresent('fixed_period_rollover_day[d]');
388
389 $this->select('fixed_period_rollover_day[M]', 'value=10');
390 $this->select('fixed_period_rollover_day[d]', 'value=31');
391
392 $this->click('relationship_type_id', 'value=4_b_a');
393
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."));
397
071a6d2e 398 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
399
400 $firstName = "John_" . substr(sha1(rand()), 0, 7);
401
402 //fill in first name
403 $this->type('first_name', $firstName);
404
405 //fill in last name
406 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
407 $this->type('last_name', $lastName);
408
409 //fill in email
410 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
411 $this->type('email_1_email', $email);
412
413 // Clicking save.
414 $this->click('_qf_Contact_upload_view');
415 $this->waitForPageToLoad($this->getTimeoutMsec());
416
417 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
418
419 // click through to the membership view screen
420 $this->click('css=li#tab_member a');
421
422 $this->waitForElementPresent('link=Add Membership');
423 $this->click('link=Add Membership');
424
425 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
426
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}");
432
6a488035
TO
433 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3";
434 // fill in Source
435 $this->type('source', $sourceText);
436
437 //build the membership dates.
438 require_once 'CRM/Core/Config.php';
439 require_once 'CRM/Utils/Array.php';
440 require_once 'CRM/Utils/Date.php';
441 $currentYear = date('Y');
442 $currentMonth = date('m');
443 $previousYear = $currentYear - 1;
444 $nextYear = $currentYear + 1;
445 $todayDate = date('Y-m-d');
446 $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear));
447 $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear));
448 $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear));
449 $configVars = new CRM_Core_Config_Variables();
450 foreach (array(
451 'joinDate', 'startDate', 'endDate') as $date) {
452 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
453 }
454
455 $query = "
76e86fd8
CW
456SELECT end_event_adjust_interval
457
458 FROM civicrm_membership_status
459
6a488035
TO
460 WHERE start_event = 'join_date'
461 AND name = 'New'";
462 $endInterval = CRM_Core_DAO::singleValueQuery($query);
463
464 // Add endInterval to Nov 15 (join date month above) to get end of New status period
465 $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear));
466
467 $status = 'Current';
468 // status will be 'New' if today is >= join date and <= endNewStatus date
469 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
470 $status = 'New';
471 }
472
473 // fill in Join Date
474 $this->webtestFillDate('join_date', $joinDate);
475
476 // Clicking save.
477 $this->click('_qf_Membership_upload');
478 $this->waitForPageToLoad($this->getTimeoutMsec());
479
480 // page was loaded
481 $this->waitForTextPresent($sourceText);
482
483 // Is status message correct?
484 $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."),
485 "Status message didn't show up after saving!"
486 );
487
488 // click through to the membership view screen
489 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
490 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
491
492 $this->webtestVerifyTabularData(
493 array(
494 'Membership Type' => "Membership Type {$title}",
495 'Status' => $status,
496 'Source' => $sourceText,
497 'Member Since' => $joinDate,
498 'Start date' => $startDate,
499 'End date' => $endDate,
500 )
501 );
502 }
503
504 function testMembershipTypeScenario4() {
505 // Scenario 4
506 // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover
507 // Join Date is earlier than Rollover Date
508
6a488035
TO
509 // Log in using webtestLogin() method
510 $this->webtestLogin();
511
42daf119 512 $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel');
6a488035
TO
513
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());
519
520 $this->assertTrue($this->isTextPresent("Organization $title has been created."));
521
071a6d2e 522 $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse");
6a488035
TO
523
524 $this->click("link=Add Membership Type");
525 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
526
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");
76e86fd8 532
6a488035
TO
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");
537
538 $this->select('period_type', "label=fixed");
539 $this->waitForElementPresent('fixed_period_rollover_day[d]');
540
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');
544
545 $this->click('relationship_type_id', 'value=4_b_a');
546
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."));
550
071a6d2e 551 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
6a488035
TO
552
553 $firstName = "John_" . substr(sha1(rand()), 0, 7);
554
555 //fill in first name
556 $this->type('first_name', $firstName);
557
558 //fill in last name
559 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);;
560 $this->type('last_name', $lastName);
561
562 //fill in email
563 $email = substr(sha1(rand()), 0, 7) . "john@gmail.com";
564 $this->type('email_1_email', $email);
565
566 // Clicking save.
567 $this->click('_qf_Contact_upload_view');
568 $this->waitForPageToLoad($this->getTimeoutMsec());
569
570 $this->assertTrue($this->isTextPresent("$firstName $lastName has been created."));
571
572 // click through to the membership view screen
573 $this->click('css=li#tab_member a');
574
575 $this->waitForElementPresent('link=Add Membership');
576 $this->click('link=Add Membership');
577
578 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
579
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");
583
584 $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4";
585 // fill in Source
586 $this->type('source', $sourceText);
587
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');
596
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));
599
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();
604 foreach (array(
605 'joinDate', 'startDate', 'endDate') as $date) {
606 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
607 }
608
609 $query = "
76e86fd8
CW
610SELECT end_event_adjust_interval
611
612 FROM civicrm_membership_status
613
6a488035
TO
614 WHERE start_event = 'join_date'
615 AND name = 'New'";
616 $endInterval = CRM_Core_DAO::singleValueQuery($query);
617
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));
620
621 $status = 'Current';
622 // status will be 'New' if today is >= join date and <= endNewStatus date
623 if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) {
624 $status = 'New';
625 }
626
627 // fill in Join Date
628 $this->webtestFillDate('join_date', $joinDate);
629
630 // Clicking save.
631 $this->click('_qf_Membership_upload');
632 $this->waitForPageToLoad($this->getTimeoutMsec());
633
634 // page was loaded
635 $this->waitForTextPresent($sourceText);
636
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!"
640 );
641
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");
645
646 $this->webtestVerifyTabularData(
647 array(
648 'Membership Type' => "Membership Type $title",
649 'Status' => $status,
650 'Source' => $sourceText,
651 'Member Since' => $joinDate,
652 'Start date' => $startDate,
653 'End date' => $endDate,
654 )
655 );
656 }
657}
658