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 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,
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');
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->assertElementContainsText("xpath=//div[@class='view-content']", '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->waitForText("xpath=//div[@class='crm-confirm-dialog ui-dialog-content ui-widget-content modal-dialog']", '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->assertElementContainsText("xpath=//div[@class='view-content']/div[3]", '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-current']/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-current']/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->waitForElementPresent('css=div#memberships');
262 * Webtest for CRM-10146
265 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->removeSelection('relationship_type_id', 'label=- select -');
294 $this->addSelection('relationship_type_id', 'label=Employer of');
296 $this->type('max_related', '5');
298 $this->click('_qf_MembershipType_upload-bottom');
299 $this->waitForElementPresent('link=Add Membership Type');
300 $this->waitForText('crm-notification-container', "Membership Type $title");
302 // creating another Organization
303 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
304 $org1 = substr(sha1(rand()), 0, 7);
305 $this->type('organization_name', "Organization $org1");
306 $this->type('email_1_email', "$org1@org.com");
307 $this->clickLink('_qf_Contact_upload_view');
309 // click through to the membership view screen
310 $this->click('css=li#tab_member a');
312 $this->waitForElementPresent('link=Add Membership');
313 $this->click('link=Add Membership');
315 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
317 // fill in Membership Organization and Type
318 $this->select('membership_type_id[0]', "label=Organization $title");
319 $this->select('membership_type_id[1]', "label=Membership Type $title");
321 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
323 $this->type('source', $sourceText);
326 $this->click('_qf_Membership_upload');
329 $this->waitForTextPresent($sourceText);
331 // Is status message correct?
332 $this->waitForText('crm-notification-container', "Membership Type $title");
335 $this->openCiviPage('contact/add', 'reset=1&ct=Individual', '_qf_Contact_cancel-bottom');
336 $firstName = substr(sha1(rand()), 0, 7);
337 $lastName = 'Anderson';
338 $email = "$firstName@anderson.name";
339 $this->type("first_name", $firstName);
340 $this->type("last_name", $lastName);
342 // Set Current Employer
343 $this->select2('employer_id', $org1);
344 $this->waitForText('s2id_employer_id', $org1);
346 $this->type("email_1_email", $email);
347 $this->clickLink("_qf_Contact_upload_view-bottom");
348 $cid = $this->urlArg('cid');
350 // click through to the membership view screen
351 $this->click('css=li#tab_member a');
352 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
354 // check number of membership for contact
355 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
357 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
358 $expectedMembershipId = $url['queryString']['id'];
360 // click through to the activity view screen
361 $this->click('css=li#tab_activity a');
362 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
364 // check number of activity for contact
365 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
367 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
368 $expectedMembershipActivityId = $url['queryString']['id'];
370 // verify membership id with membership activity id
371 $this->assertEquals($expectedMembershipId, $expectedMembershipActivityId);
373 // click through to the relationship view screen
374 $this->click('css=li#tab_rel a');
375 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
376 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
377 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
379 // Edit Contact but do not change any field
380 $this->waitForElementPresent("xpath=//ul[@id='actions']/li[2]/a/span");
381 $this->clickLink("xpath=//ul[@id='actions']/li[2]/a/span");
382 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
383 $this->clickLink("_qf_Contact_upload_view-top");
385 // click through to the membership view screen after edit
386 $this->click('css=li#tab_member a');
387 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
388 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
390 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
391 $actualMembershipId1 = $url['queryString']['id'];
393 // click through to the activity view screen after edit
394 $this->click('css=li#tab_activity a');
395 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
396 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
397 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
398 $actualMembershipActivityId1 = $url['queryString']['id'];
400 // verify membership id and membership activity id with previous one
401 $this->assertEquals($expectedMembershipId, $actualMembershipId1);
402 $this->assertEquals($expectedMembershipId, $actualMembershipActivityId1);
404 // click through to the relationship view screen after edit
405 $this->click('css=li#tab_rel a');
406 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
407 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org1']"));
408 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
410 // change the current employer of the contact
411 // creating another membership type
412 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
414 $this->click('link=Add Membership Type');
415 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
417 $this->type('name', "Membership Type Another $title");
419 $this->select2('member_of_contact_id', $title);
421 $this->type('minimum_fee', '100');
422 $this->select('financial_type_id', 'label=Member Dues');
423 $this->type('duration_interval', 1);
424 $this->select('duration_unit', 'label=year');
426 $this->select('period_type', 'value=rolling');
428 $this->removeSelection('relationship_type_id', 'label=- select -');
429 $this->addSelection('relationship_type_id', 'label=Employer of');
431 $this->type('max_related', '5');
433 $this->click('_qf_MembershipType_upload-bottom');
434 $this->waitForElementPresent('link=Add Membership Type');
435 $this->waitForText('crm-notification-container', "Membership Type Another $title");
437 // creating another Orgnization
438 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
439 $org2 = substr(sha1(rand()), 0, 7);
440 $this->type('organization_name', "Organization $org2");
441 $this->type('email_1_email', "$org2@org.com");
442 $this->clickLink('_qf_Contact_upload_view');
444 // click through to the membership view screen
445 $this->click('css=li#tab_member a');
446 $this->waitForElementPresent('link=Add Membership');
447 $this->click('link=Add Membership');
448 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
450 // fill in Membership Organization and Type
451 $this->select('membership_type_id[0]', "label=Organization $title");
452 $this->select('membership_type_id[1]', "label=Membership Type Another $title");
454 $sourceText = 'Membership ContactAddTest with Rolling Membership Type';
455 $this->type('source', $sourceText);
456 $this->clickLink('_qf_Membership_upload', 'link=Add Membership', FALSE);
457 $this->waitForTextPresent($sourceText);
459 // Is status message correct?
460 $this->waitForText('crm-notification-container', "Membership Type Another $title");
463 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
465 // change Current Employer
466 $this->select2('employer_id', $org2);
467 $this->clickLink("_qf_Contact_upload_view-bottom");
469 // click through to the membership view screen
470 $this->click('css=li#tab_member a');
471 $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
472 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_member']/a/em"));
473 $url = $this->parseURL($this->getAttribute("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']@href"));
474 $actualMembershipId2 = $url['queryString']['id'];
476 // click through to the activity view screen
477 $this->click('css=li#tab_activity a');
478 $this->waitForElementPresent("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']");
479 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
480 $url = $this->parseURL($this->getAttribute("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody//tr/td[8]/span/a[text()='View']@href"));
481 $actualMembershipActivityId2 = $url['queryString']['id'];
483 // verify membership id and membership activity id with previous one
484 $this->assertNotEquals($expectedMembershipId, $actualMembershipId2);
485 $this->assertNotEquals($expectedMembershipId, $actualMembershipActivityId2);
487 // click through to the relationship view screen
488 $this->click('css=li#tab_rel a');
489 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
490 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org2']"));
491 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));
493 // creating another Orgnization with no membership
494 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
495 $org3 = substr(sha1(rand()), 0, 7);
496 $this->type('organization_name', "Organization $org3");
497 $this->type('email_1_email', "$org3@org.com");
498 $this->clickLink('_qf_Contact_upload_view');
501 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$cid", "_qf_Contact_cancel-bottom");
503 // change Current Employer
504 $this->select2('employer_id', $org3);
505 $this->clickLink("_qf_Contact_upload_view-bottom");
507 // click through to the membership view screen
508 $this->click('css=li#tab_member a');
510 $this->waitForText("xpath=//div[@class='messages status no-popup']", "No memberships have been recorded for this contact.");
511 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_member']/a/em"));
513 // click through to the activity view screen
514 $this->click('css=li#tab_activity a');
515 $this->waitForText("xpath=//table[@class='contact-activity-selector-activity dataTable no-footer']/tbody/tr/td", "No matches found.");
516 $this->assertEquals(0, $this->getText("xpath=//li[@id='tab_activity']/a/em"));
518 // click through to the relationship view screen
519 $this->click('css=li#tab_rel a');
520 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a");
521 $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-contact-relationship-current']/div/table/tbody/tr/td[2]/a[text()='Organization $org3']"));
522 $this->assertEquals(1, $this->getText("xpath=//li[@id='tab_rel']/a/em"));