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';
28 class WebTest_Contact_AddTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testIndividualAdd() {
35 $this->webtestLogin();
37 $groupName = $this->WebtestAddGroup();
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');
46 //contact details section
48 $this->click("prefix_id");
49 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
52 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
55 $this->type("middle_name", "Bruce");
58 $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith");
61 $this->select("suffix_id", "value=3");
64 $this->type("nick_name", "jsmith");
67 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
70 $this->type("phone_1_phone", "2222-4444");
73 $this->type("im_1_name", "testYahoo");
76 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com");
79 $this->type("website_1_url", "http://www.john.com");
82 $this->type("contact_source", "johnSource");
84 //fill in external identifier
85 $indExternalId = substr(sha1(rand()), 0, 4);
86 $this->type("external_identifier", $indExternalId);
88 //check for matching contact
89 $this->click("_qf_Contact_refresh_dedupe");
90 $this->waitForPageToLoad($this->getTimeoutMsec());
93 $this->click("addressBlock");
94 $this->waitForElementPresent("address_1_street_address");
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");
100 $this->click("address_1_country_id");
101 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
103 if ($this->assertElementContainsText('address_1', "Latitude")) {
104 $this->type("address_1_geo_code_1", "1234");
105 $this->type("address_1_geo_code_2", "5678");
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");
115 $this->click("address_2_country_id");
116 $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID());
118 if ($this->assertElementContainsText('address_2', "Latitude")) {
119 $this->type("address_2_geo_code_1", "1234");
120 $this->type("address_2_geo_code_2", "5678");
123 //Communication Preferences section
124 $this->click("commPrefs");
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");
131 //Select preferred method for Privacy
132 $this->click("privacy[do_not_trade]");
133 $this->click("privacy[do_not_sms]");
135 //Select preferred method(s) of communication
136 $this->click("preferred_communication_method[1]");
137 $this->click("preferred_communication_method[2]");
139 //select preferred language
140 $this->waitForElementPresent("preferred_language");
141 $this->select("preferred_language", "value=en_US");
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");
148 $this->assertElementContainsText('notesBlock', "Subject\n Notes");
150 //Demographics section
151 $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]");
152 $this->waitForElementPresent("birth_date");
154 $this->webtestFillDate('birth_date', "-1 year");
156 //Tags and Groups section
157 $this->click("tagGroup");
160 $this->select("group", "label=$groupName");
161 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
164 $this->click("_qf_Contact_upload_view");
166 $this->waitForPageToLoad($this->getTimeoutMsec());
167 $this->waitForText('crm-notification-container', "Contact Saved");
170 function testHouseholdAdd() {
171 $this->webtestLogin();
173 $groupName = $this->WebtestAddGroup();
175 // go to display preferences to enable Open ID field
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());
181 $this->openCiviPage('contact/add', "reset=1&ct=Household");
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);
190 $this->type("nick_name", substr(sha1(rand()), 0, 7) . "Grant's home");
193 $email = substr(sha1(rand()), 0, 7) . "fraddiegrantshome@web.com ";
194 $this->type("email_1_email", $email);
195 $this->click("Email_1_IsBulkmail");
198 $this->type("phone_1_phone", "444-4444");
199 $this->select("phone_1_phone_type_id", "value=" . $this->webtestGetFirstValueForOptionGroup('phone_type'));
202 $this->assertElementContainsText('im_1_provider_id', "Yahoo MSN AIM GTalk Jabber Skype");
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");
208 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "shomeopenid.com");
210 //fill in website url
211 $this->type("website_1_url", "http://www.fraddiegrantshome.com");
213 //fill in contact source
214 $this->type("contact_source", "Grant's home source");
216 //fill in external identifier
217 $houExternalId = substr(sha1(rand()), 0, 4);
218 $this->type("external_identifier", $houExternalId);
220 //check for duplicate contact
221 $this->click("_qf_Contact_refresh_dedupe");
222 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
231 $this->click("address_1_country_id");
232 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
234 if ($this->assertElementContainsText('address_1', "Latitude")) {
235 $this->type("address_1_geo_code_1", "1234");
236 $this->type("address_1_geo_code_2", "5678");
239 //Communication Preferences section
240 $this->click("commPrefs");
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");
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]");
252 //Select preferred method for Privacy
253 $this->click("privacy[do_not_sms]");
255 //select preferred language
256 $this->waitForElementPresent("preferred_language");
257 $this->select("preferred_language", "value=fr_FR");
260 $this->clickAt("//*[@id='Contact']/div[2]/div[6]/div[1]");
261 $this->waitForElementPresent("subject");
262 $this->type("subject", "Grant's note");
263 $this->type("note", "This is a household contact webtest note.");
266 $this->clickAt("xpath=//div[text()='Tags and Groups']");
267 $this->select("group", "label=$groupName");
270 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
273 $this->click("_qf_Contact_upload_view");
274 $this->waitForPageToLoad($this->getTimeoutMsec());
276 $this->waitForText('crm-notification-container', "Contact Saved");
279 function testOrganizationAdd() {
280 $this->webtestLogin();
282 $groupName = $this->WebtestAddGroup();
284 // go to display preferences to enable Open ID field
285 $this->openCiviPage('admin/setting/preferences/display', "reset=1", "_qf_Display_next-bottom");
286 $this->check("xpath=//ul[@id='contactEditBlocks']//li/span[2]/label[text()='Open ID']/../input");
287 $this->click("_qf_Display_next-bottom");
288 $this->waitForPageToLoad($this->getTimeoutMsec());
290 $this->openCiviPage('contact/add', 'reset=1&ct=Organization');
292 //contact details section
293 //fill in Organization name
294 $this->click("organization_name");
295 $this->type("organization_name", substr(sha1(rand()), 0, 7) . "syntel tech");
298 $this->type("legal_name", "syntel tech Ltd");
301 $this->type("nick_name", "syntel");
304 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "info@syntel.com");
307 $this->type("phone_1_phone", "222-7777");
308 $this->select("phone_1_phone_type_id", "value=2");
311 $this->type("im_1_name", "testGtalk");
312 $this->select("im_1_location_type_id", "value=4");
313 $this->select("im_1_provider_id", "value=4");
316 $this->select("openid_1_location_type_id", "value=5");
317 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "Openid.com");
319 //fill in website url
320 $this->type("website_1_url", "http://syntelglobal.com");
322 //fill in contact source
323 $this->type("contact_source", "syntel's source");
325 //fill in external identifier
326 $orgExternalId = substr(sha1(rand()), 0, 4);
327 $this->type("external_identifier", $orgExternalId);
329 //check for duplicate contact
330 $this->click("_qf_Contact_refresh_dedupe");
331 $this->waitForPageToLoad($this->getTimeoutMsec());
334 $this->click("addressBlock");
335 $this->waitForElementPresent("address_1_street_address");
336 $this->type("address_1_street_address", "928A Lincoln Way W");
337 $this->type("address_1_city", "Madison");
338 $this->type("address_1_postal_code", "68748");
340 $this->click("address_1_country_id");
341 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
343 if ($this->assertElementContainsText('address_1', "Latitude")) {
344 $this->type("address_1_geo_code_1", "1234");
345 $this->type("address_1_geo_code_2", "5678");
348 //Communication Preferences section
349 $this->click("commPrefs");
351 //Select preferred method(s) of communication
352 $this->click("preferred_communication_method[2]");
353 $this->click("preferred_communication_method[5]");
355 //Select preferred method for Privacy
356 $this->click("privacy[do_not_sms]");
357 $this->click("privacy[do_not_mail]");
358 //select preferred language
359 $this->waitForElementPresent("preferred_language");
360 $this->select("preferred_language", "value=de_DE");
363 $this->click("notesBlock");
364 $this->waitForElementPresent("subject");
365 $this->type("subject", "syntel global note");
366 $this->type("note", "This is a note for syntel global's contact webtest.");
368 //Tags and Groups section
369 $this->click("tagGroup");
372 $this->select("group", "label=$groupName");
374 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
377 $this->click("_qf_Contact_upload_view");
378 $this->waitForPageToLoad($this->getTimeoutMsec());
380 $this->waitForText('crm-notification-container', "Contact Saved");
383 function testIndividualAddWithSharedAddress() {
384 $this->webtestLogin();
386 $this->openCiviPage('contact/add', "reset=1&ct=Individual");
388 //contact details section
390 $this->click("prefix_id");
391 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
394 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
396 //fill in middle name
397 $this->type("middle_name", "Bruce");
399 $lastName = substr(sha1(rand()), 0, 7) . "Smith";
401 $this->type("last_name", $lastName);
403 //create new current employer
404 $currentEmployer = substr(sha1(rand()), 0, 7) . "Web Access";
406 $this->type('current_employer', $currentEmployer);
409 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
412 $this->type("phone_1_phone", "2222-4444");
415 $this->type("contact_source", "johnSource");
418 $this->click("addressBlock");
419 $this->waitForElementPresent("address_1_street_address");
421 $this->select('address_1_location_type_id', 'value=2');
423 $this->click('address[1][use_shared_address]');
425 // create new organization with dialog
426 $this->select("profiles_1", "label=New Organization");
428 // create new contact using dialog
429 $this->waitForElementPresent("css=div#contact-dialog-1");
430 $this->waitForElementPresent("_qf_Edit_next");
432 $this->type('organization_name', $currentEmployer);
433 $this->type('street_address-1', '902C El Camino Way SW');
434 $this->type("email-Primary", "john@gmail.com" . substr(sha1(rand()), 0, 7));
435 $this->type('city-1', 'Dumfries');
436 $this->type('postal_code-1', '1234');
438 $this->click("_qf_Edit_next");
440 // Is new contact created?
441 $this->waitForText('crm-notification-container', "$currentEmployer has been created.");
443 //make sure shared address is selected
444 $this->waitForElementPresent('selected_shared_address-1');
447 $this->click("//div[@id='addMoreAddress1']/a/span");
448 $this->waitForElementPresent("address_2_street_address");
450 $this->select('address_2_location_type_id', 'value=1');
452 $this->click('address[2][use_shared_address]');
454 // create new household with dialog
455 $this->select('profiles_2', "label=New Household");
457 // create new contact using dialog
458 $this->waitForElementPresent("css=div#contact-dialog-2");
459 $this->waitForElementPresent("_qf_Edit_next");
461 $sharedHousehold = substr(sha1(rand()), 0, 7) . 'Smith Household';
462 $this->type('household_name', $sharedHousehold);
463 $this->type('street_address-1', '2782Y Dowlen Path W');
464 $this->type("email-Primary", substr(sha1(rand()), 0, 7) . "john@gmail.com");
465 $this->type('city-1', 'Birmingham');
466 $this->type('postal_code-1', '3456');
468 $this->click("_qf_Edit_next");
470 // Is new contact created?
471 $this->waitForText('crm-notification-container', "$sharedHousehold has been created.");
473 //make sure shared address is selected
474 $this->waitForElementPresent('selected_shared_address-2');
477 $this->click("_qf_Contact_upload_view");
478 $this->waitForPageToLoad($this->getTimeoutMsec());
479 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
480 $this->waitForText('crm-notification-container', "$name has been created.");
482 //make sure current employer is set
483 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div", 'Employer');
484 $this->verifyText("xpath=id('contactinfo-block')/div/div/div[2]/div[2]/a[text()]", $currentEmployer);
486 //make sure both shared address are set.
487 $this->assertElementContainsText('address-block-1', "Address belongs to $currentEmployer");
488 $this->assertElementContainsText('address-block-2', "Address belongs to $sharedHousehold");
490 // make sure relationships are created
491 $this->click("xpath=id('tab_rel')/a");
492 $this->waitForElementPresent('permission-legend');
493 $this->assertElementContainsText('option11', 'Employee of');
494 $this->assertElementContainsText('option11', 'Household Member of');