3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public function testPrefixGenderSuffix() {
39 $this->webtestLogin();
42 $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7);
43 $this->WebtestAddGroup($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->waitForAjaxContent();
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->waitForAjaxContent();
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->clickLink("_qf_Basic_refresh");
91 // Is contact present in search result?
92 $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!");
94 // Is contact present in search result?
95 $this->assertElementContainsText('css=div.crm-search-results', $sortSecondName, "Contact did not found in search result!");
97 // select to export all the contasct from search result.
98 $this->click("CIVICRM_QFID_ts_all_4");
100 // Select the task action to export.
101 $this->click("task");
102 $this->select("task", "label=Export Contacts");
103 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
107 // Build header row for assertion.
108 require_once 'CRM/Contact/BAO/Contact.php';
109 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
111 $checkHeaders = array();
112 foreach ($expotableFields as $key => $field) {
113 // Exclude custom fields.
114 if ($key && (substr($key, 0, 6) == 'custom')) {
117 $checkHeaders[] = $field['title'];
120 // All other rows to be check.
123 'First Name' => $secondContactName,
124 'Last Name' => 'John',
125 'Email' => '' . strtolower($emailContactSecond) . '',
126 'Sort Name' => $sortSecondName,
127 'Display Name' => $prefixLabelContactScnd . ' ' . $displaySecondName . ' ' . $suffixLabelContactScnd,
128 'Individual Prefix' => $prefixLabelContactScnd,
129 'Individual Suffix' => $suffixLabelContactScnd,
130 'Gender' => $genderLabelContactScnd,
133 'First Name' => $firstContactName,
134 'Last Name' => 'Smith',
135 'Email' => '' . strtolower($emailContactFirst) . '',
136 'Sort Name' => $sortFirstName,
137 'Display Name' => $prefixLabelContactFrst . ' ' . $displayFirstName . ' ' . $suffixLabelContactFrst,
138 'Individual Prefix' => $prefixLabelContactFrst,
139 'Individual Suffix' => $suffixLabelContactFrst,
140 'Gender' => $genderLabelContactFrst,
144 // Read CSV and fire assertions.
145 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
149 * Test Contact Export.
151 public function testContactExport() {
152 $this->webtestLogin();
155 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
156 $this->WebtestAddGroup($parentGroupName);
158 // Create new group and select the previously selected group as parent group for this new group.
159 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
160 $this->WebtestAddGroup($childGroupName, $parentGroupName);
162 // Adding Parent group contact
163 // We're using Quick Add block on the main page for this.
164 $firstName = 'a' . substr(sha1(rand()), 0, 7);
165 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
167 $sortName = "Smith, $firstName";
168 $displayName = "$firstName Smith";
170 // Add contact to parent group
172 $this->click("css=li#tab_group a");
173 $this->waitForElementPresent("group_id");
176 $this->select("group_id", "label=$parentGroupName");
177 $this->click("_qf_GroupContact_next");
178 $this->waitForAjaxContent();
180 // Adding child group contact
181 // We're using Quick Add block on the main page for this.
182 $childName = 'b' . substr(sha1(rand()), 0, 7);
183 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
185 $childSortName = "John, $childName";
186 $childDisplayName = "$childName John";
188 // Add contact to child group
190 $this->click("css=li#tab_group a");
191 $this->waitForElementPresent("group_id");
193 // Add to child group.
194 $this->select("group_id", "label=regexp:$childGroupName");
195 $this->click("_qf_GroupContact_next");
196 $this->waitForAjaxContent();
198 // Visit contact search page.
199 $this->openCiviPage("contact/search", "reset=1");
201 // Select contact type as Indiividual.
202 $this->select("contact_type", "value=Individual");
205 $this->select("group", "label=$parentGroupName");
208 $this->clickLink("_qf_Basic_refresh");
210 // Is contact present in search result?
211 $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
213 // Is contact present in search result?
214 $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!");
216 // select to export all the contasct from search result.
217 $this->click("CIVICRM_QFID_ts_all_4");
219 // Select the task action to export.
220 $this->click("task");
221 $this->select("task", "label=Export Contacts");
222 $this->waitForPageToLoad($this->getTimeoutMsec());
224 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
226 // Build header row for assertion.
227 require_once 'CRM/Contact/BAO/Contact.php';
228 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
230 $checkHeaders = array();
231 foreach ($expotableFields as $key => $field) {
232 // Exclude custom fields.
233 if ($key && (substr($key, 0, 6) == 'custom')) {
236 $checkHeaders[] = $field['title'];
239 // All other rows to be check.
242 'First Name' => $childName,
243 'Last Name' => 'John',
244 'Email' => "$childName.john@example.org",
245 'Sort Name' => $childSortName,
246 'Display Name' => $childDisplayName,
249 'First Name' => $firstName,
250 'Last Name' => 'Smith',
251 'Email' => "$firstName.smith@example.org",
252 'Sort Name' => $sortName,
253 'Display Name' => $displayName,
257 // Read CSV and fire assertions.
258 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
261 public function testMergeHousehold() {
262 $this->webtestLogin();
265 $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
266 $this->WebtestAddGroup($groupName);
268 // Adding Parent group contact
269 // We're using Quick Add block on the main page for this.
270 $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House';
272 $this->openCiviPage("contact/add", "reset=1&ct=Household");
273 $this->click('household_name');
274 $this->type('household_name', $houseHold);
277 $this->click("addressBlock");
278 $this->waitForElementPresent("address_1_street_address");
281 $this->click("//div[@id='addressBlockId']/div[1]");
282 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
283 $this->type("address_1_city", "Dumfries");
284 $this->type("address_1_postal_code", "1234");
285 $this->select("address_1_country_id", "United States");
286 $this->select("address_1_state_province_id", "value=1019");
288 $this->click('_qf_Contact_upload_view');
289 $this->waitForPageToLoad($this->getTimeoutMsec());
291 // Add contact to group
293 $this->click("css=li#tab_group a");
294 $this->waitForElementPresent("group_id");
297 $this->select("group_id", "label=$groupName");
298 $this->click("_qf_GroupContact_next");
299 $this->waitForAjaxContent();
301 $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
302 $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
304 $sortName1 = "Smith, {$firstName1}";
305 $displayName1 = "{$firstName1} Smith";
307 // Add contact to parent group
309 $this->click("css=li#tab_group a");
310 $this->waitForElementPresent("group_id");
313 $this->select("group_id", "label=$groupName");
314 $this->click("_qf_GroupContact_next");
315 $this->waitForAjaxContent();
317 $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
319 $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom");
320 $this->type('first_name', $firstName2);
321 $this->type('last_name', "Smith");
322 $this->type('email_1_email', "{$firstName2}.smith@example.org");
325 $this->click("addressBlock");
326 $this->waitForElementPresent("address_1_street_address");
328 $this->click("//div[@id='addressBlockId']/div[1]");
330 $this->click("address[1][use_shared_address]");
331 $this->waitForElementPresent("address_1_master_contact_id");
332 $this->select2('address_1_master_contact_id', $houseHold);
333 $this->waitForTextPresent("121A Sherman");
335 $this->click('_qf_Contact_upload_view-bottom');
336 $this->waitForPageToLoad($this->getTimeoutMsec());
338 $sortName2 = "Smith, {$firstName2}";
339 $displayName2 = "{$firstName2} Smith";
341 // Add contact to parent group
343 $this->click("css=li#tab_group a");
344 $this->waitForElementPresent("group_id");
347 $this->select("group_id", "label=$groupName");
348 $this->click("_qf_GroupContact_next");
349 $this->waitForAjaxContent();
351 $this->openCiviPage("contact/search", "reset=1", NULL);
354 $this->select("group", "label=$groupName");
357 $this->clickLink("_qf_Basic_refresh");
359 // Is contact present in search result?
360 $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!");
362 // Is contact present in search result?
363 $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!");
365 // Is contact present in search result?
366 $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!");
368 // select to export all the contasct from search result.
369 $this->click("CIVICRM_QFID_ts_all_4");
371 // Select the task action to export.
372 $this->click("task");
373 $this->select("task", "label=Export Contacts");
374 $this->waitForPageToLoad($this->getTimeoutMsec());
376 $this->click("CIVICRM_QFID_2_10");
378 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
380 // Build header row for assertion.
381 require_once 'CRM/Contact/BAO/Contact.php';
382 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
384 $checkHeaders = array();
385 foreach ($expotableFields as $key => $field) {
386 // Exclude custom fields.
387 if ($key && (substr($key, 0, 6) == 'custom')) {
390 $checkHeaders[] = $field['title'];
393 // All other rows to be check.
396 'Contact Type' => 'Household',
397 'Household Name' => $houseHold,
400 'Contact Type' => 'Individual',
401 'First Name' => $firstName1,
402 'Email' => "{$firstName1}.smith@example.org",
403 'Sort Name' => $sortName1,
404 'Display Name' => $displayName1,
408 // Read CSV and fire assertions.
409 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
413 * @param string $fname
414 * @param string $lname
416 * @param null $contactSubtype
420 public function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) {
421 $url = $this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Individual';
422 if ($contactSubtype) {
423 $url = $url . "&cst={$contactSubtype}";
426 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
428 $this->type('first_name', $fname);
429 $this->type('last_name', $lname);
430 if ($email === TRUE) {
431 $email = substr(sha1(rand()), 0, 7) . '@example.org';
434 $this->type('email_1_email', $email);
436 $genderLabelArray = array(
441 $prefix = rand(1, 4);
442 $suffix = rand(1, 8);
443 $gender = rand(1, 3);
444 $genderLabel = "civicrm_gender_" . $genderLabelArray[$gender] . "_$gender";
445 $this->select("prefix_id", "value=$prefix");
446 $this->select("suffix_id", "value=$suffix");
447 $this->click("demographics");
448 $this->waitForElementPresent("civicrm_gender_Female_1");
449 $this->click($genderLabel, "value=$gender");
450 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
451 $this->click('_qf_Contact_upload_view-bottom');
452 $this->waitForPageToLoad($this->getTimeoutMsec());
453 $prefixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_prefix', $prefix);
454 $suffixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_suffix', $suffix);
455 $genderLabel = WebTest_Export_ContactTest
::getOptionLabel('gender', $gender);
456 return array($email, $prefixLabel, $suffixLabel, $genderLabel);
460 * @param string $optionGroupName
461 * @param $optionValue
465 public function getOptionLabel($optionGroupName, $optionValue) {
469 'option_group_name' => $optionGroupName,
470 'value' => $optionValue,
473 $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue", $params);