Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
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(); |
9c7c904f | 190 | |
6a488035 TO |
191 | $gid = $elements['queryString']['gid']; |
192 | $id = $elements['queryString']['id']; | |
b2552577 | 193 | |
6a488035 | 194 | if ($userCheck) { |
b2552577 PJ |
195 | //add drupal user |
196 | $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name'); | |
6a488035 TO |
197 | $this->type('cms_name', $recordNew['firstname']); |
198 | $this->type('cms_pass', $recordNew['firstname']); | |
199 | $this->type('cms_confirm_pass', $recordNew['firstname']); | |
200 | $this->click('_qf_Useradd_next-bottom'); | |
201 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
42daf119 CW |
202 | $this->webtestLogout(); |
203 | ||
050fb75a | 204 | $this->webtestLogin($recordNew['firstname'], $recordNew['firstname']); |
6a488035 | 205 | } |
d45e6108 | 206 | $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", NULL); |
6a488035 | 207 | if (!$checkMultiRecord) { |
9c7c904f | 208 | $this->assertElementContainsText('crm-container', 'No records'); |
a90b085c | 209 | return array($gid, $profileTitle); |
6a488035 | 210 | } |
ee88fff2 PJ |
211 | $this->waitForElementPresent("//a/span[contains(text(), 'Add New Record')]"); |
212 | $this->click("//a/span[contains(text(), 'Add New Record')]"); | |
6a488035 TO |
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'])); | |
ee88fff2 PJ |
217 | $this->openCiviPage('profile/edit', "reset=1&id=$id&gid=$gid", "//a/span[contains(text(), 'Add New Record')]"); |
218 | $this->click("//a/span[contains(text(), 'Add New Record')]"); | |
6a488035 TO |
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 | 223 | // Check Max Record Limit |
ee88fff2 | 224 | $this->verifyElementNotPresent("//a/span[contains(text(), 'Add New Record')]"); |
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'])); | |
ee88fff2 PJ |
234 | $this->type("//div[@id='profile-dialog']/div/form/div[2]/div/div[2]/input", $recordNew['text'].'edit'); |
235 | $this->click("//div[@id='profile-dialog']/div/form/div[3]/span/input[@id='_qf_Edit_next']"); | |
6a488035 TO |
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 | 258 | if ($checkSearchable) { |
9c7c904f | 259 | $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/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) { | |
9c7c904f | 265 | $this->click("//div[@id='profile-dialog']/div/div/div/div/div/div[2]/a"); |
6a488035 | 266 | $this->waitForElementPresent("//form[@id='Search']"); |
9c7c904f | 267 | $this->verifyText("//form[@id='Search']/div[2]/div[2]/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 | |
9c7c904f PJ |
272 | $this->verifyElementNotPresent("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr/th[7]/a[@label='Email (Primary)']"); |
273 | $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr/th[3]/a", preg_quote($params['textFieldLabel'])); | |
274 | $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr[2]/td[3]", preg_quote($record1['text'])); | |
275 | $this->verifyText("//form[@id='Search']/div[2]/div[2]/div[2]/table/tbody/tr[3]/td[3]", preg_quote($record2['text'])); | |
6a488035 | 276 | } |
a90b085c PJ |
277 | return array($gid, $profileTitle); |
278 | } | |
279 | ||
280 | function _deleteProfile($gid, $profileTitle) { | |
050fb75a | 281 | $this->webtestLogin(); |
a90b085c PJ |
282 | $this->openCiviPage("admin/uf/group", "action=delete&id={$gid}", '_qf_Group_next-bottom'); |
283 | $this->click('_qf_Group_next-bottom'); | |
284 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
285 | $this->assertElementContainsText('crm-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted."); | |
6a488035 TO |
286 | } |
287 | ||
288 | function _testCustomAdd($checkSearchable) { | |
42daf119 | 289 | |
38bf8139 | 290 | $this->openCiviPage('admin/custom/group', 'action=add&reset=1'); |
6a488035 TO |
291 | |
292 | //fill custom group title | |
293 | $params['customGroupTitle'] = 'custom_group' . substr(sha1(rand()), 0, 3); | |
294 | $this->click("title"); | |
295 | $this->type("title", $params['customGroupTitle']); | |
296 | ||
297 | //custom group extends | |
298 | $this->click("extends[0]"); | |
299 | $this->select("extends[0]", "label=Contacts"); | |
300 | $this->click("//option[@value='Contact']"); | |
301 | $this->waitForElementPresent("//input[@id='is_multiple']"); | |
302 | $this->click("//input[@id='is_multiple']"); | |
303 | $this->type("max_multiple", 3); | |
304 | $this->click("//form[@id='Group']/div[2]/div[3]/span[1]/input"); | |
305 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
306 | ||
307 | //Is custom group created? | |
38bf8139 | 308 | $this->assertElementContainsText('crm-container', $params['customGroupTitle']); |
6a488035 TO |
309 | //add custom field - alphanumeric text |
310 | $params['textFieldLabel'] = 'test_text_field' . substr(sha1(rand()), 0, 3); | |
311 | $this->click("header"); | |
312 | $this->type("label", $params['textFieldLabel']); | |
313 | //Is searchable? | |
314 | if (!$checkSearchable) { | |
315 | $this->click("is_searchable"); | |
316 | } | |
317 | $this->click("_qf_Field_next_new-bottom"); | |
318 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
319 | $this->click("data_type[0]"); | |
320 | $this->select("data_type[0]", "value=0"); | |
321 | $this->click("//option[@value='0']"); | |
322 | $this->click("data_type[1]"); | |
323 | $this->select("data_type[1]", "label=Select"); | |
324 | $this->click("//option[@value='Select']"); | |
325 | ||
326 | $params['selectFieldLabel'] = 'test_select' . substr(sha1(rand()), 0, 5); | |
327 | $this->type("label", $params['selectFieldLabel']); | |
328 | $selectOptionLabel1 = 'option1' . substr(sha1(rand()), 0, 3); | |
329 | $this->type("option_label_1", $selectOptionLabel1); | |
330 | $this->type("option_value_1", "1"); | |
331 | $selectOptionLabel2 = 'option2' . substr(sha1(rand()), 0, 3); | |
332 | $this->type("option_label_2", $selectOptionLabel2); | |
333 | $this->type("option_value_2", "2"); | |
334 | $this->click("link=another choice"); | |
335 | ||
336 | //enter pre help message | |
337 | $this->type("help_pre", "this is field pre help"); | |
338 | ||
339 | //enter post help message | |
340 | $this->type("help_post", "this field post help"); | |
341 | ||
342 | //Is searchable? | |
343 | $this->click("is_searchable"); | |
344 | ||
345 | //clicking save | |
346 | $this->click("_qf_Field_next_new-bottom"); | |
347 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
348 | ||
349 | //Is custom field created? | |
38bf8139 | 350 | $this->assertElementContainsText('crm-container', $params['selectFieldLabel']); |
6a488035 TO |
351 | return $params; |
352 | } | |
353 | ||
9c7c904f PJ |
354 | function _addRecords($context = 'Edit', $waitAtStart = TRUE, $parentElement = '//') { |
355 | if ($waitAtStart) { | |
356 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
357 | } | |
6a488035 | 358 | $params['text'] = 'text' . substr(sha1(rand()), 0, 3); |
ee88fff2 | 359 | $this->type("//div[@id='crm-profile-block']/div/div[2]/input[@type='text']", $params['text']); |
6a488035 TO |
360 | if ($context == 'Create') { |
361 | $params['firstname'] = 'John' . substr(sha1(rand()), 0, 3); | |
362 | $this->type('first_name', $params['firstname']); | |
363 | $params['lastname'] = 'Anderson' . substr(sha1(rand()), 0, 3); | |
364 | $this->type('last_name', $params['lastname']); | |
365 | $params['email'] = $params['firstname'].$params['lastname'].'@exa.com'; | |
366 | $this->type('email-Primary', $params['email']); | |
367 | } | |
ee88fff2 PJ |
368 | $this->waitForElementPresent("//div[@id='crm-profile-block']//div/div[2]/select"); |
369 | $this->select("//div[@id='crm-profile-block']//div/div[2]/select",'value=1'); | |
6a488035 TO |
370 | $this->click('_qf_Edit_next'); |
371 | return $params; | |
372 | } | |
232624b1 | 373 | } |