3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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));
121 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
124 $this->webtestVerifyTabularData(
126 'Membership Type' => "Membership Type $title",
128 'Source' => $sourceText,
129 'Member Since' => $joinDate,
130 'Start date' => $startDate,
131 'End date' => $endDate,
132 'Max related' => "5",
137 // We're using Quick Add block on the main page for this.
138 $firstName = substr(sha1(rand()), 0, 7);
139 $this->webtestAddContact($firstName, 'Anderson', "$firstName@anderson.name");
141 // visit relationship tab
142 $this->click('css=li#tab_rel a');
143 $this->waitForElementPresent('css=div.action-link');
144 $this->click("//div[@class='action-link']/a/span");
145 $this->waitForElementPresent('_qf_Relationship_cancel-bottom');
146 $this->click('relationship_type_id');
147 $this->select('relationship_type_id', 'label=Employee of');
149 $this->select2('related_contact_id', $title1, TRUE);
151 $description = 'Well here is some description !!!!';
152 $this->type('description', $description);
154 //save the relationship
155 $this->click('_qf_Relationship_upload-bottom');
156 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
157 //check the status message
158 $this->waitForText('crm-notification-container', 'Relationship created.');
160 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='View']");
162 // click through to the membership view screen
163 $this->click('css=li#tab_member a');
164 $this->waitForElementPresent('css=div#memberships');
166 // click through to the membership view screen
167 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
168 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
170 $this->webtestVerifyTabularData(
172 'Membership Type' => "Membership Type $title",
174 'Source' => $sourceText,
175 'Member Since' => $joinDate,
176 'Start date' => $startDate,
177 'End date' => $endDate,
180 $this->click("_qf_MembershipView_cancel-bottom");
181 $this->waitForElementPresent('css=div#memberships');
183 //1. change relationship status on form
184 $this->click('css=li#tab_rel a');
185 $this->waitForElementPresent('css=div.action-link');
187 $this->click("//li[@id='tab_rel']/a");
188 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
189 $id = explode('&id=', $this->getAttribute("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a@href"));
190 $id = explode('&', $id[0]);
191 $id = explode('=', $id[2]);
193 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
195 $this->waitForElementPresent('is_active');
196 //disable relationship
197 if ($this->isChecked('is_active')) {
198 $this->click('is_active');
200 $this->click('_qf_Relationship_upload');
201 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
202 //check the status message
203 $this->waitForText('crm-notification-container', 'Relationship record has been updated');
205 // click through to the membership view screen
206 $this->click('css=li#tab_member a');
208 //verify inherited membership has been removed
209 $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
210 $this->waitForTextPresent("No memberships have been recorded for this contact.");
212 // visit relationship tab and re-enable the relationship
213 $this->click('css=li#tab_rel a');
214 $this->waitForElementPresent('css=div.action-link');
215 $this->click("//li[@id='tab_rel']/a");
217 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
218 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
219 $this->waitForElementPresent('is_active');
220 if (!$this->isChecked('is_active')) {
221 $this->click('is_active');
223 $this->click('_qf_Relationship_upload');
224 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
225 //check the status message
226 $this->waitForText('crm-notification-container', 'Relationship record has been updated.');
228 //check for memberships
229 $this->click('css=li#tab_member a');
230 $this->waitForElementPresent('css=div#memberships');
232 //2 . visit relationship tab and disable the relationship (by links)
233 //disable relationship
234 $this->click('css=li#tab_rel a');
235 $this->waitForElementPresent('css=div.action-link');
236 $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']");
237 $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']");
238 $this->waitForTextPresent('Are you sure you want to disable this relationship?');
239 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Yes']");
240 // Because it tends to cause problems, all uses of sleep() must be justified in comments
241 // Sleep should never be used for wait for anything to load from the server
242 // Justification for this instance: FIXME
245 //verify inherited membership has been removed
246 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
247 $this->waitForTextPresent("No memberships have been recorded for this contact.");
249 //enable relationship
250 $this->click('css=li#tab_rel a');
251 $this->waitForElementPresent('css=div.action-link');
253 $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']");
254 $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']");
257 $this->click('css=li#tab_member a');
258 $this->waitForTextPresent("No memberships have been recorded for this contact.");
262 * Webtest for CRM-10146
264 public function testInheritedMembershipActivity() {
265 // Log in using webtestLogin() method
266 $this->webtestLogin();
268 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
270 $title = substr(sha1(rand()), 0, 7);
271 $this->type('organization_name', "Organization $title");
272 $this->type('email_1_email', "$title@org.com");
273 $this->clickLink('_qf_Contact_upload_view');
274 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
276 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
278 $this->click('link=Add Membership Type');
279 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
281 $this->type('name', "Membership Type $title");
283 $this->select2('member_of_contact_id', $title);
285 $this->type('minimum_fee', '100');
286 $this->select('financial_type_id', 'label=Member Dues');
287 $this->type('duration_interval', 1);
288 $this->select('duration_unit', 'label=year');
290 $this->select('period_type', 'value=rolling');
292 $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 crm-ajax-table dataTable no-footer']/tbody/tr/td[8]/span/a");
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 crm-ajax-table dataTable no-footer']/tbody/tr/td[8]/span/a@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 crm-ajax-table dataTable no-footer']/tbody/tr/td[8]/span/a");
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 crm-ajax-table dataTable no-footer']/tbody/tr/td[8]/span/a@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 crm-ajax-table 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 crm-ajax-table 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 crm-ajax-table dataTable no-footer']/tbody/tr/td", "None 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"));