Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 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'); | |
481a74f4 | 65 | $this->select('financial_type_id', 'value=2'); |
6a488035 TO |
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'; | |
92915c55 | 123 | $currentYear = date('Y'); |
6a488035 TO |
124 | $currentMonth = date('m'); |
125 | $previousYear = $currentYear - 1; | |
92915c55 | 126 | $nextYear = $currentYear + 1; |
6a488035 TO |
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 | ||
6a488035 | 139 | foreach (array( |
92915c55 TO |
140 | 'joinDate', |
141 | 'startDate', | |
79d7553f | 142 | 'endDate', |
92915c55 | 143 | ) as $date) { |
d3f2fd13 | 144 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
6a488035 TO |
145 | } |
146 | ||
147 | $query = " | |
76e86fd8 CW |
148 | SELECT end_event_adjust_interval |
149 | ||
150 | FROM civicrm_membership_status | |
151 | ||
6a488035 TO |
152 | WHERE start_event = 'join_date' |
153 | AND name = 'New'"; | |
154 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
155 | ||
156 | // Add endInterval to March 25 (join date month above) to get end of New status period | |
157 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 3, 25, $currentYear)); | |
158 | ||
159 | $status = 'Current'; | |
160 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
161 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
162 | $status = 'New'; | |
163 | } | |
164 | ||
165 | // fill in Join Date | |
166 | $this->webtestFillDate('join_date', $joinDate); | |
167 | ||
168 | // Clicking save. | |
169 | $this->click('_qf_Membership_upload'); | |
6a488035 TO |
170 | |
171 | // page was loaded | |
172 | $this->waitForTextPresent($sourceText); | |
173 | ||
c900afb1 | 174 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
175 | // Is status message correct? |
176 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), | |
177 | "Status message didn't show up after saving!" | |
178 | ); | |
179 | ||
180 | // click through to the membership view screen | |
181 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
182 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
183 | ||
184 | $this->webtestVerifyTabularData( | |
185 | array( | |
186 | 'Membership Type' => "Membership Type $title", | |
187 | 'Status' => $status, | |
188 | 'Source' => $sourceText, | |
189 | 'Member Since' => $joinDate, | |
190 | 'Start date' => $startDate, | |
191 | 'End date' => $endDate, | |
192 | ) | |
193 | ); | |
194 | } | |
195 | ||
00be9182 | 196 | public function testMembershipTypeScenario2() { |
6a488035 TO |
197 | // Scenario 2 |
198 | // Rollover Date < Join Date | |
199 | ||
6a488035 TO |
200 | // Log in using webtestLogin() method |
201 | $this->webtestLogin(); | |
202 | ||
42daf119 | 203 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
204 | |
205 | $title = substr(sha1(rand()), 0, 7); | |
206 | $this->type('organization_name', "Organization $title"); | |
207 | $this->type('email_1_email', "$title@org.com"); | |
208 | $this->click('_qf_Contact_upload_view'); | |
209 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
210 | ||
211 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
212 | ||
071a6d2e | 213 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
214 | |
215 | $this->click("link=Add Membership Type"); | |
216 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
217 | ||
218 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 219 | $this->select2('member_of_contact_id', $title); |
6a488035 TO |
220 | |
221 | $this->type('minimum_fee', '100'); | |
481a74f4 | 222 | $this->select('financial_type_id', 'value=2'); |
6a488035 TO |
223 | |
224 | $this->type('duration_interval', 2); | |
225 | $this->select('duration_unit', "label=year"); | |
226 | ||
5ddf4885 | 227 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
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'); | |
6c6e6187 | 238 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
6a488035 | 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'; | |
92915c55 | 283 | $currentYear = date('Y'); |
6a488035 TO |
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)); | |
6a488035 | 297 | foreach (array( |
92915c55 TO |
298 | 'joinDate', |
299 | 'startDate', | |
79d7553f | 300 | 'endDate', |
92915c55 | 301 | ) as $date) { |
d3f2fd13 | 302 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
6a488035 TO |
303 | } |
304 | ||
305 | $query = " | |
76e86fd8 CW |
306 | SELECT end_event_adjust_interval |
307 | ||
308 | FROM civicrm_membership_status | |
309 | ||
6a488035 TO |
310 | WHERE start_event = 'join_date' |
311 | AND name = 'New'"; | |
312 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
313 | ||
314 | // Add endInterval to July 15 (join date month above) to get end of New status period | |
315 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval + 7, 15, $currentYear)); | |
316 | ||
317 | $status = 'Current'; | |
318 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
319 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
320 | $status = 'New'; | |
321 | } | |
322 | ||
323 | // fill in Join Date | |
324 | $this->webtestFillDate('join_date', $joinDate); | |
325 | ||
326 | // Clicking save. | |
327 | $this->click('_qf_Membership_upload'); | |
c900afb1 | 328 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
329 | |
330 | // page was loaded | |
331 | $this->waitForTextPresent($sourceText); | |
332 | ||
333 | // Is status message correct? | |
334 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), | |
335 | "Status message didn't show up after saving!" | |
336 | ); | |
337 | ||
338 | // click through to the membership view screen | |
339 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
340 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
341 | ||
342 | $this->webtestVerifyTabularData( | |
343 | array( | |
344 | 'Membership Type' => "Membership Type {$title}", | |
345 | 'Status' => $status, | |
346 | 'Source' => $sourceText, | |
347 | 'Member Since' => $joinDate, | |
348 | 'Start date' => $startDate, | |
349 | 'End date' => $endDate, | |
350 | ) | |
351 | ); | |
352 | } | |
353 | ||
00be9182 | 354 | public function testMembershipTypeScenario3() { |
6a488035 TO |
355 | // Scenario 3 |
356 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover | |
357 | // Join Date is later than Rollover Date | |
358 | ||
6a488035 TO |
359 | // Log in using webtestLogin() method |
360 | $this->webtestLogin(); | |
361 | ||
42daf119 | 362 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
363 | |
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()); | |
369 | ||
370 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
371 | ||
071a6d2e | 372 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
373 | |
374 | $this->click("link=Add Membership Type"); | |
375 | $this->waitForElementPresent('_qf_MembershipType_cancel-bottom'); | |
376 | ||
377 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 378 | $this->select2('member_of_contact_id', $title); |
6a488035 TO |
379 | |
380 | $this->type('minimum_fee', '100'); | |
481a74f4 | 381 | $this->select('financial_type_id', 'value=2'); |
6a488035 TO |
382 | $this->type('duration_interval', 1); |
383 | $this->select('duration_unit', "label=year"); | |
384 | ||
5ddf4885 | 385 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
386 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
387 | ||
388 | $this->select('fixed_period_rollover_day[M]', 'value=10'); | |
389 | $this->select('fixed_period_rollover_day[d]', 'value=31'); | |
390 | ||
391 | $this->click('relationship_type_id', 'value=4_b_a'); | |
392 | ||
393 | $this->click('_qf_MembershipType_upload-bottom'); | |
394 | $this->waitForElementPresent('link=Add Membership Type'); | |
6a488035 | 395 | |
6c6e6187 | 396 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
071a6d2e | 397 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
398 | |
399 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
400 | ||
401 | //fill in first name | |
402 | $this->type('first_name', $firstName); | |
403 | ||
404 | //fill in last name | |
405 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
406 | $this->type('last_name', $lastName); | |
407 | ||
408 | //fill in email | |
409 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
410 | $this->type('email_1_email', $email); | |
411 | ||
412 | // Clicking save. | |
413 | $this->click('_qf_Contact_upload_view'); | |
414 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
415 | ||
416 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
417 | ||
418 | // click through to the membership view screen | |
419 | $this->click('css=li#tab_member a'); | |
420 | ||
421 | $this->waitForElementPresent('link=Add Membership'); | |
422 | $this->click('link=Add Membership'); | |
423 | ||
424 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
425 | ||
426 | // fill in Membership Organization and Type | |
427 | $this->select('membership_type_id[0]', "label=Organization {$title}"); | |
428 | // Wait for membership type select to reload | |
429 | $this->waitForTextPresent("Membership Type {$title}"); | |
430 | $this->select('membership_type_id[1]', "label=Membership Type {$title}"); | |
431 | ||
6a488035 TO |
432 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 3"; |
433 | // fill in Source | |
434 | $this->type('source', $sourceText); | |
435 | ||
436 | //build the membership dates. | |
437 | require_once 'CRM/Core/Config.php'; | |
438 | require_once 'CRM/Utils/Array.php'; | |
439 | require_once 'CRM/Utils/Date.php'; | |
92915c55 | 440 | $currentYear = date('Y'); |
6a488035 TO |
441 | $currentMonth = date('m'); |
442 | $previousYear = $currentYear - 1; | |
92915c55 TO |
443 | $nextYear = $currentYear + 1; |
444 | $todayDate = date('Y-m-d'); | |
445 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 11, 15, $currentYear)); | |
446 | $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear)); | |
447 | $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $nextYear)); | |
6a488035 | 448 | foreach (array( |
92915c55 TO |
449 | 'joinDate', |
450 | 'startDate', | |
79d7553f | 451 | 'endDate', |
92915c55 | 452 | ) as $date) { |
d3f2fd13 | 453 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
6a488035 TO |
454 | } |
455 | ||
456 | $query = " | |
76e86fd8 CW |
457 | SELECT end_event_adjust_interval |
458 | ||
459 | FROM civicrm_membership_status | |
460 | ||
6a488035 TO |
461 | WHERE start_event = 'join_date' |
462 | AND name = 'New'"; | |
463 | $endInterval = CRM_Core_DAO::singleValueQuery($query); | |
464 | ||
465 | // Add endInterval to Nov 15 (join date month above) to get end of New status period | |
466 | $endNewStatus = date('Y-m-d', mktime(0, 0, 0, $endInterval - 1, 15, $nextYear)); | |
467 | ||
468 | $status = 'Current'; | |
469 | // status will be 'New' if today is >= join date and <= endNewStatus date | |
470 | if ((strtotime($todayDate) >= strtotime($joinDate)) && (strtotime($todayDate) <= strtotime($endNewStatus))) { | |
471 | $status = 'New'; | |
472 | } | |
473 | ||
474 | // fill in Join Date | |
475 | $this->webtestFillDate('join_date', $joinDate); | |
476 | ||
477 | // Clicking save. | |
478 | $this->click('_qf_Membership_upload'); | |
c900afb1 | 479 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
480 | |
481 | // page was loaded | |
482 | $this->waitForTextPresent($sourceText); | |
483 | ||
484 | // Is status message correct? | |
485 | $this->assertTrue($this->isTextPresent("Membership Type $title membership for $firstName $lastName has been added."), | |
486 | "Status message didn't show up after saving!" | |
487 | ); | |
488 | ||
489 | // click through to the membership view screen | |
490 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); | |
491 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
492 | ||
493 | $this->webtestVerifyTabularData( | |
494 | array( | |
495 | 'Membership Type' => "Membership Type {$title}", | |
496 | 'Status' => $status, | |
497 | 'Source' => $sourceText, | |
498 | 'Member Since' => $joinDate, | |
499 | 'Start date' => $startDate, | |
500 | 'End date' => $endDate, | |
501 | ) | |
502 | ); | |
503 | } | |
504 | ||
00be9182 | 505 | public function testMembershipTypeScenario4() { |
6a488035 TO |
506 | // Scenario 4 |
507 | // Standard Fixed scenario - Jan 1 Fixed Period Start and October 31 rollover | |
508 | // Join Date is earlier than Rollover Date | |
509 | ||
6a488035 TO |
510 | // Log in using webtestLogin() method |
511 | $this->webtestLogin(); | |
512 | ||
42daf119 | 513 | $this->openCiviPage("contact/add", "reset=1&ct=Organization", '_qf_Contact_cancel'); |
6a488035 TO |
514 | |
515 | $title = substr(sha1(rand()), 0, 7); | |
516 | $this->type('organization_name', "Organization $title"); | |
517 | $this->type('email_1_email', "$title@org.com"); | |
518 | $this->click('_qf_Contact_upload_view'); | |
519 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
520 | ||
521 | $this->assertTrue($this->isTextPresent("Organization $title has been created.")); | |
522 | ||
071a6d2e | 523 | $this->openCiviPage("admin/member/membershipType", "reset=1&action=browse"); |
6a488035 TO |
524 | |
525 | $this->click("link=Add Membership Type"); | |
acaa2fb9 | 526 | $this->waitForElementPresent("xpath=//button//span[contains(text(),'Cancel')]"); |
6a488035 TO |
527 | |
528 | $this->type('name', "Membership Type $title"); | |
6c6e6187 | 529 | $this->select2('member_of_contact_id', $title); |
76e86fd8 | 530 | |
6a488035 | 531 | $this->type('minimum_fee', '100'); |
481a74f4 | 532 | $this->select('financial_type_id', 'value=2'); |
6a488035 TO |
533 | $this->type('duration_interval', 1); |
534 | $this->select('duration_unit', "label=year"); | |
535 | ||
5ddf4885 | 536 | $this->select('period_type', "value=fixed"); |
6a488035 TO |
537 | $this->waitForElementPresent('fixed_period_rollover_day[d]'); |
538 | ||
539 | $this->select('fixed_period_start_day[M]', 'value=1'); | |
540 | $this->select('fixed_period_rollover_day[M]', 'value=10'); | |
541 | $this->select('fixed_period_rollover_day[d]', 'value=31'); | |
542 | ||
543 | $this->click('relationship_type_id', 'value=4_b_a'); | |
544 | ||
545 | $this->click('_qf_MembershipType_upload-bottom'); | |
546 | $this->waitForElementPresent('link=Add Membership Type'); | |
6c6e6187 | 547 | $this->waitForText('crm-notification-container', "The membership type 'Membership Type $title' has been saved."); |
6a488035 | 548 | |
071a6d2e | 549 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
550 | |
551 | $firstName = "John_" . substr(sha1(rand()), 0, 7); | |
552 | ||
553 | //fill in first name | |
554 | $this->type('first_name', $firstName); | |
555 | ||
556 | //fill in last name | |
557 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; | |
558 | $this->type('last_name', $lastName); | |
559 | ||
560 | //fill in email | |
561 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; | |
562 | $this->type('email_1_email', $email); | |
563 | ||
564 | // Clicking save. | |
565 | $this->click('_qf_Contact_upload_view'); | |
566 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
567 | ||
568 | $this->assertTrue($this->isTextPresent("$firstName $lastName has been created.")); | |
569 | ||
570 | // click through to the membership view screen | |
571 | $this->click('css=li#tab_member a'); | |
572 | ||
573 | $this->waitForElementPresent('link=Add Membership'); | |
574 | $this->click('link=Add Membership'); | |
575 | ||
576 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
577 | ||
578 | // fill in Membership Organization and Type | |
579 | $this->select('membership_type_id[0]', "label=Organization $title"); | |
580 | $this->select('membership_type_id[1]', "label=Membership Type $title"); | |
581 | ||
582 | $sourceText = "Membership ContactAddTest with Fixed Membership Type Scenario 4"; | |
583 | // fill in Source | |
584 | $this->type('source', $sourceText); | |
585 | ||
586 | //build the membership dates. | |
587 | require_once 'CRM/Core/Config.php'; | |
588 | require_once 'CRM/Utils/Array.php'; | |
589 | require_once 'CRM/Utils/Date.php'; | |
92915c55 | 590 | $currentYear = date('Y'); |
6a488035 | 591 | $currentMonth = date('m'); |
92915c55 TO |
592 | $nextYear = $currentYear + 1; |
593 | $todayDate = date('Y-m-d'); | |
6a488035 TO |
594 | |
595 | // the member-since date we will type in to membership form | |
596 | $joinDate = date('Y-m-d', mktime(0, 0, 0, 1, 15, $currentYear)); | |
597 | ||
598 | // expected calc'd start and end dates | |
92915c55 TO |
599 | $startDate = date('Y-m-d', mktime(0, 0, 0, 1, 1, $currentYear)); |
600 | $endDate = date('Y-m-d', mktime(0, 0, 0, 12, 31, $currentYear)); | |
6a488035 | 601 | foreach (array( |
92915c55 TO |
602 | 'joinDate', |
603 | 'startDate', | |
79d7553f | 604 | 'endDate', |
92915c55 | 605 | ) as $date) { |
d3f2fd13 | 606 | $$date = CRM_Utils_Date::customFormat($$date, $this->webtestGetSetting('dateformatFull')); |
6a488035 TO |
607 | } |
608 | ||
609 | $query = " | |
76e86fd8 CW |
610 | SELECT 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'); | |
c900afb1 | 632 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
6a488035 TO |
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 | } | |
96025800 | 657 | |
6a488035 | 658 | } |