3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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_InheritedMembershipTest
32 class WebTest_Member_InheritedMembershipTest
extends CiviSeleniumTestCase
{
33 protected function setUp() {
37 public function testInheritedMembership() {
38 $this->markTestSkipped('Skipping for now as it works fine locally.');
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
42 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
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 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
51 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
53 $this->click('link=Add Membership Type');
54 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
56 $this->type('name', "Membership Type $title");
58 $this->select2('member_of_contact_id', $title);
60 $this->type('minimum_fee', '100');
61 $this->select('financial_type_id', 'value=2');
62 $this->type('duration_interval', 1);
63 $this->select('duration_unit', 'label=year');
65 $this->select('period_type', 'value=rolling');
67 $this->select2('relationship_type_id', 'Employer of', TRUE);
68 $this->type('max_related', '5');
70 $this->click('_qf_MembershipType_upload-bottom');
71 $this->waitForElementPresent('link=Add Membership Type');
72 $this->waitForText('crm-notification-container', "Membership Type $title");
74 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
76 // creating another Orgnization
77 $title1 = substr(sha1(rand()), 0, 7);
78 $this->type('organization_name', "Organization $title1");
79 $this->type('email_1_email', "$title1@org.com");
80 $this->click('_qf_Contact_upload_view');
81 $this->waitForPageToLoad($this->getTimeoutMsec());
83 // click through to the membership view screen
84 $this->click('css=li#tab_member a');
86 $this->waitForElementPresent('link=Add Membership');
87 $this->click('link=Add Membership');
89 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
91 // fill in Membership Organization and Type
92 $this->select('membership_type_id[0]', "label=Organization $title");
93 $this->select('membership_type_id[1]', "label=Membership Type $title");
95 $sourceText = 'Membership ContactAddTest with Fixed Membership Type';
97 $this->type('source', $sourceText);
100 $this->click('_qf_Membership_upload');
101 $this->waitForElementPresent('link=Add Membership');
104 $this->waitForTextPresent($sourceText);
106 // Is status message correct?
107 $this->waitForText('crm-notification-container', "Membership Type $title");
109 // click through to the membership view screen
110 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
111 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
113 $joinDate = date('Y-m-d');
114 $startDate = date('Y-m-d');
115 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y') +
1));
116 $configVars = new CRM_Core_Config_Variables();
122 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
125 $this->webtestVerifyTabularData(
127 'Membership Type' => "Membership Type $title",
129 'Source' => $sourceText,
130 'Member Since' => $joinDate,
131 'Start date' => $startDate,
132 'End date' => $endDate,
133 'Max related' => "5",
138 // We're using Quick Add block on the main page for this.
139 $firstName = substr(sha1(rand()), 0, 7);
140 $this->webtestAddContact($firstName, 'Anderson', "$firstName@anderson.name");
142 // visit relationship tab
143 $this->click('css=li#tab_rel a');
144 $this->waitForElementPresent('css=div.action-link');
145 $this->click("//div[@class='action-link']/a/span");
146 $this->waitForElementPresent('_qf_Relationship_cancel-bottom');
147 $this->click('relationship_type_id');
148 $this->select('relationship_type_id', 'label=Employee of');
150 $this->select2('related_contact_id', $title1, TRUE);
152 $description = 'Well here is some description !!!!';
153 $this->type('description', $description);
155 //save the relationship
156 $this->click('_qf_Relationship_upload-bottom');
157 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
158 //check the status message
159 $this->waitForText('crm-notification-container', 'Relationship created.');
161 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='View']");
163 // click through to the membership view screen
164 $this->click('css=li#tab_member a');
165 $this->waitForElementPresent('css=div#memberships');
167 // click through to the membership view screen
168 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
169 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
171 $this->webtestVerifyTabularData(
173 'Membership Type' => "Membership Type $title",
175 'Source' => $sourceText,
176 'Member Since' => $joinDate,
177 'Start date' => $startDate,
178 'End date' => $endDate,
181 $this->click("_qf_MembershipView_cancel-bottom");
182 $this->waitForElementPresent('css=div#memberships');
184 //1. change relationship status on form
185 $this->click('css=li#tab_rel a');
186 $this->waitForElementPresent('css=div.action-link');
188 $this->click("//li[@id='tab_rel']/a");
189 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
190 $id = explode('&id=', $this->getAttribute("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a@href"));
191 $id = explode('&', $id[0]);
192 $id = explode('=', $id[2]);
194 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
196 $this->waitForElementPresent('is_active');
197 //disable relationship
198 if ($this->isChecked('is_active')) {
199 $this->click('is_active');
201 $this->click('_qf_Relationship_upload');
202 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
203 //check the status message
204 $this->waitForText('crm-notification-container', 'Relationship record has been updated');
206 // click through to the membership view screen
207 $this->click('css=li#tab_member a');
209 //verify inherited membership has been removed
210 $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
211 $this->waitForTextPresent("No memberships have been recorded for this contact.");
213 // visit relationship tab and re-enable the relationship
214 $this->click('css=li#tab_rel a');
215 $this->waitForElementPresent('css=div.action-link');
216 $this->click("//li[@id='tab_rel']/a");
218 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
219 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
220 $this->waitForElementPresent('is_active');
221 if (!$this->isChecked('is_active')) {
222 $this->click('is_active');
224 $this->click('_qf_Relationship_upload');
225 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
226 //check the status message
227 $this->waitForText('crm-notification-container', 'Relationship record has been updated.');
229 //check for memberships
230 $this->click('css=li#tab_member a');
231 $this->waitForElementPresent('css=div#memberships');
233 //2 . visit relationship tab and disable the relationship (by links)
234 //disable relationship
235 $this->click('css=li#tab_rel a');
236 $this->waitForElementPresent('css=div.action-link');
237 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
238 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
239 $this->waitForTextPresent('Are you sure you want to disable this relationship?');
240 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Yes']");
241 // Because it tends to cause problems, all uses of sleep() must be justified in comments
242 // Sleep should never be used for wait for anything to load from the server
243 // Justification for this instance: FIXME
246 //verify inherited membership has been removed
247 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
248 $this->waitForTextPresent("No memberships have been recorded for this contact.");
250 //enable relationship
251 $this->click('css=li#tab_rel a');
252 $this->waitForElementPresent('css=div.action-link');
254 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
255 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
258 $this->click('css=li#tab_member a');
259 $this->waitForTextPresent("No memberships have been recorded for this contact.");
263 * Webtest for CRM-10146
265 public function testInheritedMembershipActivity() {
266 // Log in using webtestLogin() method
267 $this->webtestLogin();
269 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
271 $title = substr(sha1(rand()), 0, 7);
272 $this->type('organization_name', "Organization $title");
273 $this->type('email_1_email', "$title@org.com");
274 $this->clickLink('_qf_Contact_upload_view');
275 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
277 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
279 $this->click('link=Add Membership Type');
280 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
282 $this->type('name', "Membership Type $title");
284 $this->select2('member_of_contact_id', $title);
286 $this->type('minimum_fee', '100');
287 $this->select('financial_type_id', 'label=Member Dues');
288 $this->type('duration_interval', 1);
289 $this->select('duration_unit', 'label=year');
291 $this->select('period_type', 'value=rolling');
293 $this->select2('relationship_type_id', 'Employer of', TRUE);
294 $this->type('max_related', '5');
296 $this->click('_qf_MembershipType_upload-bottom');
297 $this->waitForElementPresent('link=Add Membership Type');
298 $this->waitForText('crm-notification-container', "Membership Type $title");
300 // creating another Organization
301 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
302 $org1 = substr(sha1(rand()), 0, 7);
303 $this->type('organization_name', "Organization $org1");
304 $this->type('email_1_email', "$org1@org.com");
305 $this->clickLink('_qf_Contact_upload_view');
307 // click through to the membership view screen
308 $this->click('css=li#tab_member a');
310 $this->waitForElementPresent('link=Add Membership');
311 $this->click('link=Add Membership');
313 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
315 // fill in Membership Organization and Type
316 $this->select('membership_type_id[0]', "label=Organization $title");
317 $this->select('membership_type_id[1]', "label=Membership Type $title");
319 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
321 $this->type('source', $sourceText);
324 $this->click('_qf_Membership_upload');
327 $this->waitForTextPresent($sourceText);
329 // Is status message correct?
330 $this->waitForText('crm-notification-container', "Membership Type $title");
333 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel-bottom');
334 $firstName = substr(sha1(rand()), 0, 7);
335 $lastName = 'Anderson';
336 $email = "$firstName@anderson.name";
337 $this->type("first_name", $firstName);
338 $this->type("last_name", $lastName);
340 // Set Current Employer
341 $this->select2('employer_id', $org1);
342 $this->waitForText('s2id_employer_id', $org1);
344 $this->type("email_1_email", $email);
345 $this->clickLink("_qf_Contact_upload_view-bottom");
346 $cid = $this->urlArg('cid');
348 // click through to the membership view screen
349 $this->click('css=li#tab_member a');
350 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
352 // check number of membership for contact
353 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
355 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
356 $expectedMembershipId = $url['queryString']['id'];
358 // click through to the activity view screen
359 $this->click('css=li#tab_activity a');
360 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
362 // check number of activity for contact
363 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
365 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
366 $expectedMembershipActivityId = $url['queryString']['id'];
368 // verify membership id with membership activity id
369 $this->assertEquals($expectedMembershipId, $expectedMembershipActivityId);
371 // click through to the relationship view screen
372 $this->click('css=li#tab_rel a');
373 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
374 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
375 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
377 // Edit Contact but do not change any field
378 $this->waitForElementPresent("xpath=//ul[@id='actions']/li[2]/a/span");
379 $this->clickLink("xpath=//ul[@id='actions']/li[2]/a/span");
380 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
381 $this->clickLink("_qf_Contact_upload_view-top");
383 // click through to the membership view screen after edit
384 $this->click('css=li#tab_member a');
385 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
386 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
388 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
389 $actualMembershipId1 = $url['queryString']['id'];
391 // click through to the activity view screen after edit
392 $this->click('css=li#tab_activity a');
393 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
394 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
395 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
396 $actualMembershipActivityId1 = $url['queryString']['id'];
398 // verify membership id and membership activity id with previous one
399 // FIXME: These 2 lines are currently failing because the inherited membership and signup activity or being recreated when contact is edited/saved. dgg
400 $this->assertEquals($expectedMembershipId, $actualMembershipId1);
401 $this->assertEquals($expectedMembershipActivityId, $actualMembershipActivityId1);
403 // click through to the relationship view screen after edit
404 $this->click('css=li#tab_rel a');
405 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
406 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
407 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
409 // change the current employer of the contact
410 // creating another membership type
411 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
413 $this->click('link=Add Membership Type');
414 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
416 $this->type('name', "Membership Type Another $title");
418 $this->select2('member_of_contact_id', $title);
420 $this->type('minimum_fee', '100');
421 $this->select('financial_type_id', 'label=Member Dues');
422 $this->type('duration_interval', 1);
423 $this->select('duration_unit', 'label=year');
425 $this->select('period_type', 'value=rolling');
427 $this->select2('relationship_type_id', 'Employer of', TRUE);
428 $this->type('max_related', '5');
430 $this->click('_qf_MembershipType_upload-bottom');
431 $this->waitForElementPresent('link=Add Membership Type');
432 $this->waitForText('crm-notification-container', "Membership Type Another $title");
434 // creating another Orgnization
435 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
436 $org2 = substr(sha1(rand()), 0, 7);
437 $this->type('organization_name', "Organization $org2");
438 $this->type('email_1_email', "$org2@org.com");
439 $this->clickLink('_qf_Contact_upload_view');
441 // click through to the membership view screen
442 $this->click('css=li#tab_member a');
443 $this->waitForElementPresent('link=Add Membership');
444 $this->click('link=Add Membership');
445 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
447 // fill in Membership Organization and Type
448 $this->select('membership_type_id[0]', "label=Organization $title");
449 $this->select('membership_type_id[1]', "label=Membership Type Another $title");
451 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
452 $this->type('source', $sourceText);
453 $this->clickLink('_qf_Membership_upload', 'link=Add Membership', FALSE);
454 $this->waitForTextPresent($sourceText);
456 // Is status message correct?
457 $this->waitForText('crm-notification-container', "Membership Type Another $title");
460 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
462 // change Current Employer
463 $this->select2('employer_id', $org2);
464 $this->clickLink("_qf_Contact_upload_view-bottom");
466 // click through to the membership view screen
467 $this->click('css=li#tab_member a');
468 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
469 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
470 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
471 $actualMembershipId2 = $url['queryString']['id'];
473 // click through to the activity view screen
474 $this->click('css=li#tab_activity a');
475 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
476 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
477 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
478 $actualMembershipActivityId2 = $url['queryString']['id'];
480 // verify membership id and membership activity id with previous one
481 $this->assertNotEquals($expectedMembershipId, $actualMembershipId2);
482 $this->assertNotEquals($expectedMembershipId, $actualMembershipActivityId2);
484 // click through to the relationship view screen
485 $this->click('css=li#tab_rel a');
486 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
487 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org2']"));
488 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
490 // creating another Orgnization with no membership
491 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
492 $org3 = substr(sha1(rand()), 0, 7);
493 $this->type('organization_name', "Organization $org3");
494 $this->type('email_1_email', "$org3@org.com");
495 $this->clickLink('_qf_Contact_upload_view');
498 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
500 // change Current Employer
501 $this->select2('employer_id', $org3);
502 $this->clickLink("_qf_Contact_upload_view-bottom");
504 // click through to the membership view screen
505 $this->click('css=li#tab_member a');
507 $this->waitForAjaxContent();
508 $this->waitForTextPresent("No memberships have been recorded for this contact.");
509 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_member']/a/em"));
511 // click through to the activity view screen
512 $this->click('css=li#tab_activity a');
513 $this->waitForText("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr/td", "No matches found.");
514 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
516 // click through to the relationship view screen
517 $this->click('css=li#tab_rel a');
518 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
519 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org3']"));
520 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));