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