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