bae57f0f5bc047baf5870ff13a34d0cc97b56ffe
[civicrm-core.git] / tests / phpunit / WebTest / Profile / MultiRecordProfileAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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_Profile_MultiRecordProfileAddTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33 function testAdminAddNewProfile() {
34 $this->webtestLogin();
35 list($id, $profileTitle) = $this->_addNewProfile();
36 $this->_deleteProfile($id, $profileTitle);
37 }
38
39 function testUserAddNewProfile() {
40 //add the required permission
41 $permissions = array(
42 'edit-2-profile-listings-and-forms',
43 'edit-2-access-all-custom-data',
44 'edit-2-access-civicrm'
45 );
46 $this->changePermissions($permissions);
47 list($id, $profileTitle) = $this->_addNewProfile(TRUE, FALSE, TRUE);
48 $this->_deleteProfile($id, $profileTitle);
49 }
50
51 function testAddNewNonMultiProfile() {
52 $this->webtestLogin();
53 list($id, $profileTitle) = $this->_addNewProfile(FALSE);
54 $this->_deleteProfile($id, $profileTitle);
55 }
56
57 function testNonSearchableMultiProfile() {
58 $this->webtestLogin();
59 list($id, $profileTitle) = $this->_addNewProfile(TRUE, TRUE);
60 $this->_deleteProfile($id, $profileTitle);
61 }
62
63 function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $userCheck = FALSE) {
64 $params = $this->_testCustomAdd($checkSearchable);
65
66 $this->openCiviPage('admin/uf/group', 'reset=1');
67
68 $this->click('newCiviCRMProfile-top');
69 $this->waitForElementPresent('_qf_Group_next-bottom');
70
71 //Name of profile
72 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
73 $this->type('title', $profileTitle);
74
75 //profile Used for
76 $this->click('uf_group_type_User Account');
77
78 //Profile Advance Settings
79 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
80
81 //If you want member(s) of your organization to receive a
82 //notification email whenever this Profile
83 //form is used to enter or update contact information, enter one or more email addresses here.
84 $this->type('notify', 'This is notify email');
85
86 //Drupal user account registration option
87 $this->click('CIVICRM_QFID_0_8');
88
89 //What to do upon duplicate match
90 $this->click('CIVICRM_QFID_1_4');
91
92 //Proximity search options
93 $this->click('CIVICRM_QFID_0_14');
94
95 // enable maping for contact
96 $this->click('is_map');
97
98 // include a link in the listings to Edit profile fields
99 $this->click('is_edit_link');
100
101 //to view contacts' Drupal user account information
102 $this->click('is_uf_link');
103
104 //click on save
105 $this->click('_qf_Group_next');
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107
108 //check for profile create
109 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
110
111 //Add field to profile
112 $this->waitForElementPresent('field_name[0]');
113 $this->click('field_name[0]');
114 $this->select('field_name[0]', 'value=Contact');
115 $this->click("//option[@value='Contact']");
116 $this->click('field_name_1');
117 $this->select('field_name_1', 'label='.$params['textFieldLabel'].' :: '.$params['customGroupTitle']);
118 if ($checkMultiRecord) {
119 $this->click('is_multi_summary');
120 }
121 if (!$checkSearchable) {
122 $this->click('is_searchable');
123 $this->select('visibility', 'value=Public Pages and Listings');
124 }
125 else {
126 $this->select('visibility', 'value=User and User Admin Only');
127 }
128 $this->click('in_selector');
129 $this->click('is_required');
130 $this->type('help_post', 'This is help for profile field');
131 $this->click('_qf_Field_next_new-top');
132 $this->waitForPageToLoad($this->getTimeoutMsec());
133 $this->click('field_name[0]');
134 $this->select('field_name[0]', 'value=Contact');
135 $this->click("//option[@value='Contact']");
136 $this->click('field_name_1');
137 $this->select('field_name_1', 'label='.$params['selectFieldLabel'].' :: '.$params['customGroupTitle']);
138 if ($checkMultiRecord) {
139 $this->click('is_multi_summary');
140 }
141 $this->select('visibility', 'value=Public Pages and Listings');
142 $this->click('is_searchable');
143 $this->click('in_selector');
144 $this->type('help_post', 'This is help for profile field');
145 $this->click('_qf_Field_next_new-top');
146
147 // Add Contact
148 $this->waitForPageToLoad($this->getTimeoutMsec());
149 $this->click('field_name[0]');
150 $this->select('field_name[0]', 'value=Student');
151 $this->click("//option[@value='Student']");
152
153 $this->click('field_name_1');
154 $this->select('field_name_1', 'value=first_name');
155 $this->click('is_multi_summary');
156 $this->select('visibility', 'value=Public Pages and Listings');
157 $this->click('is_searchable');
158 $this->click('in_selector');
159 $this->type('help_post', 'This is help for profile field');
160 $this->click('_qf_Field_next_new-top');
161 $this->waitForPageToLoad($this->getTimeoutMsec());
162 $this->click('field_name[0]');
163 $this->select('field_name[0]', 'value=Student');
164 $this->click("//option[@value='Student']");
165 $this->click('field_name_1');
166 $this->select('field_name_1', 'value=last_name');
167 $this->select('visibility', 'value=Public Pages and Listings');
168 $this->click('is_searchable');
169 $this->click('in_selector');
170 $this->type('help_post', 'This is help for profile field');
171 $this->click('_qf_Field_next_new-top');
172
173 $this->waitForPageToLoad($this->getTimeoutMsec());
174 $this->click('field_name[0]');
175 $this->select('field_name[0]', 'value=Contact');
176 $this->click("//option[@value='Contact']");
177 $this->click('field_name_1');
178 $this->select('field_name_1', 'value=email');
179 $this->select('visibility', 'value=Public Pages and Listings');
180 $this->click('is_searchable');
181 $this->type('help_post', 'This is help for profile field');
182 $this->click('_qf_Field_next');
183 //click on save
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185
186 $this->click('link=Use (create mode)');
187 $recordNew = $this->_addRecords('Create');
188 $this->waitForPageToLoad($this->getTimeoutMsec());
189 $elements = $this->parseURL();
190
191 $gid = $elements['queryString']['gid'];
192 $id = $elements['queryString']['id'];
193
194 if ($userCheck) {
195 //add drupal user
196 $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name');
197 $this->type('cms_name', $recordNew['firstname']);
198 $this->type('cms_pass', $recordNew['firstname']);
199 $this->type('cms_confirm_pass', $recordNew['firstname']);
200 $this->click('_qf_Useradd_next-bottom');
201 $this->waitForPageToLoad($this->getTimeoutMsec());
202 $this->webtestLogout();
203
204 $this->webtestLogin($recordNew['firstname'], $recordNew['firstname']);
205 }
206 $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL);
207 if (!$checkMultiRecord) {
208 $this->assertElementContainsText('crm-container', 'No records');
209 return array($gid, $profileTitle);
210 }
211 $this->waitForElementPresent("//div[@id='crm-profile-block']/../a");
212 $this->click("//div[@id='crm-profile-block']/../a");
213 sleep(1);
214 $record1 = $this->_addRecords('Edit', FALSE, "//div[@class='crm-container-snippet']/form/div[2]/");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
216 $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel']));
217 $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text']));
218 $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//div[@id='crm-profile-block']/../a");
219 $this->click("//div[@id='crm-profile-block']/../a");
220 sleep(1);
221 $record2 = $this->_addRecords('Edit', FALSE, "//div[@class='crm-container-snippet']/form/div[2]/");
222 $this->waitForPageToLoad($this->getTimeoutMsec());
223 $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[3]/td[1]", preg_quote($record2['text']));
224
225 // Check Max Record Limit
226 $this->verifyElementNotPresent("//div[@id='crm-profile-block']/../a/span");
227
228 //Check for edit functionality
229 // Because it tends to cause problems, all uses of sleep() must be justified in comments
230 // Sleep should never be used for wait for anything to load from the server
231 // Justification for this instance: FIXME
232 sleep(3);
233 $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Edit']");
234 $this->waitForElementPresent("//html/body/div[5]");
235 $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel']));
236 $this->type("//div[@id='profile-dialog']/div/form/div[2]/div/div/div[2]/input", $recordNew['text'].'edit');
237 $this->click("//div[@id='profile-dialog']/div/form/div[2]/div[2]/span/input[@id='_qf_Edit_next']");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
239 $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[1]/td[1]", preg_quote($recordNew['text'].'edit'));
240
241 // Check the delete functionality
242 $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']");
243 $this->waitForElementPresent("//html/body/div[5]");
244 // Because it tends to cause problems, all uses of sleep() must be justified in comments
245 // Sleep should never be used for wait for anything to load from the server
246 // Justification for this instance: FIXME
247 sleep(3);
248 $this->assertElementContainsText('profile-dialog', 'Are you sure you want to delete this record?');
249 $this->click('_qf_Edit_upload_delete');
250
251 // Check the view functionality
252 // Because it tends to cause problems, all uses of sleep() must be justified in comments
253 // Sleep should never be used for wait for anything to load from the server
254 // Justification for this instance: FIXME
255 sleep(3);
256 $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']");
257 $this->waitForElementPresent("//html/body/div[5]");
258 $this->assertElementContainsText('ui-id-1', 'View '.$params['customGroupTitle']);
259 $this->assertElementContainsText('crm-container', $params['textFieldLabel']);
260 if ($checkSearchable) {
261 $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div/div[1]/div[2]/a");
262 return array($gid, $profileTitle);
263 }
264
265 // Check Search Functionality
266 if (!$userCheck) {
267 $this->click("//div[@id='profile-dialog']/div/div/div/div/div/div[2]/a");
268 $this->waitForElementPresent("//form[@id='Search']");
269 $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr[2]/td[2]", preg_quote($recordNew['firstname']));
270 $this->openCiviPage('profile/view', "reset=1&id=$id&gid=$gid", "//div[@id='row-first_name']/div[2]/a");
271 $this->click("//div[@id='row-first_name']/div[2]/a");
272 $this->waitForElementPresent("//form[@id='Search']");
273 // Check that Email column is not present in selector results
274 $this->verifyElementNotPresent("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr/th[7]/a[@label='Email (Primary)']");
275 $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr/th[3]/a", preg_quote($params['textFieldLabel']));
276 $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr[2]/td[3]", preg_quote($record1['text']));
277 $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]", preg_quote($record2['text']));
278 }
279 return array($gid, $profileTitle);
280 }
281
282 function _deleteProfile($gid, $profileTitle) {
283 $this->webtestLogin();
284 $this->openCiviPage("admin/uf/group", "action=delete&id={$gid}", '_qf_Group_next-bottom');
285 $this->click('_qf_Group_next-bottom');
286 $this->waitForPageToLoad($this->getTimeoutMsec());
287 $this->assertElementContainsText('crm-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
288 }
289
290 function _testCustomAdd($checkSearchable) {
291
292 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
293
294 //fill custom group title
295 $params['customGroupTitle'] = 'custom_group' . substr(sha1(rand()), 0, 3);
296 $this->click("title");
297 $this->type("title", $params['customGroupTitle']);
298
299 //custom group extends
300 $this->click("extends[0]");
301 $this->select("extends[0]", "label=Contacts");
302 $this->click("//option[@value='Contact']");
303 $this->waitForElementPresent("//input[@id='is_multiple']");
304 $this->click("//input[@id='is_multiple']");
305 $this->type("max_multiple", 3);
306 $this->click("//form[@id='Group']/div[2]/div[3]/span[1]/input");
307 $this->waitForPageToLoad($this->getTimeoutMsec());
308
309 //Is custom group created?
310 $this->assertElementContainsText('crm-container', $params['customGroupTitle']);
311 //add custom field - alphanumeric text
312 $params['textFieldLabel'] = 'test_text_field' . substr(sha1(rand()), 0, 3);
313 $this->click("header");
314 $this->type("label", $params['textFieldLabel']);
315 //Is searchable?
316 if (!$checkSearchable) {
317 $this->click("is_searchable");
318 }
319 $this->click("_qf_Field_next_new-bottom");
320 $this->waitForPageToLoad($this->getTimeoutMsec());
321 $this->click("data_type[0]");
322 $this->select("data_type[0]", "value=0");
323 $this->click("//option[@value='0']");
324 $this->click("data_type[1]");
325 $this->select("data_type[1]", "label=Select");
326 $this->click("//option[@value='Select']");
327
328 $params['selectFieldLabel'] = 'test_select' . substr(sha1(rand()), 0, 5);
329 $this->type("label", $params['selectFieldLabel']);
330 $selectOptionLabel1 = 'option1' . substr(sha1(rand()), 0, 3);
331 $this->type("option_label_1", $selectOptionLabel1);
332 $this->type("option_value_1", "1");
333 $selectOptionLabel2 = 'option2' . substr(sha1(rand()), 0, 3);
334 $this->type("option_label_2", $selectOptionLabel2);
335 $this->type("option_value_2", "2");
336 $this->click("link=another choice");
337
338 //enter pre help message
339 $this->type("help_pre", "this is field pre help");
340
341 //enter post help message
342 $this->type("help_post", "this field post help");
343
344 //Is searchable?
345 $this->click("is_searchable");
346
347 //clicking save
348 $this->click("_qf_Field_next_new-bottom");
349 $this->waitForPageToLoad($this->getTimeoutMsec());
350
351 //Is custom field created?
352 $this->assertElementContainsText('crm-container', $params['selectFieldLabel']);
353 return $params;
354 }
355
356 function _addRecords($context = 'Edit', $waitAtStart = TRUE, $parentElement = '//') {
357 if ($waitAtStart) {
358 $this->waitForPageToLoad($this->getTimeoutMsec());
359 }
360 $params['text'] = 'text' . substr(sha1(rand()), 0, 3);
361 $this->type("{$parentElement}div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']);
362 if ($context == 'Create') {
363 $params['firstname'] = 'John' . substr(sha1(rand()), 0, 3);
364 $this->type('first_name', $params['firstname']);
365 $params['lastname'] = 'Anderson' . substr(sha1(rand()), 0, 3);
366 $this->type('last_name', $params['lastname']);
367 $params['email'] = $params['firstname'].$params['lastname'].'@exa.com';
368 $this->type('email-Primary', $params['email']);
369 }
370 $this->waitForElementPresent("{$parentElement}div[@id='crm-profile-block']//div/div[2]/select");
371 $this->select("{$parentElement}div[@id='crm-profile-block']//div/div[2]/select",'value=1');
372 $this->click("{$parentElement}div[@class='crm-submit-buttons']/span/input[@id='_qf_Edit_next']");
373 return $params;
374 }
375 }