Commit | Line | Data |
---|---|---|
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class 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() { | |
050fb75a PJ |
40 | //add the required permission |
41 | $permissions = array( | |
42 | 'edit-2-profile-listings-and-forms', | |
43 | 'edit-2-access-all-custom-data', | |
44 | 'edit-2-access-civicrm' | |
45 | ); | |
46 | $this->changePermissions($permissions); | |
a90b085c PJ |
47 | list($id, $profileTitle) = $this->_addNewProfile(TRUE, FALSE, TRUE); |
48 | $this->_deleteProfile($id, $profileTitle); | |
6a488035 | 49 | } |
b2552577 | 50 | |
6a488035 | 51 | function testAddNewNonMultiProfile() { |
6a488035 | 52 | $this->webtestLogin(); |
a90b085c PJ |
53 | list($id, $profileTitle) = $this->_addNewProfile(FALSE); |
54 | $this->_deleteProfile($id, $profileTitle); | |
6a488035 | 55 | } |
b2552577 | 56 | |
6a488035 | 57 | function testNonSearchableMultiProfile() { |
6a488035 | 58 | $this->webtestLogin(); |
a90b085c PJ |
59 | list($id, $profileTitle) = $this->_addNewProfile(TRUE, TRUE); |
60 | $this->_deleteProfile($id, $profileTitle); | |
6a488035 | 61 | } |
b2552577 | 62 | |
6a488035 | 63 | function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $userCheck = FALSE) { |
6a488035 | 64 | $params = $this->_testCustomAdd($checkSearchable); |
42daf119 | 65 | |
38bf8139 | 66 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
6a488035 | 67 | |
b2552577 | 68 | $this->click('newCiviCRMProfile-top'); |
6a488035 TO |
69 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
70 | ||
71 | //Name of profile | |
72 | $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7); | |
73 | $this->type('title', $profileTitle); | |
74 | ||
75 | //profile Used for | |
6a488035 TO |
76 | $this->click('uf_group_type_User Account'); |
77 | ||
78 | //Profile Advance Settings | |
79 | $this->click("//form[@id='Group']/div[2]/div[2]/div[1]"); | |
80 | ||
81 | //If you want member(s) of your organization to receive a | |
82 | //notification email whenever this Profile | |
83 | //form is used to enter or update contact information, enter one or more email addresses here. | |
84 | $this->type('notify', 'This is notify email'); | |
85 | ||
86 | //Drupal user account registration option | |
87 | $this->click('CIVICRM_QFID_0_8'); | |
88 | ||
89 | //What to do upon duplicate match | |
90 | $this->click('CIVICRM_QFID_1_4'); | |
91 | ||
92 | //Proximity search options | |
93 | $this->click('CIVICRM_QFID_0_14'); | |
94 | ||
95 | // enable maping for contact | |
96 | $this->click('is_map'); | |
97 | ||
98 | // include a link in the listings to Edit profile fields | |
99 | $this->click('is_edit_link'); | |
100 | ||
101 | //to view contacts' Drupal user account information | |
102 | $this->click('is_uf_link'); | |
103 | ||
104 | //click on save | |
105 | $this->click('_qf_Group_next'); | |
106 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
107 | ||
108 | //check for profile create | |
6c5f7368 | 109 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
6a488035 TO |
110 | |
111 | //Add field to profile | |
112 | $this->waitForElementPresent('field_name[0]'); | |
113 | $this->click('field_name[0]'); | |
114 | $this->select('field_name[0]', 'value=Contact'); | |
b2552577 | 115 | $this->click("//option[@value='Contact']"); |
6a488035 TO |
116 | $this->click('field_name_1'); |
117 | $this->select('field_name_1', 'label='.$params['textFieldLabel'].' :: '.$params['customGroupTitle']); | |
118 | if ($checkMultiRecord) { | |
119 | $this->click('is_multi_summary'); | |
120 | } | |
121 | if (!$checkSearchable) { | |
122 | $this->click('is_searchable'); | |
123 | $this->select('visibility', 'value=Public Pages and Listings'); | |
124 | } | |
125 | else { | |
126 | $this->select('visibility', 'value=User and User Admin Only'); | |
127 | } | |
128 | $this->click('in_selector'); | |
129 | $this->click('is_required'); | |
130 | $this->type('help_post', 'This is help for profile field'); | |
131 | $this->click('_qf_Field_next_new-top'); | |
132 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
133 | $this->click('field_name[0]'); | |
134 | $this->select('field_name[0]', 'value=Contact'); | |
135 | $this->click("//option[@value='Contact']"); | |
136 | $this->click('field_name_1'); | |
137 | $this->select('field_name_1', 'label='.$params['selectFieldLabel'].' :: '.$params['customGroupTitle']); | |
138 | if ($checkMultiRecord) { | |
139 | $this->click('is_multi_summary'); | |
140 | } | |
141 | $this->select('visibility', 'value=Public Pages and Listings'); | |
142 | $this->click('is_searchable'); | |
143 | $this->click('in_selector'); | |
144 | $this->type('help_post', 'This is help for profile field'); | |
145 | $this->click('_qf_Field_next_new-top'); | |
146 | ||
147 | // Add Contact | |
148 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
149 | $this->click('field_name[0]'); | |
150 | $this->select('field_name[0]', 'value=Student'); | |
151 | $this->click("//option[@value='Student']"); | |
b2552577 | 152 | |
6a488035 TO |
153 | $this->click('field_name_1'); |
154 | $this->select('field_name_1', 'value=first_name'); | |
155 | $this->click('is_multi_summary'); | |
156 | $this->select('visibility', 'value=Public Pages and Listings'); | |
157 | $this->click('is_searchable'); | |
158 | $this->click('in_selector'); | |
159 | $this->type('help_post', 'This is help for profile field'); | |
160 | $this->click('_qf_Field_next_new-top'); | |
161 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
162 | $this->click('field_name[0]'); | |
163 | $this->select('field_name[0]', 'value=Student'); | |
164 | $this->click("//option[@value='Student']"); | |
165 | $this->click('field_name_1'); | |
166 | $this->select('field_name_1', 'value=last_name'); | |
167 | $this->select('visibility', 'value=Public Pages and Listings'); | |
168 | $this->click('is_searchable'); | |
169 | $this->click('in_selector'); | |
170 | $this->type('help_post', 'This is help for profile field'); | |
171 | $this->click('_qf_Field_next_new-top'); | |
172 | ||
173 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
174 | $this->click('field_name[0]'); | |
175 | $this->select('field_name[0]', 'value=Contact'); | |
176 | $this->click("//option[@value='Contact']"); | |
177 | $this->click('field_name_1'); | |
178 | $this->select('field_name_1', 'value=email'); | |
179 | $this->select('visibility', 'value=Public Pages and Listings'); | |
180 | $this->click('is_searchable'); | |
181 | $this->type('help_post', 'This is help for profile field'); | |
182 | $this->click('_qf_Field_next'); | |
183 | //click on save | |
184 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
185 | ||
186 | $this->click('link=Use (create mode)'); | |
187 | $recordNew = $this->_addRecords('Create'); | |
188 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
a471a3b6 | 189 | $elements = $this->parseURL(); |
6a488035 TO |
190 | $gid = $elements['queryString']['gid']; |
191 | $id = $elements['queryString']['id']; | |
b2552577 | 192 | |
6a488035 | 193 | if ($userCheck) { |
b2552577 PJ |
194 | //add drupal user |
195 | $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name'); | |
6a488035 TO |
196 | $this->type('cms_name', $recordNew['firstname']); |
197 | $this->type('cms_pass', $recordNew['firstname']); | |
198 | $this->type('cms_confirm_pass', $recordNew['firstname']); | |
199 | $this->click('_qf_Useradd_next-bottom'); | |
200 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
42daf119 CW |
201 | $this->webtestLogout(); |
202 | ||
050fb75a | 203 | $this->webtestLogin($recordNew['firstname'], $recordNew['firstname']); |
6a488035 | 204 | } |
d45e6108 | 205 | $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL); |
6a488035 | 206 | if (!$checkMultiRecord) { |
38bf8139 | 207 | $this->assertElementContainsText('crm-container', 'No multi-record entries found'); |
a90b085c | 208 | return array($gid, $profileTitle); |
6a488035 TO |
209 | } |
210 | $this->waitForElementPresent("//div[@id='crm-profile-block']/a"); | |
211 | $this->click("//div[@id='crm-profile-block']/a"); | |
212 | $record1 = $this->_addRecords(); | |
213 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
214 | $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); | |
215 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text'])); | |
38bf8139 | 216 | $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//div[@id='crm-profile-block']/a"); |
6a488035 TO |
217 | $this->click("//div[@id='crm-profile-block']/a"); |
218 | $record2 = $this->_addRecords(); | |
219 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
220 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[3]/td[1]", preg_quote($record2['text'])); | |
b2552577 | 221 | |
6a488035 TO |
222 | // Check Max Record Limit |
223 | $this->verifyElementNotPresent("//div[@id='crm-profile-block']/a/span"); | |
b2552577 | 224 | |
6a488035 | 225 | //Check for edit functionality |
efb29358 CW |
226 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
227 | // Sleep should never be used for wait for anything to load from the server | |
228 | // Justification for this instance: FIXME | |
6a488035 TO |
229 | sleep(3); |
230 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Edit']"); | |
231 | $this->waitForElementPresent("//html/body/div[5]"); | |
232 | $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); | |
233 | $this->type("//div[@id='profile-dialog']/div/form/div[2]/div/div/div[2]/input", $recordNew['text'].'edit'); | |
234 | $this->click("//div[@id='profile-dialog']/div/form/div[2]/div[2]/span/input[@id='_qf_Edit_next']"); | |
235 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
236 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[1]/td[1]", preg_quote($recordNew['text'].'edit')); | |
b2552577 | 237 | |
6a488035 TO |
238 | // Check the delete functionality |
239 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']"); | |
240 | $this->waitForElementPresent("//html/body/div[5]"); | |
efb29358 CW |
241 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
242 | // Sleep should never be used for wait for anything to load from the server | |
243 | // Justification for this instance: FIXME | |
6a488035 | 244 | sleep(3); |
38bf8139 | 245 | $this->assertElementContainsText('profile-dialog', 'Are you sure you want to delete this record?'); |
6a488035 | 246 | $this->click('_qf_Edit_upload_delete'); |
b2552577 | 247 | |
6a488035 | 248 | // Check the view functionality |
efb29358 CW |
249 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
250 | // Sleep should never be used for wait for anything to load from the server | |
251 | // Justification for this instance: FIXME | |
6a488035 TO |
252 | sleep(3); |
253 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']"); | |
254 | $this->waitForElementPresent("//html/body/div[5]"); | |
38bf8139 PJ |
255 | $this->assertElementContainsText('ui-id-1', 'View '.$params['customGroupTitle']); |
256 | $this->assertElementContainsText('crm-container', $params['textFieldLabel']); | |
6a488035 TO |
257 | if ($checkSearchable) { |
258 | $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a"); | |
a90b085c | 259 | return array($gid, $profileTitle); |
6a488035 | 260 | } |
b2552577 | 261 | |
6a488035 TO |
262 | // Check Search Functionality |
263 | if (!$userCheck) { | |
264 | $this->click("//div[@id='profile-dialog']/div/div/div/div/div[2]/a"); | |
265 | $this->waitForElementPresent("//form[@id='Search']"); | |
266 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[2]", preg_quote($recordNew['firstname'])); | |
38bf8139 | 267 | $this->openCiviPage('profile/view', "reset=1&id=$id&gid=$gid", "//div[@id='row-first_name']/div[2]/a"); |
6a488035 TO |
268 | $this->click("//div[@id='row-first_name']/div[2]/a"); |
269 | $this->waitForElementPresent("//form[@id='Search']"); | |
270 | // Check that Email column is not present in selector results | |
271 | $this->verifyElementNotPresent("//form[@id='Search']/div[3]/div[2]/table/tbody/tr/th[7]/a[@label='Email (Primary)']"); | |
272 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr/th[3]/a", preg_quote($params['textFieldLabel'])); | |
273 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[3]", preg_quote($record1['text'])); | |
274 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[3]/td[3]", preg_quote($record2['text'])); | |
275 | } | |
a90b085c PJ |
276 | return array($gid, $profileTitle); |
277 | } | |
278 | ||
279 | function _deleteProfile($gid, $profileTitle) { | |
050fb75a | 280 | $this->webtestLogin(); |
a90b085c PJ |
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 | } |