3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_AddTest
32 class WebTest_Contact_AddTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testIndividualAdd() {
39 $this->webtestLogin();
41 $groupName = $this->WebtestAddGroup();
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->waitForAjaxContent();
46 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
47 $this->click("_qf_Display_next-bottom");
48 $this->waitForPageToLoad($this->getTimeoutMsec());
49 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
51 //contact details section
53 $this->click("prefix_id");
54 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
57 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
60 $this->type("middle_name", "Bruce");
63 $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith");
66 $this->select("suffix_id", "value=3");
69 $this->type("nick_name", "jsmith");
72 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
75 $this->type("phone_1_phone", "2222-4444");
78 $this->type("im_1_name", "testYahoo");
81 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com");
84 $this->type("website_1_url", "http://www.john.com");
87 $this->type("contact_source", "johnSource");
89 //fill in external identifier
90 $indExternalId = substr(sha1(rand()), 0, 4);
91 $this->type("external_identifier", $indExternalId);
93 //check for matching contact
94 $this->click("_qf_Contact_refresh_dedupe");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
98 $this->click("addressBlock");
99 $this->waitForElementPresent("address_1_street_address");
101 $this->type("address_1_street_address", "902C El Camino Way SW");
102 $this->type("address_1_city", "Dumfries");
103 $this->type("address_1_postal_code", "1234");
105 $this->click("address_1_country_id");
106 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
108 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
109 $this->type("address_1_geo_code_1", "1234");
110 $this->type("address_1_geo_code_2", "5678");
114 $this->click("//div[@id='addMoreAddress1']/a/span");
115 $this->waitForElementPresent("address_2_street_address");
116 $this->type("address_2_street_address", "2782Y Dowlen Path W");
117 $this->type("address_2_city", "Birmingham");
118 $this->type("address_2_postal_code", "3456");
120 $this->click("address_2_country_id");
121 $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID());
123 if ($this->assertElementContainsText('address_table_2', "Latitude")) {
124 $this->type("address_2_geo_code_1", "1234");
125 $this->type("address_2_geo_code_2", "5678");
128 //Communication Preferences section
129 $this->click("commPrefs");
131 //select greeting/addressee options
132 $this->waitForElementPresent("email_greeting_id");
133 $this->select("email_greeting_id", "value=2");
134 $this->select("postal_greeting_id", "value=3");
136 //Select preferred method for Privacy
137 $this->click("privacy[do_not_trade]");
138 $this->click("privacy[do_not_sms]");
140 //Select preferred method(s) of communication
141 $this->click("preferred_communication_method[1]");
142 $this->click("preferred_communication_method[2]");
144 //select preferred language
145 $this->waitForElementPresent("preferred_language");
146 $this->select("preferred_language", "value=en_US");
149 $this->click("notesBlock");
150 $this->waitForElementPresent("subject");
151 $this->type("subject", "test note");
152 $this->type("note", "this is a test note contact webtest");
153 $this->assertElementContainsText('notesBlock', "Subject\n Note");
155 //Demographics section
156 $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]");
157 $this->waitForElementPresent("birth_date");
159 $this->webtestFillDate('birth_date', "-1 year");
161 //Tags and Groups section
162 $this->click("tagGroup");
165 $this->select("group", "label=$groupName");
166 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
169 $this->click("_qf_Contact_upload_view");
171 $this->waitForPageToLoad($this->getTimeoutMsec());
172 $this->waitForText('crm-notification-container', "Contact Saved");
175 public function testHouseholdAdd() {
176 $this->webtestLogin();
178 $groupName = $this->WebtestAddGroup();
180 // go to display preferences to enable Open ID field
181 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
182 $this->waitForAjaxContent();
183 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
184 $this->click("_qf_Display_next-bottom");
185 $this->waitForPageToLoad($this->getTimeoutMsec());
187 $this->openCiviPage('contact/add', "reset=1&ct=Household");
189 //contact details section
190 //fill in Household name
191 $this->click("household_name");
192 $name = substr(sha1(rand()), 0, 7) . "Fraddie Grant's home ";
193 $this->type("household_name", $name);
196 $this->type("nick_name", substr(sha1(rand()), 0, 7) . "Grant's home");
199 $email = substr(sha1(rand()), 0, 7) . "fraddiegrantshome@web.com ";
200 $this->type("email_1_email", $email);
201 $this->click("Email_1_IsBulkmail");
204 $this->type("phone_1_phone", "444-4444");
205 $this->select("phone_1_phone_type_id", "value=" . $this->webtestGetFirstValueForOptionGroup('phone_type'));
208 foreach (array('Yahoo', 'MSN', 'AIM', 'GTalk', 'Jabber', 'Skype') as $option) {
209 $this->assertSelectHasOption('im_1_provider_id', $option);
211 $this->type("im_1_name", "testSkype");
212 $this->select("im_1_location_type_id", "value=3");
213 $this->select("im_1_provider_id", "value=6");
216 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "shomeopenid.com");
218 //fill in website url
219 $this->type("website_1_url", "http://www.fraddiegrantshome.com");
221 //fill in contact source
222 $this->type("contact_source", "Grant's home source");
224 //fill in external identifier
225 $houExternalId = substr(sha1(rand()), 0, 4);
226 $this->type("external_identifier", $houExternalId);
228 //check for duplicate contact
229 $this->click("_qf_Contact_refresh_dedupe");
230 $this->waitForPageToLoad($this->getTimeoutMsec());
233 $this->click("addressBlock");
234 $this->waitForElementPresent("address_1_street_address");
235 $this->type("address_1_street_address", "938U Bay Rd E");
236 $this->type("address_1_city", "Birmingham");
237 $this->type("address_1_postal_code", "35278");
239 $this->click("address_1_country_id");
240 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
242 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
243 $this->type("address_1_geo_code_1", "1234");
244 $this->type("address_1_geo_code_2", "5678");
247 //Communication Preferences section
248 $this->click("commPrefs");
250 //select greeting/addressee options
251 $this->waitForElementPresent("addressee_id");
252 $this->select("addressee_id", "value=4");
253 $this->type("addressee_custom", "Grant's home");
255 //Select preferred method(s) of communication
256 $this->click("preferred_communication_method[1]");
257 $this->click("preferred_communication_method[2]");
258 $this->click("preferred_communication_method[5]");
260 //Select preferred method for Privacy
261 $this->click("privacy[do_not_sms]");
263 //select preferred language
264 $this->waitForElementPresent("preferred_language");
265 $this->select("preferred_language", "value=fr_FR");
268 $this->clickAt("//*[@id='Contact']/div[2]/div[6]/div[1]");
269 $this->waitForElementPresent("subject");
270 $this->type("subject", "Grant's note");
271 $this->type("note", "This is a household contact webtest note.");
274 $this->clickAt("xpath=//div[text()='Tags and Groups']");
275 $this->select("group", "label=$groupName");
278 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
281 $this->click("_qf_Contact_upload_view");
282 $this->waitForPageToLoad($this->getTimeoutMsec());
284 $this->waitForText('crm-notification-container', "Contact Saved");
287 public function testOrganizationAdd() {
288 $this->webtestLogin();
290 $groupName = $this->WebtestAddGroup();
292 // go to display preferences to enable Open ID field
293 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
294 $this->waitForAjaxContent();
295 $this->click("xpath=//ul[@id='contactEditBlocks']//li/span/label[text()='Open ID']");
296 $this->click("_qf_Display_next-bottom");
297 $this->waitForPageToLoad($this->getTimeoutMsec());
299 $this->openCiviPage('contact/add', 'reset=1&ct=Organization');
301 //contact details section
302 //fill in Organization name
303 $this->click("organization_name");
304 $this->type("organization_name", substr(sha1(rand()), 0, 7) . "syntel tech");
307 $this->type("legal_name", "syntel tech Ltd");
310 $this->type("nick_name", "syntel");
313 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "info@syntel.com");
316 $this->type("phone_1_phone", "222-7777");
317 $this->select("phone_1_phone_type_id", "value=2");
320 $this->type("im_1_name", "testGtalk");
321 $this->select("im_1_location_type_id", "value=4");
322 $this->select("im_1_provider_id", "value=4");
325 $this->select("openid_1_location_type_id", "value=5");
326 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "Openid.com");
328 //fill in website url
329 $this->type("website_1_url", "http://syntelglobal.com");
331 //fill in contact source
332 $this->type("contact_source", "syntel's source");
334 //fill in external identifier
335 $orgExternalId = substr(sha1(rand()), 0, 4);
336 $this->type("external_identifier", $orgExternalId);
338 //check for duplicate contact
339 $this->click("_qf_Contact_refresh_dedupe");
340 $this->waitForPageToLoad($this->getTimeoutMsec());
343 $this->click("addressBlock");
344 $this->waitForElementPresent("address_1_street_address");
345 $this->type("address_1_street_address", "928A Lincoln Way W");
346 $this->type("address_1_city", "Madison");
347 $this->type("address_1_postal_code", "68748");
349 $this->click("address_1_country_id");
350 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
352 if ($this->assertElementContainsText('address_table_1', "Latitude")) {
353 $this->type("address_1_geo_code_1", "1234");
354 $this->type("address_1_geo_code_2", "5678");
357 //Communication Preferences section
358 $this->click("commPrefs");
360 //Select preferred method(s) of communication
361 $this->click("preferred_communication_method[2]");
362 $this->click("preferred_communication_method[5]");
364 //Select preferred method for Privacy
365 $this->click("privacy[do_not_sms]");
366 $this->click("privacy[do_not_mail]");
367 //select preferred language
368 $this->waitForElementPresent("preferred_language");
369 $this->select("preferred_language", "value=de_DE");
372 $this->click("notesBlock");
373 $this->waitForElementPresent("subject");
374 $this->type("subject", "syntel global note");
375 $this->type("note", "This is a note for syntel global's contact webtest.");
377 //Tags and Groups section
378 $this->click("tagGroup");
381 $this->select("group", "label=$groupName");
383 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
386 $this->click("_qf_Contact_upload_view");
387 $this->waitForPageToLoad($this->getTimeoutMsec());
389 $this->waitForText('crm-notification-container', "Contact Saved");
392 public function testIndividualAddWithSharedAddress() {
393 $this->webtestLogin();
395 $this->openCiviPage('contact/add', "reset=1&ct=Individual");
397 //contact details section
399 $this->click("prefix_id");
400 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
403 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
405 //fill in middle name
406 $this->type("middle_name", "Bruce");
408 $lastName = substr(sha1(rand()), 0, 7) . "Smith";
410 $this->type("last_name", $lastName);
412 //create new current employer
413 $currentEmployer = substr(sha1(rand()), 0, 7) . "Web Access";
416 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
419 $this->type("phone_1_phone", "2222-4444");
422 $this->type("contact_source", "johnSource");
425 $this->click("addressBlock");
426 $this->waitForElementPresent("address_1_street_address");
428 $this->select('address_1_location_type_id', 'value=2');
430 $this->click('address[1][use_shared_address]');
432 // create new organization with dialog
433 $this->clickAt("xpath=//div[@id='s2id_address_1_master_contact_id']/a");
434 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
436 // create new contact using dialog
437 $this->waitForElementPresent("css=div#crm-profile-block");
438 $this->waitForElementPresent("_qf_Edit_next");
440 $this->type('organization_name', $currentEmployer);
441 $this->type('street_address-1', '902C El Camino Way SW');
442 $this->type("email-Primary", "john@gmail.com" . substr(sha1(rand()), 0, 7));
443 $this->type('city-1', 'Dumfries');
444 $this->type('postal_code-1', '1234');
445 $this->select('state_province-1', 'value=1001');
447 $this->click("_qf_Edit_next");
449 $this->select2('employer_id', $currentEmployer);
451 //make sure shared address is selected
452 $this->waitForElementPresent('selected_shared_address-1');
455 $this->click("//div[@id='addMoreAddress1']/a/span");
456 $this->waitForElementPresent("address_2_street_address");
458 $this->select('address_2_location_type_id', 'value=1');
460 $this->click('address[2][use_shared_address]');
462 // create new household with dialog
463 $this->clickAt("xpath=//div[@id='s2id_address_2_master_contact_id']/a");
464 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Household')]");
466 // create new contact using dialog
467 $this->waitForElementPresent("css=div#crm-profile-block");
468 $this->waitForElementPresent("_qf_Edit_next");
470 $sharedHousehold = substr(sha1(rand()), 0, 7) . 'Smith Household';
471 $this->type('household_name', $sharedHousehold);
472 $this->type('street_address-1', '2782Y Dowlen Path W');
473 $this->type("email-Primary", substr(sha1(rand()), 0, 7) . "john@gmail.com");
474 $this->type('city-1', 'Birmingham');
475 $this->type('postal_code-1', '3456');
476 $this->select('state_province-1', 'value=1001');
478 $this->click("_qf_Edit_next");
480 //make sure shared address is selected
481 $this->waitForElementPresent('selected_shared_address-2');
484 $this->click("_qf_Contact_upload_view");
485 $this->waitForPageToLoad($this->getTimeoutMsec());
486 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
487 $this->waitForText('crm-notification-container', "$name has been created.");
489 //make sure current employer is set
490 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div", 'Employer');
491 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div[2]/a[text()]", $currentEmployer);
493 //make sure both shared address are set.
494 $this->assertElementContainsText('address-block-1', "Address belongs to $currentEmployer");
495 $this->assertElementContainsText('address-block-2', "Address belongs to $sharedHousehold");
497 // make sure relationships are created
498 $this->click("xpath=id('tab_rel')/a");
499 $this->waitForElementPresent('permission-legend');
500 $this->assertElementContainsText('DataTables_Table_0', 'Employee of');
501 $this->assertElementContainsText('DataTables_Table_0', 'Household Member of');
504 public function testContactDeceased() {
505 $this->webtestLogin();
506 $this->waitForPageToLoad($this->getTimeoutMsec());
507 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
508 //contact details section
510 $fname = substr(sha1(rand()), 0, 7) . "John";
511 $lname = substr(sha1(rand()), 0, 7) . "Smith";
512 $this->type("first_name", $fname);
514 $this->type("last_name", $lname);
516 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
518 $this->click("_qf_Contact_upload_view");
519 $this->waitForPageToLoad($this->getTimeoutMsec());
520 $this->waitForText('crm-notification-container', "Contact Saved");
522 $cid = $this->urlArg('cid');
523 $dname = $fname . ' ' . $lname . ' (deceased)';
524 foreach (array('', 'deceased') as $val) {
525 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$cid}");
527 $this->assertElementContainsText('page-title', 'Edit ' . $dname);
529 // Click on the Demographics tab
530 $this->click('demographics');
531 $this->waitForElementPresent('is_deceased');
532 $this->click('is_deceased');
534 $this->click('_qf_Contact_upload_view-bottom');
535 $this->waitForPageToLoad($this->getTimeoutMsec());
537 $this->assertElementContainsText('css=div.crm-summary-display_name', $dname);
540 $this->assertTrue(($this->getText('css=div.crm-summary-display_name') != $dname));
543 foreach (array('', 'deceased') as $val) {
544 $this->mouseDown('crm-demographic-content');
545 $this->mouseUp('crm-demographic-content');
546 $this->waitForElementPresent("css=#crm-demographic-content .crm-container-snippet form");
547 $this->click('is_deceased');
548 $this->click("css=#crm-demographic-content input.crm-form-submit");
549 $this->waitForElementPresent("css=#crm-demographic-content > .crm-inline-block-content");
551 $this->assertElementContainsText('css=div.crm-summary-display_name', $dname);
554 $this->assertTrue(($this->getText('css=div.crm-summary-display_name') != $dname));
557 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$cid}");
558 $this->assertTrue(($this->getText('page-title') != $dname));