3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Profile_MultiRecordProfileAddTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
33 function testAdminAddNewProfile() {
34 $this->webtestLogin();
35 list($id, $profileTitle) = $this->_addNewProfile();
36 $this->_deleteProfile($id, $profileTitle);
39 function testUserAddNewProfile() {
40 $this->webtestLogin();
41 list($id, $profileTitle) = $this->_addNewProfile(TRUE, FALSE, TRUE);
42 $this->_deleteProfile($id, $profileTitle);
45 function testAddNewNonMultiProfile() {
46 $this->webtestLogin();
47 list($id, $profileTitle) = $this->_addNewProfile(FALSE);
48 $this->_deleteProfile($id, $profileTitle);
51 function testNonSearchableMultiProfile() {
53 $this->webtestLogin();
54 list($id, $profileTitle) = $this->_addNewProfile(TRUE, TRUE);
55 $this->_deleteProfile($id, $profileTitle);
58 function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $userCheck = FALSE) {
59 $params = $this->_testCustomAdd($checkSearchable);
61 $this->openCiviPage('admin/uf/group', 'reset=1');
63 $this->click('newCiviCRMProfile-top');
64 $this->waitForElementPresent('_qf_Group_next-bottom');
67 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
68 $this->type('title', $profileTitle);
71 $this->click('uf_group_type_User Account');
73 //Profile Advance Settings
74 $this->click("//form[@id='Group']/div[2]/div[2]/div[1]");
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');
81 //Drupal user account registration option
82 $this->click('CIVICRM_QFID_0_8');
84 //What to do upon duplicate match
85 $this->click('CIVICRM_QFID_1_4');
87 //Proximity search options
88 $this->click('CIVICRM_QFID_0_14');
90 // enable maping for contact
91 $this->click('is_map');
93 // include a link in the listings to Edit profile fields
94 $this->click('is_edit_link');
96 //to view contacts' Drupal user account information
97 $this->click('is_uf_link');
100 $this->click('_qf_Group_next');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
103 //check for profile create
104 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
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');
110 $this->click("//option[@value='Contact']");
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');
116 if (!$checkSearchable) {
117 $this->click('is_searchable');
118 $this->select('visibility', 'value=Public Pages and Listings');
121 $this->select('visibility', 'value=User and User Admin Only');
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');
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');
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']");
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');
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');
179 $this->waitForPageToLoad($this->getTimeoutMsec());
181 $this->click('link=Use (create mode)');
182 $recordNew = $this->_addRecords('Create');
183 $this->waitForPageToLoad($this->getTimeoutMsec());
184 $elements = $this->parseURL();
185 $gid = $elements['queryString']['gid'];
186 $id = $elements['queryString']['id'];
190 $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name');
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());
196 $this->webtestLogout();
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());
206 $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL);
207 if (!$checkMultiRecord) {
208 $this->assertElementContainsText('crm-container', 'No multi-record entries found');
209 return array($gid, $profileTitle);
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']));
217 $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//div[@id='crm-profile-block']/a");
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']));
223 // Check Max Record Limit
224 $this->verifyElementNotPresent("//div[@id='crm-profile-block']/a/span");
226 //Check for edit functionality
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
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'));
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]");
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
246 $this->assertElementContainsText('profile-dialog', 'Are you sure you want to delete this record?');
247 $this->click('_qf_Edit_upload_delete');
249 // Check the view functionality
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
254 $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']");
255 $this->waitForElementPresent("//html/body/div[5]");
256 $this->assertElementContainsText('ui-id-1', 'View '.$params['customGroupTitle']);
257 $this->assertElementContainsText('crm-container', $params['textFieldLabel']);
258 if ($checkSearchable) {
259 $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a");
260 return array($gid, $profileTitle);
263 // Check Search Functionality
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']));
268 $this->openCiviPage('profile/view', "reset=1&id=$id&gid=$gid", "//div[@id='row-first_name']/div[2]/a");
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']));
277 return array($gid, $profileTitle);
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.");
287 function _testCustomAdd($checkSearchable) {
289 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
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']);
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());
306 //Is custom group created?
307 $this->assertElementContainsText('crm-container', $params['customGroupTitle']);
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']);
313 if (!$checkSearchable) {
314 $this->click("is_searchable");
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']");
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");
335 //enter pre help message
336 $this->type("help_pre", "this is field pre help");
338 //enter post help message
339 $this->type("help_post", "this field post help");
342 $this->click("is_searchable");
345 $this->click("_qf_Field_next_new-bottom");
346 $this->waitForPageToLoad($this->getTimeoutMsec());
348 //Is custom field created?
349 $this->assertElementContainsText('crm-container', $params['selectFieldLabel']);
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']);
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');
367 $this->click('_qf_Edit_next');