Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Member_FixedMembershipTypeTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_FixedMembershipTypeTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testMembershipTypeScenario1() { |
6a488035 TO |
39 | // Scenario 1 |
40 | // Rollover Date < Start Date | |
41 | // Join Date > Rollover Date and Join Date < Start Date | |
42 | ||
6a488035 TO |
43 | // Log in using webtestLogin() method |
44 | $this->webtestLogin(); | |
45 | ||
42daf119 | 46 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
47 | |
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()); | |
53 | ||
54 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
55 | ||
071a6d2e | 56 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
57 | |
58 | $this->click("link=Add Membership Type"); | |
59 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
60 | ||
61 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 62 | $this->select2('member_of_contact_id', $title); |
6a488035 TO |
63 | |
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"); | |
68 | ||
5ddf4885 | 69 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
70 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
71 | ||
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'); | |
76 | ||
77 | $this->click('relationship_type_id', 'value=4_b_a'); | |
78 | ||
79 | $this->click('_qf_MembershipType_upload-bottom'); | |
80 | $this->waitForElementPresent('link=Add Membership Type'); | |
6c6e6187 | 81 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
6a488035 | 82 | |
071a6d2e | 83 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
84 | |
85 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
86 | ||
87 | //fill in first name | |
88 | $this->type('first_name', $firstName); | |
89 | ||
90 | //fill in last name | |
91 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
92 | $this->type('last_name', $lastName); | |
93 | ||
94 | //fill in email | |
95 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
96 | $this->type('email_1_email', $email); | |
97 | ||
98 | // Clicking save. | |
99 | $this->click('_qf_Contact_upload_view'); | |
100 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
101 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
102 | ||
103 | // click through to the membership view screen | |
104 | $this->click('css=li#tab_member a'); | |
105 | ||
106 | $this->waitForElementPresent('link=Add Membership'); | |
107 | $this->click('link=Add Membership'); | |
108 | ||
109 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
110 | ||
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"); | |
114 | ||
115 | $sourceText = "Membership ContactAddTest with Fixed Membership Type"; | |
116 | // fill in Source | |
117 | $this->type('source', $sourceText); | |
118 | ||
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; | |
127 | ||
128 | $todayDate = date('Y-m-d'); | |
129 | ||
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)); | |
132 | ||
133 | // expected calc'd start date | |
134 | $startDate = date('Y-m-d', mktime(0, 0, 0, 4, 1, $previousYear)); | |
135 | ||
136 | // expected calc'd end date | |
137 | $endDate = date('Y-m-d', mktime(0, 0, 0, 3, 31, $nextYear)); | |
138 | ||
139 | $configVars = new CRM_Core_Config_Variables(); | |
140 | foreach (array( | |
141 | 'joinDate', 'startDate', 'endDate') as $date) { | |
142 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
143 | } | |
144 | ||
145 | $query = " | |
76e86fd8 CW |
146 | SELECT end_event_adjust_interval |
147 | ||
148 | FROM civicrm_membership_status | |
149 | ||
6a488035 TO |
150 | WHERE start_event = 'join_date' |
151 | AND name = 'New'"; | |
152 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
153 | ||
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)); | |
156 | ||
157 | $status = 'Current'; | |
158 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
159 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
160 | $status = 'New'; | |
161 | } | |
162 | ||
163 | // fill in Join Date | |
164 | $this->webtestFillDate('join_date', $joinDate); | |
165 | ||
166 | // Clicking save. | |
167 | $this->click('_qf_Membership_upload'); | |
6a488035 TO |
168 | |
169 | // page was loaded | |
170 | $this->waitForTextPresent($sourceText); | |
171 | ||
c900afb1 | 172 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
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!" | |
176 | ); | |
177 | ||
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"); | |
181 | ||
182 | $this->webtestVerifyTabularData( | |
183 | array( | |
184 | 'Membership Type' => "Membership Type $title", | |
185 | 'Status' => $status, | |
186 | 'Source' => $sourceText, | |
187 | 'Member Since' => $joinDate, | |
188 | 'Start date' => $startDate, | |
189 | 'End date' => $endDate, | |
190 | ) | |
191 | ); | |
192 | } | |
193 | ||
00be9182 | 194 | public function testMembershipTypeScenario2() { |
6a488035 TO |
195 | // Scenario 2 |
196 | // Rollover Date < Join Date | |
197 | ||
6a488035 TO |
198 | // Log in using webtestLogin() method |
199 | $this->webtestLogin(); | |
200 | ||
42daf119 | 201 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
202 | |
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()); | |
208 | ||
209 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
210 | ||
071a6d2e | 211 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
212 | |
213 | $this->click("link=Add Membership Type"); | |
214 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
215 | ||
216 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 217 | $this->select2('member_of_contact_id', $title); |
6a488035 TO |
218 | |
219 | $this->type('minimum_fee', '100'); | |
220 | $this->select( 'financial_type_id', 'value=2' ); | |
221 | ||
222 | $this->type('duration_interval', 2); | |
223 | $this->select('duration_unit', "label=year"); | |
224 | ||
5ddf4885 | 225 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
226 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
227 | ||
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'); | |
231 | ||
232 | $this->click('relationship_type_id', 'value=4_b_a'); | |
233 | ||
234 | $this->click('_qf_MembershipType_upload-bottom'); | |
235 | $this->waitForElementPresent('link=Add Membership Type'); | |
6c6e6187 | 236 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
6a488035 | 237 | |
071a6d2e | 238 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
239 | |
240 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
241 | ||
242 | //fill in first name | |
243 | $this->type('first_name', $firstName); | |
244 | ||
245 | //fill in last name | |
246 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
247 | $this->type('last_name', $lastName); | |
248 | ||
249 | //fill in email | |
250 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
251 | $this->type('email_1_email', $email); | |
252 | ||
253 | // Clicking save. | |
254 | $this->click('_qf_Contact_upload_view'); | |
255 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
256 | ||
257 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
258 | ||
259 | // click through to the membership add screen | |
260 | $this->click('css=li#tab_member a'); | |
261 | ||
262 | $this->waitForElementPresent('link=Add Membership'); | |
263 | $this->click('link=Add Membership'); | |
264 | ||
265 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
266 | ||
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}"); | |
272 | ||
273 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 2"; | |
274 | // fill in Source | |
275 | $this->type('source', $sourceText); | |
276 | ||
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; | |
284 | ||
285 | $todayDate = date('Y-m-d'); | |
286 | ||
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)); | |
289 | ||
290 | // expected calc'd start date | |
291 | $startDate = date('Y-m-d', mktime(0, 0, 0, 9, 1, $previousYear)); | |
292 | ||
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(); | |
296 | foreach (array( | |
297 | 'joinDate', 'startDate', 'endDate') as $date) { | |
298 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
299 | } | |
300 | ||
301 | $query = " | |
76e86fd8 CW |
302 | SELECT end_event_adjust_interval |
303 | ||
304 | FROM civicrm_membership_status | |
305 | ||
6a488035 TO |
306 | WHERE start_event = 'join_date' |
307 | AND name = 'New'"; | |
308 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
309 | ||
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)); | |
312 | ||
313 | $status = 'Current'; | |
314 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
315 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
316 | $status = 'New'; | |
317 | } | |
318 | ||
319 | // fill in Join Date | |
320 | $this->webtestFillDate('join_date', $joinDate); | |
321 | ||
322 | // Clicking save. | |
323 | $this->click('_qf_Membership_upload'); | |
c900afb1 | 324 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
325 | |
326 | // page was loaded | |
327 | $this->waitForTextPresent($sourceText); | |
328 | ||
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!" | |
332 | ); | |
333 | ||
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"); | |
337 | ||
338 | $this->webtestVerifyTabularData( | |
339 | array( | |
340 | 'Membership Type' => "Membership Type {$title}", | |
341 | 'Status' => $status, | |
342 | 'Source' => $sourceText, | |
343 | 'Member Since' => $joinDate, | |
344 | 'Start date' => $startDate, | |
345 | 'End date' => $endDate, | |
346 | ) | |
347 | ); | |
348 | } | |
349 | ||
00be9182 | 350 | public function testMembershipTypeScenario3() { |
6a488035 TO |
351 | // Scenario 3 |
352 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover | |
353 | // Join Date is later than Rollover Date | |
354 | ||
6a488035 TO |
355 | // Log in using webtestLogin() method |
356 | $this->webtestLogin(); | |
357 | ||
42daf119 | 358 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
359 | |
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()); | |
365 | ||
366 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
367 | ||
071a6d2e | 368 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
369 | |
370 | $this->click("link=Add Membership Type"); | |
371 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
372 | ||
373 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 374 | $this->select2('member_of_contact_id', $title); |
6a488035 TO |
375 | |
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"); | |
380 | ||
5ddf4885 | 381 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
382 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
383 | ||
384 | $this->select('fixed_period_rollover_day[M]', 'value=10'); | |
385 | $this->select('fixed_period_rollover_day[d]', 'value=31'); | |
386 | ||
387 | $this->click('relationship_type_id', 'value=4_b_a'); | |
388 | ||
389 | $this->click('_qf_MembershipType_upload-bottom'); | |
390 | $this->waitForElementPresent('link=Add Membership Type'); | |
6a488035 | 391 | |
6c6e6187 | 392 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
071a6d2e | 393 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
394 | |
395 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
396 | ||
397 | //fill in first name | |
398 | $this->type('first_name', $firstName); | |
399 | ||
400 | //fill in last name | |
401 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
402 | $this->type('last_name', $lastName); | |
403 | ||
404 | //fill in email | |
405 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
406 | $this->type('email_1_email', $email); | |
407 | ||
408 | // Clicking save. | |
409 | $this->click('_qf_Contact_upload_view'); | |
410 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
411 | ||
412 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
413 | ||
414 | // click through to the membership view screen | |
415 | $this->click('css=li#tab_member a'); | |
416 | ||
417 | $this->waitForElementPresent('link=Add Membership'); | |
418 | $this->click('link=Add Membership'); | |
419 | ||
420 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
421 | ||
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}"); | |
427 | ||
6a488035 TO |
428 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3"; |
429 | // fill in Source | |
430 | $this->type('source', $sourceText); | |
431 | ||
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(); | |
445 | foreach (array( | |
446 | 'joinDate', 'startDate', 'endDate') as $date) { | |
447 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
448 | } | |
449 | ||
450 | $query = " | |
76e86fd8 CW |
451 | SELECT end_event_adjust_interval |
452 | ||
453 | FROM civicrm_membership_status | |
454 | ||
6a488035 TO |
455 | WHERE start_event = 'join_date' |
456 | AND name = 'New'"; | |
457 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
458 | ||
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)); | |
461 | ||
462 | $status = 'Current'; | |
463 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
464 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
465 | $status = 'New'; | |
466 | } | |
467 | ||
468 | // fill in Join Date | |
469 | $this->webtestFillDate('join_date', $joinDate); | |
470 | ||
471 | // Clicking save. | |
472 | $this->click('_qf_Membership_upload'); | |
c900afb1 | 473 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
474 | |
475 | // page was loaded | |
476 | $this->waitForTextPresent($sourceText); | |
477 | ||
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!" | |
481 | ); | |
482 | ||
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"); | |
486 | ||
487 | $this->webtestVerifyTabularData( | |
488 | array( | |
489 | 'Membership Type' => "Membership Type {$title}", | |
490 | 'Status' => $status, | |
491 | 'Source' => $sourceText, | |
492 | 'Member Since' => $joinDate, | |
493 | 'Start date' => $startDate, | |
494 | 'End date' => $endDate, | |
495 | ) | |
496 | ); | |
497 | } | |
498 | ||
00be9182 | 499 | public function testMembershipTypeScenario4() { |
6a488035 TO |
500 | // Scenario 4 |
501 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover | |
502 | // Join Date is earlier than Rollover Date | |
503 | ||
6a488035 TO |
504 | // Log in using webtestLogin() method |
505 | $this->webtestLogin(); | |
506 | ||
42daf119 | 507 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
508 | |
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()); | |
514 | ||
515 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
516 | ||
071a6d2e | 517 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
518 | |
519 | $this->click("link=Add Membership Type"); | |
520 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
521 | ||
522 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 523 | $this->select2('member_of_contact_id', $title); |
76e86fd8 | 524 | |
6a488035 TO |
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"); | |
529 | ||
5ddf4885 | 530 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
531 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
532 | ||
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'); | |
536 | ||
537 | $this->click('relationship_type_id', 'value=4_b_a'); | |
538 | ||
539 | $this->click('_qf_MembershipType_upload-bottom'); | |
540 | $this->waitForElementPresent('link=Add Membership Type'); | |
6c6e6187 | 541 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
6a488035 | 542 | |
071a6d2e | 543 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
544 | |
545 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
546 | ||
547 | //fill in first name | |
548 | $this->type('first_name', $firstName); | |
549 | ||
550 | //fill in last name | |
551 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
552 | $this->type('last_name', $lastName); | |
553 | ||
554 | //fill in email | |
555 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
556 | $this->type('email_1_email', $email); | |
557 | ||
558 | // Clicking save. | |
559 | $this->click('_qf_Contact_upload_view'); | |
560 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
561 | ||
562 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
563 | ||
564 | // click through to the membership view screen | |
565 | $this->click('css=li#tab_member a'); | |
566 | ||
567 | $this->waitForElementPresent('link=Add Membership'); | |
568 | $this->click('link=Add Membership'); | |
569 | ||
570 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
571 | ||
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"); | |
575 | ||
576 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4"; | |
577 | // fill in Source | |
578 | $this->type('source', $sourceText); | |
579 | ||
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'); | |
588 | ||
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)); | |
591 | ||
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(); | |
596 | foreach (array( | |
597 | 'joinDate', 'startDate', 'endDate') as $date) { | |
598 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
599 | } | |
600 | ||
601 | $query = " | |
76e86fd8 CW |
602 | SELECT end_event_adjust_interval |
603 | ||
604 | FROM civicrm_membership_status | |
605 | ||
6a488035 TO |
606 | WHERE start_event = 'join_date' |
607 | AND name = 'New'"; | |
608 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
609 | ||
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)); | |
612 | ||
613 | $status = 'Current'; | |
614 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
615 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
616 | $status = 'New'; | |
617 | } | |
618 | ||
619 | // fill in Join Date | |
620 | $this->webtestFillDate('join_date', $joinDate); | |
621 | ||
622 | // Clicking save. | |
623 | $this->click('_qf_Membership_upload'); | |
c900afb1 | 624 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
625 | |
626 | // page was loaded | |
627 | $this->waitForTextPresent($sourceText); | |
628 | ||
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!" | |
632 | ); | |
633 | ||
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"); | |
637 | ||
638 | $this->webtestVerifyTabularData( | |
639 | array( | |
640 | 'Membership Type' => "Membership Type $title", | |
641 | 'Status' => $status, | |
642 | 'Source' => $sourceText, | |
643 | 'Member Since' => $joinDate, | |
644 | 'Start date' => $startDate, | |
645 | 'End date' => $endDate, | |
646 | ) | |
647 | ); | |
648 | } | |
649 | } |