Merge pull request #3614 from eileenmcnaughton/CRM-14951
[civicrm-core.git] / tests / phpunit / WebTest / Member / BatchUpdateViaProfileTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Member_BatchUpdateViaProfileTest
31 */
32 class WebTest_Member_BatchUpdateViaProfileTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testMemberAdd() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership)
43 $memTypeParams = $this->webtestAddMembershipType();
44
45 $endDate = date('F jS, Y', strtotime("+1 year +1 month -1 day"));
46
47 // Add new individual using Quick Add block on the main page
48 $firstName1 = "John_" . substr(sha1(rand()), 0, 7);
49 $lastName = "Smith_" . substr(sha1(rand()), 0, 7);
50 $Name1 = $lastName . ', ' . $firstName1;
51 $this->webtestAddContact($firstName1, $lastName, "$firstName1.$lastName@example.com");
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53
54 // Add membership for this individual
55 $this->_addMembership($memTypeParams);
56 // Is status message correct?
57 $this->waitForText('crm-notification-container', "membership for $firstName1 $lastName has been added");
58
59 // click through to the membership view screen
60 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
61 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
62
63 // Verify End date
64 $verifyData = array(
65 'Membership Type' => $memTypeParams['membership_type'],
66 'Status' => 'New',
67 'End date' => $endDate,
68 );
69 $this->webtestVerifyTabularData($verifyData);
70
71 // Add new individual using Quick Add block on the main page
72 $firstName2 = "John_" . substr(sha1(rand()), 0, 7);
73 $Name2 = $lastName . ', ' . $firstName2;
74 $this->webtestAddContact($firstName2, $lastName, "$firstName2.$lastName@example.com");
75 $this->waitForPageToLoad($this->getTimeoutMsec());
76
77 // Add membership for this individual
78 $this->_addMembership($memTypeParams);
79 // Is status message correct?
80
81 $this->waitForText('crm-notification-container', "membership for $firstName2 $lastName has been added.");
82
83 // click through to the membership view screen
84 $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']");
85 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
86
87 // Verify End date
88 $verifyData = array(
89 'Membership Type' => $memTypeParams['membership_type'],
90 'Status' => 'New',
91 'End date' => $endDate,
92 );
93 $this->webtestVerifyTabularData($verifyData);
94
95 $profileTitle = 'Profile_' . substr(sha1(rand()), 0, 4);
96 $customDataParams = $this->_addCustomData();
97 $this->_addProfile($profileTitle, $customDataParams);
98
99 // Find Members
100 $this->openCiviPage("member/search", "reset=1", '_qf_Search_refresh');
101
102 $this->type('sort_name', $lastName);
103 $this->click('_qf_Search_refresh');
104 $this->waitForElementPresent('Go');
105
106 // Batch Update Via Profile
107 $this->click("xpath=//div[@id='search-status']/table/tbody/tr[2]/td[2]/input");
108 //$this->click('CIVICRM_QFID_ts_all_10');
109 $this->select('task', "label=Batch Update Members Via Profile");
110 $this->click('Go');
111 $this->waitForElementPresent('_qf_PickProfile_back-bottom');
112
113 $this->select('uf_group_id', "label={$profileTitle}");
114 $this->click('_qf_PickProfile_next-bottom');
115
116 $this->waitForElementPresent('_qf_Batch_back-bottom');
117 $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[3]/input", "This is test custom data text1");
118 $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name1}']/../td[4]/select", "label=Current");
119
120 $this->type("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[3]/input", "This is test custom data text2");
121 $this->select("xpath=//form[@id='Batch']/div[2]/table/tbody//tr/td[text()='{$Name2}']/../td[4]/select", "label=Grace");
122
123 $this->click('_qf_Batch_next-bottom');
124 $this->waitForElementPresent('_qf_Result_done');
125 $this->click('_qf_Result_done');
126 $this->waitForElementPresent('Go');
127
128 // View Membership
129 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name1}']/../../td[11]/span/a[text()='View']");
130 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
131
132 // Verify End date
133 $verifyData = array(
134 'Membership Type' => $memTypeParams['membership_type'],
135 'Status' => 'Current',
136 'End date' => $endDate,
137 );
138 $this->webtestVerifyTabularData($verifyData);
139
140 $this->click('_qf_MembershipView_cancel-bottom');
141 $this->waitForElementPresent('Go');
142
143 // View Membership
144 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[3]/a[text()='{$Name2}']/../../td[11]/span/a[text()='View']");
145 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
146
147 // Verify End date
148 $verifyData = array(
149 'Membership Type' => $memTypeParams['membership_type'],
150 'Status' => 'Grace',
151 'End date' => $endDate,
152 );
153 $this->webtestVerifyTabularData($verifyData);
154 }
155
156 /**
157 * @param $memTypeParams
158 */
159 function _addMembership($memTypeParams) {
160 // click through to the membership view screen
161 $this->click("css=li#tab_member a");
162 $this->waitForElementPresent("link=Add Membership");
163 $this->click("link=Add Membership");
164 $this->waitForElementPresent("_qf_Membership_cancel-bottom");
165
166 // fill in Membership Organization and Type
167 $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}");
168 // Wait for membership type select to reload
169 $this->waitForTextPresent($memTypeParams['membership_type']);
170 // Because it tends to cause problems, all uses of sleep() must be justified in comments
171 // Sleep should never be used for wait for anything to load from the server
172 // Justification for this instance: FIXME
173 sleep(3);
174 $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}");
175
176 $sourceText = "Membership ContactAddTest Webtest";
177 // fill in Source
178 $this->type("source", $sourceText);
179
180 // Let Join Date stay default
181
182 // fill in Start Date
183 $this->webtestFillDate('start_date');
184
185 // Clicking save.
186 $this->click("_qf_Membership_upload");
187 $this->waitForPageToLoad($this->getTimeoutMsec());
188
189 // page was loaded
190 $this->waitForTextPresent($sourceText);
191 }
192
193 /**
194 * @param $profileTitle
195 * @param $customDataParams
196 */
197 function _addProfile($profileTitle, $customDataParams) {
198
199 $this->openCiviPage("admin/uf/group", "reset=1");
200
201 $this->click('link=Add Profile');
202 // Add membership custom data field to profile
203 $this->waitForElementPresent('_qf_Group_cancel-bottom');
204 $this->type('title', $profileTitle);
205 $this->click('uf_group_type_Profile');
206 $this->click('_qf_Group_next-bottom');
207
208 $this->waitForElementPresent('_qf_Field_cancel-bottom');
209 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
210
211 $this->select('field_name[0]', "value=Membership");
212 $this->select('field_name[1]', "label={$customDataParams[0]} :: {$customDataParams[1]}");
213 $this->click('field_name[1]');
214 $this->click('label');
215
216 // Clicking save and new
217 $this->click('_qf_Field_next_new-bottom');
218 $this->waitForPageToLoad($this->getTimeoutMsec());
219 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field '{$customDataParams[0]}' has been saved to '{$profileTitle}'.");
220
221 // Add membership status field to profile - CRM-8618
222 $this->select('field_name[0]', "value=Membership");
223 $this->select('field_name[1]', "label=Membership Status");
224 $this->click('field_name[1]');
225 $this->click('label');
226 // Clicking save
227 $this->click('_qf_Field_next-bottom');
228 $this->waitForPageToLoad($this->getTimeoutMsec());
229 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Membership Status' has been saved to '{$profileTitle}'.");
230 }
231
232 /**
233 * @return array
234 */
235 function _addCustomData() {
236 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 4);
237
238 $this->openCiviPage('admin/custom/group', 'reset=1');
239
240 //add new custom data
241 $this->click("//a[@id='newCustomDataGroup']/span");
242 $this->waitForPageToLoad($this->getTimeoutMsec());
243
244 //fill custom group title
245 $this->click("title");
246 $this->type("title", $customGroupTitle);
247
248 //custom group extends
249 $this->click("extends[0]");
250 $this->select("extends[0]", "value=Membership");
251 $this->click("//option[@value='Membership']");
252 $this->click('_qf_Group_next-bottom');
253 $this->waitForElementPresent('_qf_Field_cancel-bottom');
254
255 //Is custom group created?
256 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
257
258 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
259 $this->type('label', $textFieldLabel);
260
261 //enter pre help msg
262 $this->type('help_pre', "this is field pre help");
263
264 //enter post help msg
265 $this->type('help_post', "this is field post help");
266
267 //Is searchable?
268 $this->click('is_searchable');
269
270 //clicking save
271 $this->click('_qf_Field_next');
272 $this->waitForPageToLoad($this->getTimeoutMsec());
273
274 //Is custom field created
275 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' has been saved.");
276
277 return array($textFieldLabel, $customGroupTitle);
278 }
279 }