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