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 | ||
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 | $this->_addNewProfile(); | |
47 | } | |
48 | ||
49 | function testUserAddNewProfile() { | |
50 | // This is the path where our testing install resides. | |
51 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
52 | // class attributes. | |
53 | $this->open($this->sboxPath); | |
54 | ||
55 | // Logging in. Remember to wait for page to load. In most cases, | |
56 | // you can rely on 30000 as the value that allows your test to pass, however, | |
57 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
58 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
59 | // page contents loaded and you can continue your test execution. | |
60 | $this->webtestLogin(); | |
61 | $this->_addNewProfile(TRUE, FALSE, TRUE); | |
62 | } | |
b2552577 | 63 | |
6a488035 TO |
64 | function testAddNewNonMultiProfile() { |
65 | // This is the path where our testing install resides. | |
66 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
67 | // class attributes. | |
68 | $this->open($this->sboxPath); | |
69 | ||
70 | // Logging in. Remember to wait for page to load. In most cases, | |
71 | // you can rely on 30000 as the value that allows your test to pass, however, | |
72 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
73 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
74 | // page contents loaded and you can continue your test execution. | |
75 | $this->webtestLogin(); | |
76 | $this->_addNewProfile(FALSE); | |
77 | } | |
b2552577 | 78 | |
6a488035 TO |
79 | function testNonSearchableMultiProfile() { |
80 | // This is the path where our testing install resides. | |
81 | // The rest of URL is defined in CiviSeleniumTestCase base class, in | |
82 | // class attributes. | |
83 | $this->open($this->sboxPath); | |
84 | ||
85 | // Logging in. Remember to wait for page to load. In most cases, | |
86 | // you can rely on 30000 as the value that allows your test to pass, however, | |
87 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
88 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
89 | // page contents loaded and you can continue your test execution. | |
90 | $this->webtestLogin(); | |
91 | $this->_addNewProfile(TRUE, TRUE); | |
92 | } | |
b2552577 | 93 | |
6a488035 | 94 | function _addNewProfile($checkMultiRecord = TRUE, $checkSearchable = FALSE, $userCheck = FALSE) { |
6a488035 TO |
95 | $params = $this->_testCustomAdd($checkSearchable); |
96 | // Go directly to the URL of the screen that you will be | |
97 | // testing (Add new profile ). | |
98 | $this->open($this->sboxPath . 'civicrm/admin/uf/group?reset=1'); | |
6a488035 | 99 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
6a488035 | 100 | |
b2552577 | 101 | $this->click('newCiviCRMProfile-top'); |
6a488035 TO |
102 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
103 | ||
104 | //Name of profile | |
105 | $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7); | |
106 | $this->type('title', $profileTitle); | |
107 | ||
108 | //profile Used for | |
109 | $this->click('uf_group_type_User Registration'); | |
110 | $this->click('uf_group_type_User Account'); | |
111 | ||
112 | //Profile Advance Settings | |
113 | $this->click("//form[@id='Group']/div[2]/div[2]/div[1]"); | |
114 | ||
115 | //If you want member(s) of your organization to receive a | |
116 | //notification email whenever this Profile | |
117 | //form is used to enter or update contact information, enter one or more email addresses here. | |
118 | $this->type('notify', 'This is notify email'); | |
119 | ||
120 | //Drupal user account registration option | |
121 | $this->click('CIVICRM_QFID_0_8'); | |
122 | ||
123 | //What to do upon duplicate match | |
124 | $this->click('CIVICRM_QFID_1_4'); | |
125 | ||
126 | //Proximity search options | |
127 | $this->click('CIVICRM_QFID_0_14'); | |
128 | ||
129 | // enable maping for contact | |
130 | $this->click('is_map'); | |
131 | ||
132 | // include a link in the listings to Edit profile fields | |
133 | $this->click('is_edit_link'); | |
134 | ||
135 | //to view contacts' Drupal user account information | |
136 | $this->click('is_uf_link'); | |
137 | ||
138 | //click on save | |
139 | $this->click('_qf_Group_next'); | |
140 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
141 | ||
142 | //check for profile create | |
143 | $this->assertTrue($this->isTextPresent("Your CiviCRM Profile '$profileTitle' has been added. You can add fields to this profile now")); | |
144 | ||
145 | //Add field to profile | |
146 | $this->waitForElementPresent('field_name[0]'); | |
147 | $this->click('field_name[0]'); | |
148 | $this->select('field_name[0]', 'value=Contact'); | |
b2552577 | 149 | $this->click("//option[@value='Contact']"); |
6a488035 TO |
150 | $this->click('field_name_1'); |
151 | $this->select('field_name_1', 'label='.$params['textFieldLabel'].' :: '.$params['customGroupTitle']); | |
152 | if ($checkMultiRecord) { | |
153 | $this->click('is_multi_summary'); | |
154 | } | |
155 | if (!$checkSearchable) { | |
156 | $this->click('is_searchable'); | |
157 | $this->select('visibility', 'value=Public Pages and Listings'); | |
158 | } | |
159 | else { | |
160 | $this->select('visibility', 'value=User and User Admin Only'); | |
161 | } | |
162 | $this->click('in_selector'); | |
163 | $this->click('is_required'); | |
164 | $this->type('help_post', 'This is help for profile field'); | |
165 | $this->click('_qf_Field_next_new-top'); | |
166 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
167 | $this->click('field_name[0]'); | |
168 | $this->select('field_name[0]', 'value=Contact'); | |
169 | $this->click("//option[@value='Contact']"); | |
170 | $this->click('field_name_1'); | |
171 | $this->select('field_name_1', 'label='.$params['selectFieldLabel'].' :: '.$params['customGroupTitle']); | |
172 | if ($checkMultiRecord) { | |
173 | $this->click('is_multi_summary'); | |
174 | } | |
175 | $this->select('visibility', 'value=Public Pages and Listings'); | |
176 | $this->click('is_searchable'); | |
177 | $this->click('in_selector'); | |
178 | $this->type('help_post', 'This is help for profile field'); | |
179 | $this->click('_qf_Field_next_new-top'); | |
180 | ||
181 | // Add Contact | |
182 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
183 | $this->click('field_name[0]'); | |
184 | $this->select('field_name[0]', 'value=Student'); | |
185 | $this->click("//option[@value='Student']"); | |
b2552577 | 186 | |
6a488035 TO |
187 | $this->click('field_name_1'); |
188 | $this->select('field_name_1', 'value=first_name'); | |
189 | $this->click('is_multi_summary'); | |
190 | $this->select('visibility', 'value=Public Pages and Listings'); | |
191 | $this->click('is_searchable'); | |
192 | $this->click('in_selector'); | |
193 | $this->type('help_post', 'This is help for profile field'); | |
194 | $this->click('_qf_Field_next_new-top'); | |
195 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
196 | $this->click('field_name[0]'); | |
197 | $this->select('field_name[0]', 'value=Student'); | |
198 | $this->click("//option[@value='Student']"); | |
199 | $this->click('field_name_1'); | |
200 | $this->select('field_name_1', 'value=last_name'); | |
201 | $this->select('visibility', 'value=Public Pages and Listings'); | |
202 | $this->click('is_searchable'); | |
203 | $this->click('in_selector'); | |
204 | $this->type('help_post', 'This is help for profile field'); | |
205 | $this->click('_qf_Field_next_new-top'); | |
206 | ||
207 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
208 | $this->click('field_name[0]'); | |
209 | $this->select('field_name[0]', 'value=Contact'); | |
210 | $this->click("//option[@value='Contact']"); | |
211 | $this->click('field_name_1'); | |
212 | $this->select('field_name_1', 'value=email'); | |
213 | $this->select('visibility', 'value=Public Pages and Listings'); | |
214 | $this->click('is_searchable'); | |
215 | $this->type('help_post', 'This is help for profile field'); | |
216 | $this->click('_qf_Field_next'); | |
217 | //click on save | |
218 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
219 | ||
220 | $this->click('link=Use (create mode)'); | |
221 | $recordNew = $this->_addRecords('Create'); | |
222 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
223 | $elements = $this->parseURL( ); | |
6a488035 TO |
224 | $gid = $elements['queryString']['gid']; |
225 | $id = $elements['queryString']['id']; | |
b2552577 | 226 | |
6a488035 | 227 | if ($userCheck) { |
b2552577 PJ |
228 | //add drupal user |
229 | $this->openCiviPage('contact/view/useradd', "reset=1&action=add&cid=$id", 'cms_name'); | |
6a488035 TO |
230 | $this->type('cms_name', $recordNew['firstname']); |
231 | $this->type('cms_pass', $recordNew['firstname']); | |
232 | $this->type('cms_confirm_pass', $recordNew['firstname']); | |
233 | $this->click('_qf_Useradd_next-bottom'); | |
234 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
b2552577 | 235 | $this->open($this->sboxPath . "user/logout"); |
6a488035 TO |
236 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
237 | $this->open("{$this->sboxPath}user"); | |
238 | // Make sure login form is available | |
239 | $this->waitForElementPresent('edit-submit'); | |
240 | $this->type('edit-name', $recordNew['firstname']); | |
241 | $this->type('edit-pass', $recordNew['firstname']); | |
242 | $this->click('edit-submit'); | |
243 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
244 | } | |
245 | $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid); | |
246 | if (!$checkMultiRecord) { | |
247 | $this->assertTrue($this->isTextPresent('No multi-record entries found')); | |
248 | return; | |
249 | } | |
250 | $this->waitForElementPresent("//div[@id='crm-profile-block']/a"); | |
251 | $this->click("//div[@id='crm-profile-block']/a"); | |
252 | $record1 = $this->_addRecords(); | |
253 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
254 | $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); | |
255 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[2]/td[1]", preg_quote($record1['text'])); | |
256 | $this->open($this->sboxPath . 'civicrm/profile/edit?reset=1&id='.$id.'&gid='.$gid); | |
257 | $this->waitForElementPresent("//div[@id='crm-profile-block']/a"); | |
258 | $this->click("//div[@id='crm-profile-block']/a"); | |
259 | $record2 = $this->_addRecords(); | |
260 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
261 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[3]/td[1]", preg_quote($record2['text'])); | |
b2552577 | 262 | |
6a488035 TO |
263 | // Check Max Record Limit |
264 | $this->verifyElementNotPresent("//div[@id='crm-profile-block']/a/span"); | |
b2552577 | 265 | |
6a488035 TO |
266 | //Check for edit functionality |
267 | sleep(3); | |
268 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Edit']"); | |
269 | $this->waitForElementPresent("//html/body/div[5]"); | |
270 | $this->verifyText("//div[@id='browseValues']/div/div/table/thead/tr/th[1]", preg_quote($params['textFieldLabel'])); | |
271 | $this->type("//div[@id='profile-dialog']/div/form/div[2]/div/div/div[2]/input", $recordNew['text'].'edit'); | |
272 | $this->click("//div[@id='profile-dialog']/div/form/div[2]/div[2]/span/input[@id='_qf_Edit_next']"); | |
273 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
274 | $this->verifyText("//div[@id='browseValues']/div/div/table/tbody/tr[1]/td[1]", preg_quote($recordNew['text'].'edit')); | |
b2552577 | 275 | |
6a488035 TO |
276 | // Check the delete functionality |
277 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='Delete']"); | |
278 | $this->waitForElementPresent("//html/body/div[5]"); | |
279 | sleep(3); | |
280 | $this->assertTrue($this->isTextPresent('Are you sure you want to delete this record?')); | |
281 | $this->click('_qf_Edit_upload_delete'); | |
b2552577 | 282 | |
6a488035 TO |
283 | // Check the view functionality |
284 | sleep(3); | |
285 | $this->click("//div[@id='browseValues']/div/div/table/tbody/tr/td[3]/span/a[text()='View']"); | |
286 | $this->waitForElementPresent("//html/body/div[5]"); | |
287 | $this->assertTrue($this->isTextPresent('View '.$params['customGroupTitle'])); | |
288 | $this->assertTrue($this->isTextPresent($params['textFieldLabel'])); | |
289 | if ($checkSearchable) { | |
290 | $this->verifyElementNotPresent("//div[@id='profile-dialog']/div/div/div/div[1]/div[2]/a"); | |
291 | return; | |
292 | } | |
b2552577 | 293 | |
6a488035 TO |
294 | // Check Search Functionality |
295 | if (!$userCheck) { | |
296 | $this->click("//div[@id='profile-dialog']/div/div/div/div/div[2]/a"); | |
297 | $this->waitForElementPresent("//form[@id='Search']"); | |
298 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[2]", preg_quote($recordNew['firstname'])); | |
299 | $this->open($this->sboxPath . 'civicrm/profile/view?reset=1&id='.$id.'&gid='.$gid); | |
300 | $this->waitForElementPresent("//div[@id='row-first_name']/div[2]/a"); | |
301 | $this->click("//div[@id='row-first_name']/div[2]/a"); | |
302 | $this->waitForElementPresent("//form[@id='Search']"); | |
303 | // Check that Email column is not present in selector results | |
304 | $this->verifyElementNotPresent("//form[@id='Search']/div[3]/div[2]/table/tbody/tr/th[7]/a[@label='Email (Primary)']"); | |
305 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr/th[3]/a", preg_quote($params['textFieldLabel'])); | |
306 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[2]/td[3]", preg_quote($record1['text'])); | |
307 | $this->verifyText("//form[@id='Search']/div[3]/div[2]/table/tbody/tr[3]/td[3]", preg_quote($record2['text'])); | |
308 | } | |
309 | } | |
310 | ||
311 | function _testCustomAdd($checkSearchable) { | |
312 | // Go directly to the URL of the screen that you will be testing (Custom data for contacts). | |
313 | $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1"); | |
314 | // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
315 | // button at the end of this page to show up, to make sure it's fully loaded. | |
316 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
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->assertTrue($this->isTextPresent($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->assertTrue($this->isTextPresent($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[3]/div[2]/select"); | |
393 | $this->select("//div[@id='crm-profile-block']/div/div[3]/div[2]/select",'value=1'); | |
394 | $this->click('_qf_Edit_next'); | |
395 | return $params; | |
396 | } | |
397 | } |