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->waitForText('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->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->waitForPageToLoad($this->getTimeoutMsec());
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));
116 $configVars = new CRM_Core_Config_Variables();
118 'joinDate', 'startDate', 'endDate') as $date) {
119 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
122 $this->webtestVerifyTabularData(
124 'Membership Type' => "Membership Type $title",
126 'Source' => $sourceText,
127 'Member Since' => $joinDate,
128 'Start date' => $startDate,
129 'End date' => $endDate,
135 // We're using Quick Add block on the main page for this.
136 $firstName = substr(sha1(rand()), 0, 7);
137 $this->webtestAddContact($firstName, 'Anderson', "$firstName@anderson.name");
139 // visit relationship tab
140 $this->click('css=li#tab_rel a');
141 $this->waitForElementPresent('css=div.action-link');
142 $this->click("//div[@class='crm-container-snippet']/div/div[1]/div[1]/a/span");
143 $this->waitForPageToLoad($this->getTimeoutMsec());
144 $this->click('relationship_type_id');
145 $this->select('relationship_type_id', 'label=Employee of');
147 $this->webtestFillAutocomplete($title1);
149 $this->waitForElementPresent('quick-save');
151 $description = 'Well here is some description !!!!';
152 $this->type('description', $description);
154 //save the relationship
155 $this->click('quick-save');
156 $this->waitForElementPresent('current-relationships');
157 //check the status message
158 $this->waitForText('crm-notification-container', 'New relationship created');
160 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//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[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='Edit']");
189 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='Edit']");
191 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
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('inactive-relationships');
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='crm-container-snippet']/div/div[3]");
209 $this->assertElementContainsText('Memberships', '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[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
217 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/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('current-relationships');
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[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
236 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
238 $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship?[\s\S]$/",
239 $this->getConfirmation()
241 $this->chooseOkOnNextConfirmation();
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='crm-container-snippet']/div/div[3]");
249 $this->assertElementContainsText('Memberships', '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[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
256 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
258 $this->assertTrue((bool)preg_match("/^Are you sure you want to re-enable this relationship?[\s\S]$/",
259 $this->getConfirmation()
261 $this->chooseOkOnNextConfirmation();
262 $this->waitForPageToLoad($this->getTimeoutMsec());
265 $this->click('css=li#tab_member a');
266 $this->waitForElementPresent('css=div#memberships');