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