3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
28 class WebTest_Member_InheritedMembershipTest
extends CiviSeleniumTestCase
{
29 protected function setUp() {
33 function testInheritedMembership() {
34 // Log in using webtestLogin() method
35 $this->webtestLogin();
37 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
39 $title = substr(sha1(rand()), 0, 7);
40 $this->type('organization_name', "Organization $title");
41 $this->type('email_1_email', "$title@org.com");
42 $this->click('_qf_Contact_upload_view');
43 $this->waitForPageToLoad($this->getTimeoutMsec());
44 $this->assertElementContainsText('crm-notification-container', "Organization {$title} has been created.");
46 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
48 $this->click('link=Add Membership Type');
49 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
51 $this->type('name', "Membership Type $title");
53 $this->type('member_of_contact', $title);
54 $this->click('member_of_contact');
55 $this->waitForElementPresent("css=div.ac_results-inner li");
56 $this->click("css=div.ac_results-inner li");
58 $this->type('minimum_fee', '100');
59 $this->select( 'financial_type_id', 'value=2' );
60 $this->type('duration_interval', 1);
61 $this->select('duration_unit', 'label=year');
63 $this->select('period_type', 'label=rolling');
65 $this->removeSelection('relationship_type_id', 'label=- select -');
66 $this->addSelection('relationship_type_id', 'label=Employer of');
68 $this->type('max_related', '5');
70 $this->click('_qf_MembershipType_upload-bottom');
71 $this->waitForElementPresent('link=Add Membership Type');
72 $this->assertElementContainsText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
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->waitForPageToLoad($this->getTimeoutMsec());
104 $this->waitForTextPresent($sourceText);
106 // Is status message correct?
107 $this->assertElementContainsText('crm-notification-container', "Membership Type $title membership for Organization $title1 has been added.",
108 "Status message didn't show up after saving!");
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='crm-container-snippet']/div/div[1]/div[1]/a/span");
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145 $this->click('relationship_type_id');
146 $this->select('relationship_type_id', 'label=Employee of');
148 $this->webtestFillAutocomplete($title1);
150 $this->waitForElementPresent('quick-save');
152 $description = 'Well here is some description !!!!';
153 $this->type('description', $description);
155 //save the relationship
156 $this->click('quick-save');
157 $this->waitForElementPresent('current-relationships');
158 //check the status message
159 $this->assertElementContainsText('crm-notification-container', 'New relationship created.');
161 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
163 // click through to the membership view screen
164 $this->click('css=li#tab_member a');
165 $this->waitForElementPresent('css=div#memberships');
167 // click through to the membership view screen
168 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
169 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
171 $this->webtestVerifyTabularData(
173 'Membership Type' => "Membership Type $title",
175 'Source' => $sourceText,
176 'Member Since' => $joinDate,
177 'Start date' => $startDate,
178 'End date' => $endDate,
181 $this->click("_qf_MembershipView_cancel-bottom");
182 $this->waitForElementPresent('css=div#memberships');
184 //1. change relationship status on form
185 $this->click('css=li#tab_rel a');
186 $this->waitForElementPresent('css=div.action-link');
188 $this->click("//li[@id='tab_rel']/a");
189 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='Edit']");
190 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='Edit']");
192 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
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('inactive-relationships');
202 //check the status message
203 $this->assertElementContainsText('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='crm-container-snippet']/div/div[3]");
210 $this->assertElementContainsText('Memberships', '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[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
218 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/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('current-relationships');
225 //check the status message
226 $this->assertElementContainsText('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[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
237 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
239 $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship?[\s\S]$/",
240 $this->getConfirmation()
242 $this->chooseOkOnNextConfirmation();
243 // Because it tends to cause problems, all uses of sleep() must be justified in comments
244 // Sleep should never be used for wait for anything to load from the server
245 // Justification for this instance: FIXME
248 //verify inherited membership has been removed
249 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]");
250 $this->assertElementContainsText('Memberships', 'No memberships have been recorded for this contact.');
252 //enable relationship
253 $this->click('css=li#tab_rel a');
254 $this->waitForElementPresent('css=div.action-link');
256 $this->waitForElementPresent("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
257 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
259 $this->assertTrue((bool)preg_match("/^Are you sure you want to re-enable this relationship?[\s\S]$/",
260 $this->getConfirmation()
262 $this->chooseOkOnNextConfirmation();
263 $this->waitForPageToLoad($this->getTimeoutMsec());
266 $this->click('css=li#tab_member a');
267 $this->waitForElementPresent('css=div#memberships');