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