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