3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 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->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');
50 //contact details section
52 $this->click("prefix_id");
53 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
56 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
59 $this->type("middle_name", "Bruce");
62 $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith");
65 $this->select("suffix_id", "value=3");
68 $this->type("nick_name", "jsmith");
71 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
74 $this->type("phone_1_phone", "2222-4444");
77 $this->type("im_1_name", "testYahoo");
80 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com");
83 $this->type("website_1_url", "http://www.john.com");
86 $this->type("contact_source", "johnSource");
88 //fill in external identifier
89 $indExternalId = substr(sha1(rand()), 0, 4);
90 $this->type("external_identifier", $indExternalId);
92 //check for matching contact
93 $this->click("_qf_Contact_refresh_dedupe");
94 $this->waitForPageToLoad($this->getTimeoutMsec());
97 $this->click("addressBlock");
98 $this->waitForElementPresent("address_1_street_address");
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");
104 $this->click("address_1_country_id");
105 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
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");
119 $this->click("address_2_country_id");
120 $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID());
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");
127 //Communication Preferences section
128 $this->click("commPrefs");
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");
135 //Select preferred method for Privacy
136 $this->click("privacy[do_not_trade]");
137 $this->click("privacy[do_not_sms]");
139 //Select preferred method(s) of communication
140 $this->click("preferred_communication_method[1]");
141 $this->click("preferred_communication_method[2]");
143 //select preferred language
144 $this->waitForElementPresent("preferred_language");
145 $this->select("preferred_language", "value=en_US");
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");
154 //Demographics section
155 $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]");
156 $this->waitForElementPresent("birth_date");
158 $this->webtestFillDate('birth_date', "-1 year");
160 //Tags and Groups section
161 $this->click("tagGroup");
164 $this->select("group", "label=$groupName");
165 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
168 $this->click("_qf_Contact_upload_view");
170 $this->waitForPageToLoad($this->getTimeoutMsec());
171 $this->waitForText('crm-notification-container', "Contact Saved");
174 function testHouseholdAdd() {
175 $this->webtestLogin();
177 $groupName = $this->WebtestAddGroup();
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());
185 $this->openCiviPage('contact/add', "reset=1&ct=Household");
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);
194 $this->type("nick_name", substr(sha1(rand()), 0, 7) . "Grant's home");
197 $email = substr(sha1(rand()), 0, 7) . "fraddiegrantshome@web.com ";
198 $this->type("email_1_email", $email);
199 $this->click("Email_1_IsBulkmail");
202 $this->type("phone_1_phone", "444-4444");
203 $this->select("phone_1_phone_type_id", "value=" . $this->webtestGetFirstValueForOptionGroup('phone_type'));
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");
212 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "shomeopenid.com");
214 //fill in website url
215 $this->type("website_1_url", "http://www.fraddiegrantshome.com");
217 //fill in contact source
218 $this->type("contact_source", "Grant's home source");
220 //fill in external identifier
221 $houExternalId = substr(sha1(rand()), 0, 4);
222 $this->type("external_identifier", $houExternalId);
224 //check for duplicate contact
225 $this->click("_qf_Contact_refresh_dedupe");
226 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
235 $this->click("address_1_country_id");
236 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
243 //Communication Preferences section
244 $this->click("commPrefs");
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");
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]");
256 //Select preferred method for Privacy
257 $this->click("privacy[do_not_sms]");
259 //select preferred language
260 $this->waitForElementPresent("preferred_language");
261 $this->select("preferred_language", "value=fr_FR");
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.");
270 $this->clickAt("xpath=//div[text()='Tags and Groups']");
271 $this->select("group", "label=$groupName");
274 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
277 $this->click("_qf_Contact_upload_view");
278 $this->waitForPageToLoad($this->getTimeoutMsec());
280 $this->waitForText('crm-notification-container', "Contact Saved");
283 function testOrganizationAdd() {
284 $this->webtestLogin();
286 $groupName = $this->WebtestAddGroup();
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());
294 $this->openCiviPage('contact/add', 'reset=1&ct=Organization');
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");
302 $this->type("legal_name", "syntel tech Ltd");
305 $this->type("nick_name", "syntel");
308 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "info@syntel.com");
311 $this->type("phone_1_phone", "222-7777");
312 $this->select("phone_1_phone_type_id", "value=2");
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");
320 $this->select("openid_1_location_type_id", "value=5");
321 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "Openid.com");
323 //fill in website url
324 $this->type("website_1_url", "http://syntelglobal.com");
326 //fill in contact source
327 $this->type("contact_source", "syntel's source");
329 //fill in external identifier
330 $orgExternalId = substr(sha1(rand()), 0, 4);
331 $this->type("external_identifier", $orgExternalId);
333 //check for duplicate contact
334 $this->click("_qf_Contact_refresh_dedupe");
335 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
344 $this->click("address_1_country_id");
345 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
352 //Communication Preferences section
353 $this->click("commPrefs");
355 //Select preferred method(s) of communication
356 $this->click("preferred_communication_method[2]");
357 $this->click("preferred_communication_method[5]");
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");
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.");
372 //Tags and Groups section
373 $this->click("tagGroup");
376 $this->select("group", "label=$groupName");
378 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
381 $this->click("_qf_Contact_upload_view");
382 $this->waitForPageToLoad($this->getTimeoutMsec());
384 $this->waitForText('crm-notification-container', "Contact Saved");
387 function testIndividualAddWithSharedAddress() {
388 $this->webtestLogin();
390 $this->openCiviPage('contact/add', "reset=1&ct=Individual");
392 //contact details section
394 $this->click("prefix_id");
395 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
398 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
400 //fill in middle name
401 $this->type("middle_name", "Bruce");
403 $lastName = substr(sha1(rand()), 0, 7) . "Smith";
405 $this->type("last_name", $lastName);
407 //create new current employer
408 $currentEmployer = substr(sha1(rand()), 0, 7) . "Web Access";
412 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
415 $this->type("phone_1_phone", "2222-4444");
418 $this->type("contact_source", "johnSource");
421 $this->click("addressBlock");
422 $this->waitForElementPresent("address_1_street_address");
424 $this->select('address_1_location_type_id', 'value=2');
426 $this->click('address[1][use_shared_address]');
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')]");
432 // create new contact using dialog
433 $this->waitForElementPresent("css=div#crm-profile-block");
434 $this->waitForElementPresent("_qf_Edit_next");
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');
443 $this->click("_qf_Edit_next");
445 // Is new contact created?
446 $this->waitForText('crm-notification-container', "$currentEmployer has been created.");
447 $this->select2('employer_id', $currentEmployer);
449 //make sure shared address is selected
450 $this->waitForElementPresent('selected_shared_address-1');
453 $this->click("//div[@id='addMoreAddress1']/a/span");
454 $this->waitForElementPresent("address_2_street_address");
456 $this->select('address_2_location_type_id', 'value=1');
458 $this->click('address[2][use_shared_address]');
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')]");
464 // create new contact using dialog
465 $this->waitForElementPresent("css=div#crm-profile-block");
466 $this->waitForElementPresent("_qf_Edit_next");
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');
476 $this->click("_qf_Edit_next");
478 // Is new contact created?
479 $this->waitForText('crm-notification-container', "$sharedHousehold has been created.");
481 //make sure shared address is selected
482 $this->waitForElementPresent('selected_shared_address-2');
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.");
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);
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");
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');