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();
119 'joinDate', 'startDate', 'endDate') as $date) {
120 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
123 $this->webtestVerifyTabularData(
125 'Membership Type' => "Membership Type $title",
127 'Source' => $sourceText,
128 'Member Since' => $joinDate,
129 'Start date' => $startDate,
130 'End date' => $endDate,
131 'Max related' => "5",
136 // We're using Quick Add block on the main page for this.
137 $firstName = substr(sha1(rand()), 0, 7);
138 $this->webtestAddContact($firstName, 'Anderson', "$firstName@anderson.name");
140 // visit relationship tab
141 $this->click('css=li#tab_rel a');
142 $this->waitForElementPresent('css=div.action-link');
143 $this->click("//div[@class='action-link']/a/span");
144 $this->waitForElementPresent('_qf_Relationship_cancel-bottom');
145 $this->click('relationship_type_id');
146 $this->select('relationship_type_id', 'label=Employee of');
148 $this->select2('related_contact_id', $title1, TRUE);
150 $description = 'Well here is some description !!!!';
151 $this->type('description', $description);
153 //save the relationship
154 $this->click('_qf_Relationship_upload-bottom');
155 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
156 //check the status message
157 $this->waitForText('crm-notification-container', 'Relationship created.');
159 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='View']");
161 // click through to the membership view screen
162 $this->click('css=li#tab_member a');
163 $this->waitForElementPresent('css=div#memberships');
165 // click through to the membership view screen
166 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
167 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
169 $this->webtestVerifyTabularData(
171 'Membership Type' => "Membership Type $title",
173 'Source' => $sourceText,
174 'Member Since' => $joinDate,
175 'Start date' => $startDate,
176 'End date' => $endDate,
179 $this->click("_qf_MembershipView_cancel-bottom");
180 $this->waitForElementPresent('css=div#memberships');
182 //1. change relationship status on form
183 $this->click('css=li#tab_rel a');
184 $this->waitForElementPresent('css=div.action-link');
186 $this->click("//li[@id='tab_rel']/a");
187 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
188 $id = explode('&id=', $this->getAttribute("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a@href"));
189 $id = explode('&', $id[0]);
190 $id = explode('=', $id[2]);
192 $this->click("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
194 $this->waitForElementPresent('is_active');
195 //disable relationship
196 if ($this->isChecked('is_active')) {
197 $this->click('is_active');
199 $this->click('_qf_Relationship_upload');
200 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
201 //check the status message
202 $this->waitForText('crm-notification-container', 'Relationship record has been updated');
204 // click through to the membership view screen
205 $this->click('css=li#tab_member a');
207 //verify inherited membership has been removed
208 $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
209 $this->assertElementContainsText("xpath=//div[@class='view-content']", 'No memberships have been recorded for this contact.');
211 // visit relationship tab and re-enable the relationship
212 $this->click('css=li#tab_rel a');
213 $this->waitForElementPresent('css=div.action-link');
214 $this->click("//li[@id='tab_rel']/a");
216 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
217 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div/table/tbody//tr/td[9]/span/a[text()='Edit']");
218 $this->waitForElementPresent('is_active');
219 if (!$this->isChecked('is_active')) {
220 $this->click('is_active');
222 $this->click('_qf_Relationship_upload');
223 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']");
224 //check the status message
225 $this->waitForText('crm-notification-container', 'Relationship record has been updated.');
227 //check for memberships
228 $this->click('css=li#tab_member a');
229 $this->waitForElementPresent('css=div#memberships');
231 //2 . visit relationship tab and disable the relationship (by links)
232 //disable relationship
233 $this->click('css=li#tab_rel a');
234 $this->waitForElementPresent('css=div.action-link');
235 $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']");
236 $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']");
237 $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?');
238 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Yes']");
239 // Because it tends to cause problems, all uses of sleep() must be justified in comments
240 // Sleep should never be used for wait for anything to load from the server
241 // Justification for this instance: FIXME
244 //verify inherited membership has been removed
245 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='view-content']/div[3]");
246 $this->assertElementContainsText("xpath=//div[@class='view-content']/div[3]", 'No memberships have been recorded for this contact.');
248 //enable relationship
249 $this->click('css=li#tab_rel a');
250 $this->waitForElementPresent('css=div.action-link');
252 $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']");
253 $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']");
256 $this->click('css=li#tab_member a');
257 $this->waitForElementPresent('css=div#memberships');
261 * Webtest for CRM-10146
263 public function testInheritedMembershipActivity() {
264 // Log in using webtestLogin() method
265 $this->webtestLogin();
267 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
269 $title = substr(sha1(rand()), 0, 7);
270 $this->type('organization_name', "Organization $title");
271 $this->type('email_1_email', "$title@org.com");
272 $this->clickLink('_qf_Contact_upload_view');
273 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
275 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
277 $this->click('link=Add Membership Type');
278 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
280 $this->type('name', "Membership Type $title");
282 $this->select2('member_of_contact_id', $title);
284 $this->type('minimum_fee', '100');
285 $this->select('financial_type_id', 'label=Member Dues');
286 $this->type('duration_interval', 1);
287 $this->select('duration_unit', 'label=year');
289 $this->select('period_type', 'value=rolling');
291 $this->removeSelection('relationship_type_id', 'label=- select -');
292 $this->addSelection('relationship_type_id', 'label=Employer of');
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 $this->assertEquals($expectedMembershipId, $actualMembershipId1);
400 $this->assertEquals($expectedMembershipId, $actualMembershipActivityId1);
402 // click through to the relationship view screen after edit
403 $this->click('css=li#tab_rel a');
404 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
405 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
406 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
408 // change the current employer of the contact
409 // creating another membership type
410 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
412 $this->click('link=Add Membership Type');
413 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
415 $this->type('name', "Membership Type Another $title");
417 $this->select2('member_of_contact_id', $title);
419 $this->type('minimum_fee', '100');
420 $this->select('financial_type_id', 'label=Member Dues');
421 $this->type('duration_interval', 1);
422 $this->select('duration_unit', 'label=year');
424 $this->select('period_type', 'value=rolling');
426 $this->removeSelection('relationship_type_id', 'label=- select -');
427 $this->addSelection('relationship_type_id', 'label=Employer of');
429 $this->type('max_related', '5');
431 $this->click('_qf_MembershipType_upload-bottom');
432 $this->waitForElementPresent('link=Add Membership Type');
433 $this->waitForText('crm-notification-container', "Membership Type Another $title");
435 // creating another Orgnization
436 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
437 $org2 = substr(sha1(rand()), 0, 7);
438 $this->type('organization_name', "Organization $org2");
439 $this->type('email_1_email', "$org2@org.com");
440 $this->clickLink('_qf_Contact_upload_view');
442 // click through to the membership view screen
443 $this->click('css=li#tab_member a');
444 $this->waitForElementPresent('link=Add Membership');
445 $this->click('link=Add Membership');
446 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
448 // fill in Membership Organization and Type
449 $this->select('membership_type_id[0]', "label=Organization $title");
450 $this->select('membership_type_id[1]', "label=Membership Type Another $title");
452 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
453 $this->type('source', $sourceText);
454 $this->clickLink('_qf_Membership_upload', 'link=Add Membership', FALSE);
455 $this->waitForTextPresent($sourceText);
457 // Is status message correct?
458 $this->waitForText('crm-notification-container', "Membership Type Another $title");
461 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
463 // change Current Employer
464 $this->select2('employer_id', $org2);
465 $this->clickLink("_qf_Contact_upload_view-bottom");
467 // click through to the membership view screen
468 $this->click('css=li#tab_member a');
469 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
470 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
471 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
472 $actualMembershipId2 = $url['queryString']['id'];
474 // click through to the activity view screen
475 $this->click('css=li#tab_activity a');
476 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
477 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
478 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
479 $actualMembershipActivityId2 = $url['queryString']['id'];
481 // verify membership id and membership activity id with previous one
482 $this->assertNotEquals($expectedMembershipId, $actualMembershipId2);
483 $this->assertNotEquals($expectedMembershipId, $actualMembershipActivityId2);
485 // click through to the relationship view screen
486 $this->click('css=li#tab_rel a');
487 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
488 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org2']"));
489 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
491 // creating another Orgnization with no membership
492 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
493 $org3 = substr(sha1(rand()), 0, 7);
494 $this->type('organization_name', "Organization $org3");
495 $this->type('email_1_email', "$org3@org.com");
496 $this->clickLink('_qf_Contact_upload_view');
499 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
501 // change Current Employer
502 $this->select2('employer_id', $org3);
503 $this->clickLink("_qf_Contact_upload_view-bottom");
505 // click through to the membership view screen
506 $this->click('css=li#tab_member a');
508 $this->waitForText("xpath=//div[@class='messages status no-popup']", "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"));