3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_AddTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testIndividualAdd() {
36 $this->webtestLogin();
38 // Go directly to the URL of the screen that you will be testing (New Individual).
39 $this->WebtestAddGroup();
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');
48 //contact details section
50 $this->click("prefix_id");
51 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
54 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
57 $this->type("middle_name", "Bruce");
60 $this->type("last_name", substr(sha1(rand()), 0, 7) . "Smith");
63 $this->select("suffix_id", "value=3");
66 $this->type("nick_name", "jsmith");
69 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
72 $this->type("phone_1_phone", "2222-4444");
75 $this->type("im_1_name", "testYahoo");
78 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "openid.com");
81 $this->type("website_1_url", "http://www.john.com");
84 $this->type("contact_source", "johnSource");
86 //fill in external identifier
87 $indExternalId = substr(sha1(rand()), 0, 4);
88 $this->type("external_identifier", $indExternalId);
90 //check for matching contact
91 $this->click("_qf_Contact_refresh_dedupe");
92 $this->waitForPageToLoad($this->getTimeoutMsec());
95 $this->click("addressBlock");
96 $this->waitForElementPresent("address_1_street_address");
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");
102 $this->click("address_1_country_id");
103 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
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");
117 $this->click("address_2_country_id");
118 $this->select("address_2_country_id", "value=" . $this->webtestGetValidCountryID());
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");
125 //Communication Preferences section
126 $this->click("commPrefs");
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");
133 //Select preferred method for Privacy
134 $this->click("privacy[do_not_trade]");
135 $this->click("privacy[do_not_sms]");
137 //Select preferred method(s) of communication
138 $this->click("preferred_communication_method[1]");
139 $this->click("preferred_communication_method[2]");
141 //select preferred language
142 $this->waitForElementPresent("preferred_language");
143 $this->select("preferred_language", "value=en_US");
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");
152 //Demographics section
153 $this->click("//div[@class='crm-accordion-header' and contains(.,'Demographics')]");
154 $this->waitForElementPresent("birth_date");
156 $this->webtestFillDate('birth_date', "-1 year");
158 //Tags and Groups section
159 $this->click("tagGroup");
161 $this->click("group[{$this->webtestGetValidEntityID('Group')}]");
162 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
165 $this->click("_qf_Contact_upload_view");
167 $this->waitForPageToLoad($this->getTimeoutMsec());
168 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
171 function testHouseholdAdd() {
172 $this->webtestLogin();
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());
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");
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'));
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");
209 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "shomeopenid.com");
211 //fill in website url
212 $this->type("website_1_url", "http://www.fraddiegrantshome.com");
214 //fill in contact source
215 $this->type("contact_source", "Grant's home source");
217 //fill in external identifier
218 $houExternalId = substr(sha1(rand()), 0, 4);
219 $this->type("external_identifier", $houExternalId);
221 //check for duplicate contact
222 $this->click("_qf_Contact_refresh_dedupe");
223 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
232 $this->click("address_1_country_id");
233 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
240 //Communication Preferences section
241 $this->click("commPrefs");
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");
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]");
253 //Select preferred method for Privacy
254 $this->click("privacy[do_not_sms]");
256 //select preferred language
257 $this->waitForElementPresent("preferred_language");
258 $this->select("preferred_language", "value=fr_FR");
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.");
267 //Tags and Groups section
268 $this->click("group[{$this->webtestGetValidEntityID('Group')}]");
269 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
272 $this->click("_qf_Contact_upload_view");
273 $this->waitForPageToLoad($this->getTimeoutMsec());
275 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
278 function testOrganizationAdd() {
279 $this->webtestLogin();
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');
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");
295 $this->type("legal_name", "syntel tech Ltd");
298 $this->type("nick_name", "syntel");
301 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "info@syntel.com");
304 $this->type("phone_1_phone", "222-7777");
305 $this->select("phone_1_phone_type_id", "value=2");
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");
313 $this->select("openid_1_location_type_id", "value=5");
314 $this->type("openid_1_openid", "http://" . substr(sha1(rand()), 0, 7) . "Openid.com");
316 //fill in website url
317 $this->type("website_1_url", "http://syntelglobal.com");
319 //fill in contact source
320 $this->type("contact_source", "syntel's source");
322 //fill in external identifier
323 $orgExternalId = substr(sha1(rand()), 0, 4);
324 $this->type("external_identifier", $orgExternalId);
326 //check for duplicate contact
327 $this->click("_qf_Contact_refresh_dedupe");
328 $this->waitForPageToLoad($this->getTimeoutMsec());
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");
337 $this->click("address_1_country_id");
338 $this->select("address_1_country_id", "value=" . $this->webtestGetValidCountryID());
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");
345 //Communication Preferences section
346 $this->click("commPrefs");
348 //Select preferred method(s) of communication
349 $this->click("preferred_communication_method[2]");
350 $this->click("preferred_communication_method[5]");
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");
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.");
365 //Tags and Groups section
366 $this->click("tagGroup");
367 $this->click("group[{$this->webtestGetValidEntityID('Group')}]");
368 $this->click("tag[{$this->webtestGetValidEntityID('Tag')}]");
371 $this->click("_qf_Contact_upload_view");
372 $this->waitForPageToLoad($this->getTimeoutMsec());
374 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
377 function testIndividualAddWithSharedAddress() {
378 $this->webtestLogin();
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");
383 //contact details section
385 $this->click("prefix_id");
386 $this->select("prefix_id", "value=" . $this->webtestGetFirstValueForOptionGroup('individual_prefix'));
389 $this->type("first_name", substr(sha1(rand()), 0, 7) . "John");
391 //fill in middle name
392 $this->type("middle_name", "Bruce");
394 $lastName = substr(sha1(rand()), 0, 7) . "Smith";
396 $this->type("last_name", $lastName);
398 //create new current employer
399 $currentEmployer = substr(sha1(rand()), 0, 7) . "Web Access";
401 $this->type('current_employer', $currentEmployer);
404 $this->type("email_1_email", substr(sha1(rand()), 0, 7) . "john@gmail.com");
407 $this->type("phone_1_phone", "2222-4444");
410 $this->type("contact_source", "johnSource");
413 $this->click("addressBlock");
414 $this->waitForElementPresent("address_1_street_address");
416 $this->select('address_1_location_type_id', 'value=2');
418 $this->click('address[1][use_shared_address]');
420 // create new organization with dialog
421 $this->select("profiles_1", "label=New Organization");
423 // create new contact using dialog
424 $this->waitForElementPresent("css=div#contact-dialog-1");
425 $this->waitForElementPresent("_qf_Edit_next");
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');
433 $this->click("_qf_Edit_next");
435 // Is new contact created?
436 $this->assertElementContainsText('crm-notification-container', "$currentEmployer has been created.",
437 "Status message didn't show up after saving!"
440 //make sure shared address is selected
441 $this->waitForElementPresent('selected_shared_address-1');
444 $this->click("//div[@id='addMoreAddress1']/a/span");
445 $this->waitForElementPresent("address_2_street_address");
447 $this->select('address_2_location_type_id', 'value=1');
449 $this->click('address[2][use_shared_address]');
451 // create new household with dialog
452 $this->select('profiles_2', "label=New Household");
454 // create new contact using dialog
455 $this->waitForElementPresent("css=div#contact-dialog-2");
456 $this->waitForElementPresent("_qf_Edit_next");
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');
465 $this->click("_qf_Edit_next");
467 // Is new contact created?
468 $this->assertElementContainsText('crm-notification-container', "$sharedHousehold has been created.",
469 "Status message didn't show up after saving!"
472 //make sure shared address is selected
473 $this->waitForElementPresent('selected_shared_address-2');
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.");
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);
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");
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');