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 'WebTest/Export/ExportCiviSeleniumTestCase.php';
30 * Class WebTest_Export_ContactTest
32 class WebTest_Export_ContactTest
extends ExportCiviSeleniumTestCase
{
34 protected function setUp() {
38 function testPrefixGenderSuffix(){
39 $this->webtestLogin();
42 $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7);
43 $this->addContactGroup($parentGroupName);
45 // Adding Parent group contact
46 // We're using Quick Add block on the main page for this.
47 $firstContactName = 'TestExport' . substr(sha1(rand()), 0, 7);
49 list($emailContactFirst,$prefixLabelContactFrst,$suffixLabelContactFrst,$genderLabelContactFrst) = WebTest_Export_ContactTest
::webtestAddContactWithGenderPrefixSuffix($firstContactName, "Smith", "$firstContactName.smith@example.org", Null);
51 $sortFirstName = "Smith, $firstContactName";
52 $displayFirstName = "$firstContactName Smith";
54 // Add contact to parent group
56 $this->click("css=li#tab_group a");
57 $this->waitForElementPresent("group_id");
60 $this->select("group_id", "label=$parentGroupName");
61 $this->click("_qf_GroupContact_next");
62 $this->waitForElementPresent("//*[@id='GroupContact']");
64 $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7);
65 list($emailContactSecond,$prefixLabelContactScnd,$suffixLabelContactScnd,$genderLabelContactScnd) = WebTest_Export_ContactTest
::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", Null);
67 $sortSecondName = "John, $secondContactName";
68 $displaySecondName = "$secondContactName John";
70 // Add contact to parent group
72 $this->click("css=li#tab_group a");
73 $this->waitForElementPresent("group_id");
76 $this->select("group_id", "label=$parentGroupName");
77 $this->click("_qf_GroupContact_next");
78 $this->waitForElementPresent("//*[@id='GroupContact']");
80 $this->openCiviPage("contact/search", "reset=1");
82 // Select contact type as Indiividual.
83 $this->select("contact_type", "value=Individual");
86 $this->select("group", "label=$parentGroupName");
89 $this->click("_qf_Basic_refresh");
90 $this->waitForPageToLoad($this->getTimeoutMsec());
92 // Is contact present in search result?
93 $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!");
95 // Is contact present in search result?
96 $this->assertElementContainsText('css=div.crm-search-results', $sortSecondName, "Contact did not found in search result!");
98 // select to export all the contasct from search result.
99 $this->click("CIVICRM_QFID_ts_all_4");
101 // Select the task action to export.
102 $this->click("task");
103 $this->select("task", "label=Export Contacts");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
106 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
108 // Build header row for assertion.
109 require_once 'CRM/Contact/BAO/Contact.php';
110 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
112 $checkHeaders = array();
113 foreach ($expotableFields as $key => $field) {
114 // Exclude custom fields.
115 if ($key && (substr($key, 0, 6) == 'custom')) {
118 $checkHeaders[] = $field['title'];
121 // All other rows to be check.
124 'First Name' => $firstContactName,
125 'Last Name' => 'Smith',
126 'Email' => ''.strtolower($emailContactFirst).'',
127 'Sort Name' => $sortFirstName,
128 'Display Name' => $prefixLabelContactFrst.' '.$displayFirstName.' '.$suffixLabelContactFrst,
129 'Individual Prefix' => $prefixLabelContactFrst,
130 'Individual Suffix' => $suffixLabelContactFrst,
131 'Gender' => $genderLabelContactFrst,
134 'First Name' => $secondContactName,
135 'Last Name' => 'John',
136 'Email' => ''.strtolower($emailContactSecond).'',
137 'Sort Name' => $sortSecondName,
138 'Display Name' => $prefixLabelContactScnd.' '.$displaySecondName.' '.$suffixLabelContactScnd,
139 'Individual Prefix' => $prefixLabelContactScnd,
140 'Individual Suffix' => $suffixLabelContactScnd,
141 'Gender' => $genderLabelContactScnd,
145 // Read CSV and fire assertions.
146 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
150 * Test Contact Export.
152 function testContactExport() {
153 $this->webtestLogin();
156 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
157 $this->addContactGroup($parentGroupName);
159 // Create new group and select the previously selected group as parent group for this new group.
160 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
161 $this->addContactGroup($childGroupName, $parentGroupName);
163 // Adding Parent group contact
164 // We're using Quick Add block on the main page for this.
165 $firstName = 'a' . substr(sha1(rand()), 0, 7);
166 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
168 $sortName = "Smith, $firstName";
169 $displayName = "$firstName Smith";
171 // Add contact to parent group
173 $this->click("css=li#tab_group a");
174 $this->waitForElementPresent("group_id");
177 $this->select("group_id", "label=$parentGroupName");
178 $this->click("_qf_GroupContact_next");
179 $this->waitForElementPresent("//*[@id='GroupContact']");
181 // Adding child group contact
182 // We're using Quick Add block on the main page for this.
183 $childName = 'b' . substr(sha1(rand()), 0, 7);
184 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
186 $childSortName = "John, $childName";
187 $childDisplayName = "$childName John";
189 // Add contact to child group
191 $this->click("css=li#tab_group a");
192 $this->waitForElementPresent("group_id");
194 // Add to child group.
195 $this->select("group_id", "label=regexp:$childGroupName");
196 $this->click("_qf_GroupContact_next");
197 $this->waitForElementPresent("//*[@id='GroupContact']");
199 // Visit contact search page.
200 $this->openCiviPage("contact/search", "reset=1");
202 // Select contact type as Indiividual.
203 $this->select("contact_type", "value=Individual");
206 $this->select("group", "label=$parentGroupName");
209 $this->click("_qf_Basic_refresh");
210 $this->waitForPageToLoad($this->getTimeoutMsec());
212 // Is contact present in search result?
213 $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
215 // Is contact present in search result?
216 $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!");
218 // select to export all the contasct from search result.
219 $this->click("CIVICRM_QFID_ts_all_4");
221 // Select the task action to export.
222 $this->click("task");
223 $this->select("task", "label=Export Contacts");
224 $this->waitForPageToLoad($this->getTimeoutMsec());
226 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
228 // Build header row for assertion.
229 require_once 'CRM/Contact/BAO/Contact.php';
230 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
232 $checkHeaders = array();
233 foreach ($expotableFields as $key => $field) {
234 // Exclude custom fields.
235 if ($key && (substr($key, 0, 6) == 'custom')) {
238 $checkHeaders[] = $field['title'];
241 // All other rows to be check.
244 'First Name' => $firstName,
245 'Last Name' => 'Smith',
246 'Email' => "$firstName.smith@example.org",
247 'Sort Name' => $sortName,
248 'Display Name' => $displayName,
251 'First Name' => $childName,
252 'Last Name' => 'John',
253 'Email' => "$childName.john@example.org",
254 'Sort Name' => $childSortName,
255 'Display Name' => $childDisplayName,
259 // Read CSV and fire assertions.
260 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
263 function testMergeHousehold() {
264 $this->webtestLogin();
267 $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
268 $this->addContactGroup($groupName);
270 // Adding Parent group contact
271 // We're using Quick Add block on the main page for this.
272 $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House';
274 $this->openCiviPage("contact/add", "reset=1&ct=Household");
275 $this->click('household_name');
276 $this->type('household_name', $houseHold);
279 $this->click("addressBlock");
280 $this->waitForElementPresent("address_1_street_address");
283 $this->click("//div[@id='addressBlockId']/div[1]");
284 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
285 $this->type("address_1_city", "Dumfries");
286 $this->type("address_1_postal_code", "1234");
287 $this->assertElementContainsText('address_1', "- select - United States");
288 $this->select("address_1_state_province_id", "value=1019");
290 $this->click('_qf_Contact_upload_view');
291 $this->waitForPageToLoad($this->getTimeoutMsec());
293 // Add contact to group
295 $this->click("css=li#tab_group a");
296 $this->waitForElementPresent("group_id");
299 $this->select("group_id", "label=$groupName");
300 $this->click("_qf_GroupContact_next");
301 $this->waitForElementPresent("//*[@id='GroupContact']");
303 $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
304 $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
306 $sortName1 = "Smith, {$firstName1}";
307 $displayName1 = "{$firstName1} Smith";
309 // Add contact to parent group
311 $this->click("css=li#tab_group a");
312 $this->waitForElementPresent("group_id");
315 $this->select("group_id", "label=$groupName");
316 $this->click("_qf_GroupContact_next");
317 $this->waitForElementPresent("//*[@id='GroupContact']");
319 $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
321 $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom");
322 $this->type('first_name', $firstName2);
323 $this->type('last_name', "Smith");
324 $this->type('email_1_email', "{$firstName2}.smith@example.org");
327 $this->click("addressBlock");
328 $this->waitForElementPresent("address_1_street_address");
330 $this->click("//div[@id='addressBlockId']/div[1]");
332 $this->click("address[1][use_shared_address]");
333 $this->waitForElementPresent("address_1_master_contact_id");
334 $this->select2('address_1_master_contact_id', $houseHold);
335 $this->waitForTextPresent("121A Sherman");
337 $this->click('_qf_Contact_upload_view-bottom');
338 $this->waitForPageToLoad($this->getTimeoutMsec());
340 $sortName2 = "Smith, {$firstName2}";
341 $displayName2 = "{$firstName2} Smith";
343 // Add contact to parent group
345 $this->click("css=li#tab_group a");
346 $this->waitForElementPresent("group_id");
349 $this->select("group_id", "label=$groupName");
350 $this->click("_qf_GroupContact_next");
351 $this->waitForElementPresent("//*[@id='GroupContact']");
353 $this->openCiviPage("contact/search", "reset=1", NULL);
356 $this->select("group", "label=$groupName");
359 $this->click("_qf_Basic_refresh");
360 $this->waitForPageToLoad($this->getTimeoutMsec());
362 // Is contact present in search result?
363 $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!");
365 // Is contact present in search result?
366 $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!");
368 // Is contact present in search result?
369 $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!");
371 // select to export all the contasct from search result.
372 $this->click("CIVICRM_QFID_ts_all_4");
374 // Select the task action to export.
375 $this->click("task");
376 $this->select("task", "label=Export Contacts");
377 $this->waitForPageToLoad($this->getTimeoutMsec());
379 $this->click("CIVICRM_QFID_2_10");
381 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
383 // Build header row for assertion.
384 require_once 'CRM/Contact/BAO/Contact.php';
385 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
387 $checkHeaders = array();
388 foreach ($expotableFields as $key => $field) {
389 // Exclude custom fields.
390 if ($key && (substr($key, 0, 6) == 'custom')) {
393 $checkHeaders[] = $field['title'];
396 // All other rows to be check.
399 'Contact Type' => 'Household',
400 'Household Name' => $houseHold,
403 'Contact Type' => 'Individual',
404 'First Name' => $firstName1,
405 'Email' => "{$firstName1}.smith@example.org",
406 'Sort Name' => $sortName1,
407 'Display Name' => $displayName1,
411 // Read CSV and fire assertions.
412 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
416 * @param string $groupName
417 * @param string $parentGroupName
419 function addContactGroup($groupName = 'New Group', $parentGroupName = "- select group -") {
420 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
423 $this->type("title", $groupName);
426 $this->type("description", "Adding new group.");
428 // Check Access Control.
429 $this->click("group_type[1]");
431 // Check Mailing List.
432 $this->click("group_type[2]");
434 // Select Visibility as Public Pages.
435 $this->select("visibility", "value=Public Pages");
437 // Select parent group.
438 $this->select("parents", "label=$parentGroupName");
441 $this->click("_qf_Edit_upload");
442 $this->waitForPageToLoad($this->getTimeoutMsec());
444 // Is status message correct?
445 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
449 * @param string $fname
450 * @param string $lname
452 * @param null $contactSubtype
456 function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) {
457 $url = $this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Individual';
458 if ($contactSubtype) {
459 $url = $url . "&cst={$contactSubtype}";
462 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
464 $this->type('first_name', $fname);
465 $this->type('last_name', $lname);
466 if ($email === TRUE) {
467 $email = substr(sha1(rand()), 0, 7) . '@example.org';
470 $this->type('email_1_email', $email);
472 $genderLabelArray = array(
477 $prefix = rand(1, 4);
478 $suffix = rand(1, 8);
479 $gender = rand(1, 3);
480 $genderLabel = "civicrm_gender_".$genderLabelArray[$gender]."_$gender";
481 $this->select("prefix_id", "value=$prefix");
482 $this->select("suffix_id", "value=$suffix");
483 $this->click("demographics");
484 $this->waitForElementPresent("civicrm_gender_Female_1");
485 $this->click($genderLabel,"value=$gender");
486 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
487 $this->click('_qf_Contact_upload_view-bottom');
488 $this->waitForPageToLoad($this->getTimeoutMsec());
489 $prefixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_prefix',$prefix);
490 $suffixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_suffix',$suffix);
491 $genderLabel = WebTest_Export_ContactTest
::getOptionLabel('gender',$gender);
492 return array($email,$prefixLabel,$suffixLabel,$genderLabel);
496 * @param $optionGroupName
497 * @param $optionValue
501 function getOptionLabel($optionGroupName,$optionValue){
505 'option_group_name' => $optionGroupName,
506 'value' => $optionValue,
509 $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue",$params);