Develop 'context' param in BAO and api CRM-12464
[civicrm-core.git] / tests / phpunit / WebTest / Member / InheritedMembershipTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
29 protected function setUp() {
30 parent::setUp();
31 }
32
33 function testInheritedMembership() {
6a488035
TO
34 // Log in using webtestLogin() method
35 $this->webtestLogin();
36
9d15e987 37 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
6a488035
TO
38
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());
6c5f7368 44 $this->waitForText('crm-notification-container', "Organization {$title} has been created.");
6a488035 45
9d15e987 46 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
6a488035
TO
47
48 $this->click('link=Add Membership Type');
49 $this->waitForElementPresent('_qf_MembershipType_cancel-bottom');
50
51 $this->type('name', "Membership Type $title");
52
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");
57
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');
62
63 $this->select('period_type', 'label=rolling');
64
65 $this->removeSelection('relationship_type_id', 'label=- select -');
66 $this->addSelection('relationship_type_id', 'label=Employer of');
67
68 $this->type('max_related', '5');
69
70 $this->click('_qf_MembershipType_upload-bottom');
71 $this->waitForElementPresent('link=Add Membership Type');
6c5f7368 72 $this->waitForText('crm-notification-container', "Membership Type $title");
6a488035 73
9d15e987 74 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
6a488035
TO
75
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());
82
83 // click through to the membership view screen
84 $this->click('css=li#tab_member a');
85
86 $this->waitForElementPresent('link=Add Membership');
87 $this->click('link=Add Membership');
88
89 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
90
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");
94
95 $sourceText = 'Membership ContactAddTest with Fixed Membership Type';
96 // fill in Source
97 $this->type('source', $sourceText);
98
99 // Clicking save.
100 $this->click('_qf_Membership_upload');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102
103 // page was loaded
104 $this->waitForTextPresent($sourceText);
105
106 // Is status message correct?
6c5f7368 107 $this->waitForText('crm-notification-container', "Membership Type $title");
6a488035
TO
108
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');
112
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();
117 foreach (array(
118 'joinDate', 'startDate', 'endDate') as $date) {
119 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
120 }
9d15e987 121
6a488035
TO
122 $this->webtestVerifyTabularData(
123 array(
124 'Membership Type' => "Membership Type $title",
125 'Status' => 'New',
126 'Source' => $sourceText,
127 'Member Since' => $joinDate,
128 'Start date' => $startDate,
129 'End date' => $endDate,
130 'Max related' => "5"
131 )
132 );
133
134 // Adding contact
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");
138
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');
146
147 $this->webtestFillAutocomplete($title1);
148
149 $this->waitForElementPresent('quick-save');
150
151 $description = 'Well here is some description !!!!';
152 $this->type('description', $description);
153
154 //save the relationship
155 $this->click('quick-save');
156 $this->waitForElementPresent('current-relationships');
157 //check the status message
6c5f7368 158 $this->waitForText('crm-notification-container', 'New relationship created');
6a488035
TO
159
160 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
161
162 // click through to the membership view screen
163 $this->click('css=li#tab_member a');
164 $this->waitForElementPresent('css=div#memberships');
165
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");
169
170 $this->webtestVerifyTabularData(
171 array(
172 'Membership Type' => "Membership Type $title",
173 'Status' => 'New',
174 'Source' => $sourceText,
175 'Member Since' => $joinDate,
176 'Start date' => $startDate,
177 'End date' => $endDate,
178 )
179 );
180 $this->click("_qf_MembershipView_cancel-bottom");
181 $this->waitForElementPresent('css=div#memberships');
182
183 //1. change relationship status on form
184 $this->click('css=li#tab_rel a');
185 $this->waitForElementPresent('css=div.action-link');
186
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']");
a471a3b6 190 $id = $this->urlArg('cid');
6a488035
TO
191
192 $this->waitForElementPresent('is_active');
193 //disable relationship
194 if ($this->isChecked('is_active')) {
195 $this->click('is_active');
196 }
197 $this->click('_qf_Relationship_upload');
198 $this->waitForElementPresent('inactive-relationships');
199 //check the status message
6c5f7368 200 $this->waitForText('crm-notification-container', 'Relationship record has been updated');
6a488035
TO
201
202 // click through to the membership view screen
203 $this->click('css=li#tab_member a');
204
205 //verify inherited membership has been removed
9d15e987 206 $this->openCiviPage("contact/view", "reset=1&cid=$id&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]");
8fe1f83e 207 $this->assertElementContainsText('Memberships', 'No memberships have been recorded for this contact.');
6a488035
TO
208
209 // visit relationship tab and re-enable the relationship
210 $this->click('css=li#tab_rel a');
211 $this->waitForElementPresent('css=div.action-link');
212 $this->click("//li[@id='tab_rel']/a");
9d15e987 213
6a488035
TO
214 $this->waitForElementPresent("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
215 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span/a[text()='Edit']");
216 $this->waitForElementPresent('is_active');
217 if (!$this->isChecked('is_active')) {
218 $this->click('is_active');
219 }
220 $this->click('_qf_Relationship_upload');
221 $this->waitForElementPresent('current-relationships');
222 //check the status message
6c5f7368 223 $this->waitForText('crm-notification-container', 'Relationship record has been updated.');
6a488035
TO
224
225 //check for memberships
226 $this->click('css=li#tab_member a');
227 $this->waitForElementPresent('css=div#memberships');
228
229 //2 . visit relationship tab and disable the relationship (by links)
230 //disable relationship
231 $this->click('css=li#tab_rel a');
232 $this->waitForElementPresent('css=div.action-link');
233 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
234 $this->click("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
235
236 $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship?[\s\S]$/",
237 $this->getConfirmation()
238 ));
239 $this->chooseOkOnNextConfirmation();
efb29358
CW
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
6a488035
TO
243 sleep(10);
244
245 //verify inherited membership has been removed
9d15e987 246 $this->openCiviPage("contact/view", "reset=1&cid={$id}&selectedChild=member", "xpath=//div[@class='crm-container-snippet']/div/div[3]");
8fe1f83e 247 $this->assertElementContainsText('Memberships', 'No memberships have been recorded for this contact.');
6a488035
TO
248
249 //enable relationship
250 $this->click('css=li#tab_rel a');
251 $this->waitForElementPresent('css=div.action-link');
252
253 $this->waitForElementPresent("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
254 $this->click("xpath=//div[@id='inactive-relationships']//div//table/tbody//tr/td[7]/span[2][text()='more']/ul/li[1]/a[text()='Enable']");
255
256 $this->assertTrue((bool)preg_match("/^Are you sure you want to re-enable this relationship?[\s\S]$/",
257 $this->getConfirmation()
258 ));
259 $this->chooseOkOnNextConfirmation();
efb29358 260 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
261
262 //verify membership
263 $this->click('css=li#tab_member a');
264 $this->waitForElementPresent('css=div#memberships');
265 }
266}
267