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