3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 // Log in using webtestLogin() method
39 $this->webtestLogin();
41 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
43 $title = substr(sha1(rand()), 0, 7);
44 $this->type('organization_name', "Organization $title");
45 $this->type('email_1_email', "$title@org.com");
46 $this->click('_qf_Contact_upload_view');
47 $this->waitForPageToLoad($this->getTimeoutMsec());
48 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
50 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
52 $this->click('link=Add Membership Type');
53 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
55 $this->type('name', "Membership Type $title");
57 $this->select2('member_of_contact_id', $title);
59 $this->type('minimum_fee', '100');
60 $this->select('financial_type_id', 'value=2');
61 $this->type('duration_interval', 1);
62 $this->select('duration_unit', 'label=year');
64 $this->select('period_type', 'value=rolling');
66 $this->removeSelection('relationship_type_id', 'label=- select -');
67 $this->addSelection('relationship_type_id', 'label=Employer of');
69 $this->type('max_related', '5');
71 $this->click('_qf_MembershipType_upload-bottom');
72 $this->waitForElementPresent('link=Add Membership Type');
73 $this->waitForText('crm-notification-container', "Membership Type $title");
75 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
77 // creating another Orgnization
78 $title1 = substr(sha1(rand()), 0, 7);
79 $this->type('organization_name', "Organization $title1");
80 $this->type('email_1_email', "$title1@org.com");
81 $this->click('_qf_Contact_upload_view');
82 $this->waitForPageToLoad($this->getTimeoutMsec());
84 // click through to the membership view screen
85 $this->click('css=li#tab_member a');
87 $this->waitForElementPresent('link=Add Membership');
88 $this->click('link=Add Membership');
90 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
92 // fill in Membership Organization and Type
93 $this->select('membership_type_id[0]', "label=Organization $title");
94 $this->select('membership_type_id[1]', "label=Membership Type $title");
96 $sourceText = 'Membership ContactAddTest with Fixed Membership Type';
98 $this->type('source', $sourceText);
101 $this->click('_qf_Membership_upload');
102 $this->waitForElementPresent('link=Add Membership');
105 $this->waitForTextPresent($sourceText);
107 // Is status message correct?
108 $this->waitForText('crm-notification-container', "Membership Type $title");
110 // click through to the membership view screen
111 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
112 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
114 $joinDate = date('Y-m-d');
115 $startDate = date('Y-m-d');
116 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y') +
1));
117 $configVars = new CRM_Core_Config_Variables();
123 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
126 $this->webtestVerifyTabularData(
128 'Membership Type' => "Membership Type $title",
130 'Source' => $sourceText,
131 'Member Since' => $joinDate,
132 'Start date' => $startDate,
133 'End date' => $endDate,
134 'Max related' => "5",
139 // We're using Quick Add block on the main page for this.
140 $firstName = substr(sha1(rand()), 0, 7);
141 $this->webtestAddContact($firstName, 'Anderson', "$firstName@anderson.name");
143 // visit relationship tab
144 $this->click('css=li#tab_rel a');
145 $this->waitForElementPresent('css=div.action-link');
146 $this->click("//div[@class='action-link']/a/span");
147 $this->waitForElementPresent('_qf_Relationship_cancel-bottom');
148 $this->click('relationship_type_id');
149 $this->select('relationship_type_id', 'label=Employee of');
151 $this->select2('related_contact_id', $title1, TRUE);
153 $description = 'Well here is some description !!!!';
154 $this->type('description', $description);
156 //save the relationship
157 $this->click('_qf_Relationship_upload-bottom');
158 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
159 //check the status message
160 $this->waitForText('crm-notification-container', 'Relationship created.');
162 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='View']");
164 // click through to the membership view screen
165 $this->click('css=li#tab_member a');
166 $this->waitForElementPresent('css=div#memberships');
168 // click through to the membership view screen
169 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
170 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
172 $this->webtestVerifyTabularData(
174 'Membership Type' => "Membership Type $title",
176 'Source' => $sourceText,
177 'Member Since' => $joinDate,
178 'Start date' => $startDate,
179 'End date' => $endDate,
182 $this->click("_qf_MembershipView_cancel-bottom");
183 $this->waitForElementPresent('css=div#memberships');
185 //1. change relationship status on form
186 $this->click('css=li#tab_rel a');
187 $this->waitForElementPresent('css=div.action-link');
189 $this->click("//li[@id='tab_rel']/a");
190 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
191 $id = explode('&id=', $this->getAttribute("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a@href"));
192 $id = explode('&', $id[0]);
193 $id = explode('=', $id[2]);
195 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
197 $this->waitForElementPresent('is_active');
198 //disable relationship
199 if ($this->isChecked('is_active')) {
200 $this->click('is_active');
202 $this->click('_qf_Relationship_upload');
203 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
204 //check the status message
205 $this->waitForText('crm-notification-container', 'Relationship record has been updated');
207 // click through to the membership view screen
208 $this->click('css=li#tab_member a');
210 //verify inherited membership has been removed
211 $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
212 $this->assertElementContainsText("xpath=//div[@class='view-content']", 'No memberships have been recorded for this contact.');
214 // visit relationship tab and re-enable the relationship
215 $this->click('css=li#tab_rel a');
216 $this->waitForElementPresent('css=div.action-link');
217 $this->click("//li[@id='tab_rel']/a");
219 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
220 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
221 $this->waitForElementPresent('is_active');
222 if (!$this->isChecked('is_active')) {
223 $this->click('is_active');
225 $this->click('_qf_Relationship_upload');
226 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
227 //check the status message
228 $this->waitForText('crm-notification-container', 'Relationship record has been updated.');
230 //check for memberships
231 $this->click('css=li#tab_member a');
232 $this->waitForElementPresent('css=div#memberships');
234 //2 . visit relationship tab and disable the relationship (by links)
235 //disable relationship
236 $this->click('css=li#tab_rel a');
237 $this->waitForElementPresent('css=div.action-link');
238 $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']");
239 $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']");
240 $this->waitForText("xpath=//div[@class='crm-confirm-dialog ui-dialog-content ui-widget-content modal-dialog']", 'Are you sure you want to disable this relationship?');
241 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Yes']");
242 // Because it tends to cause problems, all uses of sleep() must be justified in comments
243 // Sleep should never be used for wait for anything to load from the server
244 // Justification for this instance: FIXME
247 //verify inherited membership has been removed
248 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
249 $this->assertElementContainsText("xpath=//div[@class='view-content']/div[3]", 'No memberships have been recorded for this contact.');
251 //enable relationship
252 $this->click('css=li#tab_rel a');
253 $this->waitForElementPresent('css=div.action-link');
255 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
256 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
259 $this->click('css=li#tab_member a');
260 $this->waitForElementPresent('css=div#memberships');
264 * Webtest for CRM-10146
266 public function testInheritedMembershipActivity() {
267 // Log in using webtestLogin() method
268 $this->webtestLogin();
270 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
272 $title = substr(sha1(rand()), 0, 7);
273 $this->type('organization_name', "Organization $title");
274 $this->type('email_1_email', "$title@org.com");
275 $this->clickLink('_qf_Contact_upload_view');
276 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
278 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
280 $this->click('link=Add Membership Type');
281 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
283 $this->type('name', "Membership Type $title");
285 $this->select2('member_of_contact_id', $title);
287 $this->type('minimum_fee', '100');
288 $this->select('financial_type_id', 'label=Member Dues');
289 $this->type('duration_interval', 1);
290 $this->select('duration_unit', 'label=year');
292 $this->select('period_type', 'value=rolling');
294 $this->removeSelection('relationship_type_id', 'label=- select -');
295 $this->addSelection('relationship_type_id', 'label=Employer of');
297 $this->type('max_related', '5');
299 $this->click('_qf_MembershipType_upload-bottom');
300 $this->waitForElementPresent('link=Add Membership Type');
301 $this->waitForText('crm-notification-container', "Membership Type $title");
303 // creating another Organization
304 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
305 $org1 = substr(sha1(rand()), 0, 7);
306 $this->type('organization_name', "Organization $org1");
307 $this->type('email_1_email', "$org1@org.com");
308 $this->clickLink('_qf_Contact_upload_view');
310 // click through to the membership view screen
311 $this->click('css=li#tab_member a');
313 $this->waitForElementPresent('link=Add Membership');
314 $this->click('link=Add Membership');
316 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
318 // fill in Membership Organization and Type
319 $this->select('membership_type_id[0]', "label=Organization $title");
320 $this->select('membership_type_id[1]', "label=Membership Type $title");
322 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
324 $this->type('source', $sourceText);
327 $this->click('_qf_Membership_upload');
330 $this->waitForTextPresent($sourceText);
332 // Is status message correct?
333 $this->waitForText('crm-notification-container', "Membership Type $title");
336 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel-bottom');
337 $firstName = substr(sha1(rand()), 0, 7);
338 $lastName = 'Anderson';
339 $email = "$firstName@anderson.name";
340 $this->type("first_name", $firstName);
341 $this->type("last_name", $lastName);
343 // Set Current Employer
344 $this->select2('employer_id', $org1);
345 $this->waitForText('s2id_employer_id', $org1);
347 $this->type("email_1_email", $email);
348 $this->clickLink("_qf_Contact_upload_view-bottom");
349 $cid = $this->urlArg('cid');
351 // click through to the membership view screen
352 $this->click('css=li#tab_member a');
353 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
355 // check number of membership for contact
356 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
358 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
359 $expectedMembershipId = $url['queryString']['id'];
361 // click through to the activity view screen
362 $this->click('css=li#tab_activity a');
363 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
365 // check number of activity for contact
366 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
368 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
369 $expectedMembershipActivityId = $url['queryString']['id'];
371 // verify membership id with membership activity id
372 $this->assertEquals($expectedMembershipId, $expectedMembershipActivityId);
374 // click through to the relationship view screen
375 $this->click('css=li#tab_rel a');
376 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
377 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
378 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
380 // Edit Contact but do not change any field
381 $this->waitForElementPresent("xpath=//ul[@id='actions']/li[2]/a/span");
382 $this->clickLink("xpath=//ul[@id='actions']/li[2]/a/span");
383 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
384 $this->clickLink("_qf_Contact_upload_view-top");
386 // click through to the membership view screen after edit
387 $this->click('css=li#tab_member a');
388 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
389 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
391 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
392 $actualMembershipId1 = $url['queryString']['id'];
394 // click through to the activity view screen after edit
395 $this->click('css=li#tab_activity a');
396 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
397 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
398 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
399 $actualMembershipActivityId1 = $url['queryString']['id'];
401 // verify membership id and membership activity id with previous one
402 $this->assertEquals($expectedMembershipId, $actualMembershipId1);
403 $this->assertEquals($expectedMembershipId, $actualMembershipActivityId1);
405 // click through to the relationship view screen after edit
406 $this->click('css=li#tab_rel a');
407 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
408 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
409 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
411 // change the current employer of the contact
412 // creating another membership type
413 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
415 $this->click('link=Add Membership Type');
416 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
418 $this->type('name', "Membership Type Another $title");
420 $this->select2('member_of_contact_id', $title);
422 $this->type('minimum_fee', '100');
423 $this->select('financial_type_id', 'label=Member Dues');
424 $this->type('duration_interval', 1);
425 $this->select('duration_unit', 'label=year');
427 $this->select('period_type', 'value=rolling');
429 $this->removeSelection('relationship_type_id', 'label=- select -');
430 $this->addSelection('relationship_type_id', 'label=Employer of');
432 $this->type('max_related', '5');
434 $this->click('_qf_MembershipType_upload-bottom');
435 $this->waitForElementPresent('link=Add Membership Type');
436 $this->waitForText('crm-notification-container', "Membership Type Another $title");
438 // creating another Orgnization
439 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
440 $org2 = substr(sha1(rand()), 0, 7);
441 $this->type('organization_name', "Organization $org2");
442 $this->type('email_1_email', "$org2@org.com");
443 $this->clickLink('_qf_Contact_upload_view');
445 // click through to the membership view screen
446 $this->click('css=li#tab_member a');
447 $this->waitForElementPresent('link=Add Membership');
448 $this->click('link=Add Membership');
449 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
451 // fill in Membership Organization and Type
452 $this->select('membership_type_id[0]', "label=Organization $title");
453 $this->select('membership_type_id[1]', "label=Membership Type Another $title");
455 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
456 $this->type('source', $sourceText);
457 $this->clickLink('_qf_Membership_upload', 'link=Add Membership', FALSE);
458 $this->waitForTextPresent($sourceText);
460 // Is status message correct?
461 $this->waitForText('crm-notification-container', "Membership Type Another $title");
464 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
466 // change Current Employer
467 $this->select2('employer_id', $org2);
468 $this->clickLink("_qf_Contact_upload_view-bottom");
470 // click through to the membership view screen
471 $this->click('css=li#tab_member a');
472 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
473 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
474 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
475 $actualMembershipId2 = $url['queryString']['id'];
477 // click through to the activity view screen
478 $this->click('css=li#tab_activity a');
479 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
480 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
481 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
482 $actualMembershipActivityId2 = $url['queryString']['id'];
484 // verify membership id and membership activity id with previous one
485 $this->assertNotEquals($expectedMembershipId, $actualMembershipId2);
486 $this->assertNotEquals($expectedMembershipId, $actualMembershipActivityId2);
488 // click through to the relationship view screen
489 $this->click('css=li#tab_rel a');
490 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
491 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org2']"));
492 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
494 // creating another Orgnization with no membership
495 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
496 $org3 = substr(sha1(rand()), 0, 7);
497 $this->type('organization_name', "Organization $org3");
498 $this->type('email_1_email', "$org3@org.com");
499 $this->clickLink('_qf_Contact_upload_view');
502 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
504 // change Current Employer
505 $this->select2('employer_id', $org3);
506 $this->clickLink("_qf_Contact_upload_view-bottom");
508 // click through to the membership view screen
509 $this->click('css=li#tab_member a');
511 $this->waitForText("xpath=//div[@class='messages status no-popup']", "No memberships have been recorded for this contact.");
512 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_member']/a/em"));
514 // click through to the activity view screen
515 $this->click('css=li#tab_activity a');
516 $this->waitForText("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr/td", "No matches found.");
517 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
519 // click through to the relationship view screen
520 $this->click('css=li#tab_rel a');
521 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
522 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org3']"));
523 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));