Merge pull request #7091 from mollux/CRM-17477
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Contact_AddTest
31 */
32 class WebTest_Contact_AddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testIndividualAdd() {
39 $this->webtestLogin();
40
41 $groupName = $this->WebtestAddGroup();
42
43 // go to display preferences to enable Open ID field
44 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
45 $this->waitForAjaxContent();
46 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
47 $this->click("_qf_Display_next-bottom");
48 $this->waitForPageToLoad($this->getTimeoutMsec());
49 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
50
51 //contact details section
52 //select prefix
53 $this->click("prefix_id");
54 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
55
56 //fill in first name
57 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
58
59 //fill in middle name
60 $this->type("middle_name", "Bruce");
61
62 //fill in last name
63 $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith");
64
65 //select suffix
66 $this->select("suffix_id", "value=3");
67
68 //fill in nick name
69 $this->type("nick_name", "jsmith");
70
71 //fill in email
72 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
73
74 //fill in phone
75 $this->type("phone_1_phone", "2222-4444");
76
77 //fill in IM
78 $this->type("im_1_name", "testYahoo");
79
80 //fill in openID
81 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com");
82
83 //fill in website
84 $this->type("website_1_url", "http://www.john.com");
85
86 //fill in source
87 $this->type("contact_source", "johnSource");
88
89 //fill in external identifier
90 $indExternalId = substr(sha1(rand()), 0, 4);
91 $this->type("external_identifier", $indExternalId);
92
93 //check for matching contact
94 $this->click("_qf_Contact_refresh_dedupe");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96
97 //address section
98 $this->click("addressBlock");
99 $this->waitForElementPresent("address_1_street_address");
100 //fill in address 1
101 $this->type("address_1_street_address", "902C El Camino Way SW");
102 $this->type("address_1_city", "Dumfries");
103 $this->type("address_1_postal_code", "1234");
104
105 $this->click("address_1_country_id");
106 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
107
108 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
109 $this->type("address_1_geo_code_1", "1234");
110 $this->type("address_1_geo_code_2", "5678");
111 }
112
113 //fill in address 2
114 $this->click("//div[@id='addMoreAddress1']/a/span");
115 $this->waitForElementPresent("address_2_street_address");
116 $this->type("address_2_street_address", "2782Y Dowlen Path W");
117 $this->type("address_2_city", "Birmingham");
118 $this->type("address_2_postal_code", "3456");
119
120 $this->click("address_2_country_id");
121 $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID());
122
123 if ($this->assertElementContainsText('address_table_2', "Latitude")) {
124 $this->type("address_2_geo_code_1", "1234");
125 $this->type("address_2_geo_code_2", "5678");
126 }
127
128 //Communication Preferences section
129 $this->click("commPrefs");
130
131 //select greeting/addressee options
132 $this->waitForElementPresent("email_greeting_id");
133 $this->select("email_greeting_id", "value=2");
134 $this->select("postal_greeting_id", "value=3");
135
136 //Select preferred method for Privacy
137 $this->click("privacy[do_not_trade]");
138 $this->click("privacy[do_not_sms]");
139
140 //Select preferred method(s) of communication
141 $this->click("preferred_communication_method[1]");
142 $this->click("preferred_communication_method[2]");
143
144 //select preferred language
145 $this->waitForElementPresent("preferred_language");
146 $this->select("preferred_language", "value=en_US");
147
148 //Notes section
149 $this->click("notesBlock");
150 $this->waitForElementPresent("subject");
151 $this->type("subject", "test note");
152 $this->type("note", "this is a test note contact webtest");
153 $this->assertElementContainsText('notesBlock', "Subject\n Note");
154
155 //Demographics section
156 $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]");
157 $this->waitForElementPresent("birth_date");
158
159 $this->webtestFillDate('birth_date', "-1 year");
160
161 //Tags and Groups section
162 $this->click("tagGroup");
163
164 // select group
165 $this->select("group", "label=$groupName");
166 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
167
168 // Clicking save.
169 $this->click("_qf_Contact_upload_view");
170
171 $this->waitForPageToLoad($this->getTimeoutMsec());
172 $this->waitForText('crm-notification-container', "Contact Saved");
173 }
174
175 public function testHouseholdAdd() {
176 $this->webtestLogin();
177
178 $groupName = $this->WebtestAddGroup();
179
180 // go to display preferences to enable Open ID field
181 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
182 $this->waitForAjaxContent();
183 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
184 $this->click("_qf_Display_next-bottom");
185 $this->waitForPageToLoad($this->getTimeoutMsec());
186
187 $this->openCiviPage('contact/add', "reset=1&ct=Household");
188
189 //contact details section
190 //fill in Household name
191 $this->click("household_name");
192 $name = substr(sha1(rand()), 0, 7) . "Fraddie Grant's home ";
193 $this->type("household_name", $name);
194
195 //fill in nick name
196 $this->type("nick_name", substr(sha1(rand()), 0, 7) . "Grant's home");
197
198 //fill in email
199 $email = substr(sha1(rand()), 0, 7) . "fraddiegrantshome@web.com ";
200 $this->type("email_1_email", $email);
201 $this->click("Email_1_IsBulkmail");
202
203 //fill in phone
204 $this->type("phone_1_phone", "444-4444");
205 $this->select("phone_1_phone_type_id", "value=" . $this->webtestGetFirstValueForOptionGroup('phone_type'));
206
207 //fill in IM
208 foreach (array('Yahoo', 'MSN', 'AIM', 'GTalk', 'Jabber', 'Skype') as $option) {
209 $this->assertSelectHasOption('im_1_provider_id', $option);
210 }
211 $this->type("im_1_name", "testSkype");
212 $this->select("im_1_location_type_id", "value=3");
213 $this->select("im_1_provider_id", "value=6");
214
215 //fill in openID
216 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "shomeopenid.com");
217
218 //fill in website url
219 $this->type("website_1_url", "http://www.fraddiegrantshome.com");
220
221 //fill in contact source
222 $this->type("contact_source", "Grant's home source");
223
224 //fill in external identifier
225 $houExternalId = substr(sha1(rand()), 0, 4);
226 $this->type("external_identifier", $houExternalId);
227
228 //check for duplicate contact
229 $this->click("_qf_Contact_refresh_dedupe");
230 $this->waitForPageToLoad($this->getTimeoutMsec());
231
232 //address section
233 $this->click("addressBlock");
234 $this->waitForElementPresent("address_1_street_address");
235 $this->type("address_1_street_address", "938U Bay Rd E");
236 $this->type("address_1_city", "Birmingham");
237 $this->type("address_1_postal_code", "35278");
238
239 $this->click("address_1_country_id");
240 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
241
242 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
243 $this->type("address_1_geo_code_1", "1234");
244 $this->type("address_1_geo_code_2", "5678");
245 }
246
247 //Communication Preferences section
248 $this->click("commPrefs");
249
250 //select greeting/addressee options
251 $this->waitForElementPresent("addressee_id");
252 $this->select("addressee_id", "value=4");
253 $this->type("addressee_custom", "Grant's home");
254
255 //Select preferred method(s) of communication
256 $this->click("preferred_communication_method[1]");
257 $this->click("preferred_communication_method[2]");
258 $this->click("preferred_communication_method[5]");
259
260 //Select preferred method for Privacy
261 $this->click("privacy[do_not_sms]");
262
263 //select preferred language
264 $this->waitForElementPresent("preferred_language");
265 $this->select("preferred_language", "value=fr_FR");
266
267 //Notes section
268 $this->clickAt("//*[@id='Contact']/div[2]/div[6]/div[1]");
269 $this->waitForElementPresent("subject");
270 $this->type("subject", "Grant's note");
271 $this->type("note", "This is a household contact webtest note.");
272
273 // select group
274 $this->clickAt("xpath=//div[text()='Tags and Groups']");
275 $this->select("group", "label=$groupName");
276
277 //tags section
278 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
279
280 // Clicking save.
281 $this->click("_qf_Contact_upload_view");
282 $this->waitForPageToLoad($this->getTimeoutMsec());
283
284 $this->waitForText('crm-notification-container', "Contact Saved");
285 }
286
287 public function testOrganizationAdd() {
288 $this->webtestLogin();
289
290 $groupName = $this->WebtestAddGroup();
291
292 // go to display preferences to enable Open ID field
293 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
294 $this->waitForAjaxContent();
295 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
296 $this->click("_qf_Display_next-bottom");
297 $this->waitForPageToLoad($this->getTimeoutMsec());
298
299 $this->openCiviPage('contact/add', 'reset=1&ct=Organization');
300
301 //contact details section
302 //fill in Organization name
303 $this->click("organization_name");
304 $this->type("organization_name", substr(sha1(rand()), 0, 7) . "syntel tech");
305
306 //fill in legal name
307 $this->type("legal_name", "syntel tech Ltd");
308
309 //fill in nick name
310 $this->type("nick_name", "syntel");
311
312 //fill in email
313 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "info@syntel.com");
314
315 //fill in phone
316 $this->type("phone_1_phone", "222-7777");
317 $this->select("phone_1_phone_type_id", "value=2");
318
319 //fill in IM
320 $this->type("im_1_name", "testGtalk");
321 $this->select("im_1_location_type_id", "value=4");
322 $this->select("im_1_provider_id", "value=4");
323
324 //fill in openID
325 $this->select("openid_1_location_type_id", "value=5");
326 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "Openid.com");
327
328 //fill in website url
329 $this->type("website_1_url", "http://syntelglobal.com");
330
331 //fill in contact source
332 $this->type("contact_source", "syntel's source");
333
334 //fill in external identifier
335 $orgExternalId = substr(sha1(rand()), 0, 4);
336 $this->type("external_identifier", $orgExternalId);
337
338 //check for duplicate contact
339 $this->click("_qf_Contact_refresh_dedupe");
340 $this->waitForPageToLoad($this->getTimeoutMsec());
341
342 //address section
343 $this->click("addressBlock");
344 $this->waitForElementPresent("address_1_street_address");
345 $this->type("address_1_street_address", "928A Lincoln Way W");
346 $this->type("address_1_city", "Madison");
347 $this->type("address_1_postal_code", "68748");
348
349 $this->click("address_1_country_id");
350 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
351
352 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
353 $this->type("address_1_geo_code_1", "1234");
354 $this->type("address_1_geo_code_2", "5678");
355 }
356
357 //Communication Preferences section
358 $this->click("commPrefs");
359
360 //Select preferred method(s) of communication
361 $this->click("preferred_communication_method[2]");
362 $this->click("preferred_communication_method[5]");
363
364 //Select preferred method for Privacy
365 $this->click("privacy[do_not_sms]");
366 $this->click("privacy[do_not_mail]");
367 //select preferred language
368 $this->waitForElementPresent("preferred_language");
369 $this->select("preferred_language", "value=de_DE");
370
371 //Notes section
372 $this->click("notesBlock");
373 $this->waitForElementPresent("subject");
374 $this->type("subject", "syntel global note");
375 $this->type("note", "This is a note for syntel global's contact webtest.");
376
377 //Tags and Groups section
378 $this->click("tagGroup");
379
380 // select group
381 $this->select("group", "label=$groupName");
382
383 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
384
385 // Clicking save.
386 $this->click("_qf_Contact_upload_view");
387 $this->waitForPageToLoad($this->getTimeoutMsec());
388
389 $this->waitForText('crm-notification-container', "Contact Saved");
390 }
391
392 public function testIndividualAddWithSharedAddress() {
393 $this->webtestLogin();
394
395 $this->openCiviPage('contact/add', "reset=1&ct=Individual");
396
397 //contact details section
398 //select prefix
399 $this->click("prefix_id");
400 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
401
402 //fill in first name
403 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
404
405 //fill in middle name
406 $this->type("middle_name", "Bruce");
407
408 $lastName = substr(sha1(rand()), 0, 7) . "Smith";
409 //fill in last name
410 $this->type("last_name", $lastName);
411
412 //create new current employer
413 $currentEmployer = substr(sha1(rand()), 0, 7) . "Web Access";
414
415 //fill in email
416 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
417
418 //fill in phone
419 $this->type("phone_1_phone", "2222-4444");
420
421 //fill in source
422 $this->type("contact_source", "johnSource");
423
424 //address section
425 $this->click("addressBlock");
426 $this->waitForElementPresent("address_1_street_address");
427
428 $this->select('address_1_location_type_id', 'value=2');
429
430 $this->click('address[1][use_shared_address]');
431
432 // create new organization with dialog
433 $this->clickAt("xpath=//div[@id='s2id_address_1_master_contact_id']/a");
434 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
435
436 // create new contact using dialog
437 $this->waitForElementPresent("css=div#crm-profile-block");
438 $this->waitForElementPresent("_qf_Edit_next");
439
440 $this->type('organization_name', $currentEmployer);
441 $this->type('street_address-1', '902C El Camino Way SW');
442 $this->type("email-Primary", "john@gmail.com" . substr(sha1(rand()), 0, 7));
443 $this->type('city-1', 'Dumfries');
444 $this->type('postal_code-1', '1234');
445 $this->select('state_province-1', 'value=1001');
446
447 $this->click("_qf_Edit_next");
448
449 $this->select2('employer_id', $currentEmployer);
450
451 //make sure shared address is selected
452 $this->waitForElementPresent('selected_shared_address-1');
453
454 //fill in address 2
455 $this->click("//div[@id='addMoreAddress1']/a/span");
456 $this->waitForElementPresent("address_2_street_address");
457
458 $this->select('address_2_location_type_id', 'value=1');
459
460 $this->click('address[2][use_shared_address]');
461
462 // create new household with dialog
463 $this->clickAt("xpath=//div[@id='s2id_address_2_master_contact_id']/a");
464 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Household')]");
465
466 // create new contact using dialog
467 $this->waitForElementPresent("css=div#crm-profile-block");
468 $this->waitForElementPresent("_qf_Edit_next");
469
470 $sharedHousehold = substr(sha1(rand()), 0, 7) . 'Smith Household';
471 $this->type('household_name', $sharedHousehold);
472 $this->type('street_address-1', '2782Y Dowlen Path W');
473 $this->type("email-Primary", substr(sha1(rand()), 0, 7) . "john@gmail.com");
474 $this->type('city-1', 'Birmingham');
475 $this->type('postal_code-1', '3456');
476 $this->select('state_province-1', 'value=1001');
477
478 $this->click("_qf_Edit_next");
479
480 //make sure shared address is selected
481 $this->waitForElementPresent('selected_shared_address-2');
482
483 // Clicking save.
484 $this->click("_qf_Contact_upload_view");
485 $this->waitForPageToLoad($this->getTimeoutMsec());
486 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
487 $this->waitForText('crm-notification-container', "$name has been created.");
488
489 //make sure current employer is set
490 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div", 'Employer');
491 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div[2]/a[text()]", $currentEmployer);
492
493 //make sure both shared address are set.
494 $this->assertElementContainsText('address-block-1', "Address belongs to $currentEmployer");
495 $this->assertElementContainsText('address-block-2', "Address belongs to $sharedHousehold");
496
497 // make sure relationships are created
498 $this->click("xpath=id('tab_rel')/a");
499 $this->waitForElementPresent('permission-legend');
500 $this->assertElementContainsText('DataTables_Table_0', 'Employee of');
501 $this->assertElementContainsText('DataTables_Table_0', 'Household Member of');
502 }
503
504 public function testContactDeceased() {
505 $this->webtestLogin();
506 $this->waitForPageToLoad($this->getTimeoutMsec());
507 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
508 //contact details section
509 //fill in first name
510 $fname = substr(sha1(rand()), 0, 7) . "John";
511 $lname = substr(sha1(rand()), 0, 7) . "Smith";
512 $this->type("first_name", $fname);
513 //fill in last name
514 $this->type("last_name", $lname);
515 //fill in email
516 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
517 // Clicking save.
518 $this->click("_qf_Contact_upload_view");
519 $this->waitForPageToLoad($this->getTimeoutMsec());
520 $this->waitForText('crm-notification-container', "Contact Saved");
521 //Edit Contact
522 $cid = $this->urlArg('cid');
523 $dname = $fname . ' ' . $lname . ' (deceased)';
524 foreach (array('', 'deceased') as $val) {
525 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$cid}");
526 if ($val) {
527 $this->assertElementContainsText('page-title', 'Edit ' . $dname);
528 }
529 // Click on the Demographics tab
530 $this->click('demographics');
531 $this->waitForElementPresent('is_deceased');
532 $this->click('is_deceased');
533 // Click on Save
534 $this->click('_qf_Contact_upload_view-bottom');
535 $this->waitForPageToLoad($this->getTimeoutMsec());
536 if (!$val) {
537 $this->assertElementContainsText('css=div.crm-summary-display_name', $dname);
538 }
539 else {
540 $this->assertTrue(($this->getText('css=div.crm-summary-display_name') != $dname));
541 }
542 }
543 foreach (array('', 'deceased') as $val) {
544 $this->mouseDown('crm-demographic-content');
545 $this->mouseUp('crm-demographic-content');
546 $this->waitForElementPresent("css=#crm-demographic-content .crm-container-snippet form");
547 $this->click('is_deceased');
548 $this->click("css=#crm-demographic-content input.crm-form-submit");
549 $this->waitForElementPresent("css=#crm-demographic-content > .crm-inline-block-content");
550 if (!$val) {
551 $this->assertElementContainsText('css=div.crm-summary-display_name', $dname);
552 }
553 else {
554 $this->assertTrue(($this->getText('css=div.crm-summary-display_name') != $dname));
555 }
556 }
557 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$cid}");
558 $this->assertTrue(($this->getText('page-title') != $dname));
559 }
560
561 }