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