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