Merge pull request #203 from mlutfy/CRM-11755
[civicrm-core.git] / tests / phpunit / WebTest / Member / InheritedMembershipTest.php
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Member_InheritedMembershipTest extends CiviSeleniumTestCase {
29 protected function setUp() {
30 parent::setUp();
31 }
32
33 function testInheritedMembership() {
34 // Log in using webtestLogin() method
35 $this->webtestLogin();
36
37 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
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());
44 $this->assertElementContainsText('crm-notification-container', "Organization {$title} has been created.");
45
46 $this->openCiviPage('admin/member/membershipType', 'reset=1&action=browse');
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');
72 $this->assertElementContainsText('crm-notification-container', "The membership type 'Membership Type $title' has been saved.");
73
74 $this->openCiviPage('contact/add', 'reset=1&ct=Organization', '_qf_Contact_cancel');
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?
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!");
109
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');
113
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();
118 foreach (array(
119 'joinDate', 'startDate', 'endDate') as $date) {
120 $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull);
121 }
122
123 $this->webtestVerifyTabularData(
124 array(
125 'Membership Type' => "Membership Type $title",
126 'Status' => 'New',
127 'Source' => $sourceText,
128 'Member Since' => $joinDate,
129 'Start date' => $startDate,
130 'End date' => $endDate,
131 'Max related' => "5"
132 )
133 );
134
135 // Adding contact
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");
139
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');
147
148 $this->webtestFillAutocomplete($title1);
149
150 $this->waitForElementPresent('quick-save');
151
152 $description = 'Well here is some description !!!!';
153 $this->type('description', $description);
154
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.');
160
161 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//div//table/tbody//tr/td[9]/span/a[text()='View']");
162
163 // click through to the membership view screen
164 $this->click('css=li#tab_member a');
165 $this->waitForElementPresent('css=div#memberships');
166
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");
170
171 $this->webtestVerifyTabularData(
172 array(
173 'Membership Type' => "Membership Type $title",
174 'Status' => 'New',
175 'Source' => $sourceText,
176 'Member Since' => $joinDate,
177 'Start date' => $startDate,
178 'End date' => $endDate,
179 )
180 );
181 $this->click("_qf_MembershipView_cancel-bottom");
182 $this->waitForElementPresent('css=div#memberships');
183
184 //1. change relationship status on form
185 $this->click('css=li#tab_rel a');
186 $this->waitForElementPresent('css=div.action-link');
187
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']");
191 $matches = array();
192 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
193 $id = $matches[1];
194
195 $this->waitForElementPresent('is_active');
196 //disable relationship
197 if ($this->isChecked('is_active')) {
198 $this->click('is_active');
199 }
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.');
204
205 // click through to the membership view screen
206 $this->click('css=li#tab_member a');
207
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.');
211
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");
216
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');
222 }
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.');
227
228 //check for memberships
229 $this->click('css=li#tab_member a');
230 $this->waitForElementPresent('css=div#memberships');
231
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']");
238
239 $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship?[\s\S]$/",
240 $this->getConfirmation()
241 ));
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
246 sleep(10);
247
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.');
251
252 //enable relationship
253 $this->click('css=li#tab_rel a');
254 $this->waitForElementPresent('css=div.action-link');
255
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']");
258
259 $this->assertTrue((bool)preg_match("/^Are you sure you want to re-enable this relationship?[\s\S]$/",
260 $this->getConfirmation()
261 ));
262 $this->chooseOkOnNextConfirmation();
263 $this->waitForPageToLoad($this->getTimeoutMsec());
264
265 //verify membership
266 $this->click('css=li#tab_member a');
267 $this->waitForElementPresent('css=div#memberships');
268 }
269 }
270