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 'Individual Suffix' => $suffixLabelContactScnd,
127 'Gender' => $genderLabelContactScnd,
130 'First Name' => $firstContactName,
131 'Last Name' => 'Smith',
132 'Email' => '' . strtolower($emailContactFirst) . '',
133 'Sort Name' => $sortFirstName,
134 'Display Name' => $prefixLabelContactFrst . ' ' . $displayFirstName . ' ' . $suffixLabelContactFrst,
135 'Individual Prefix' => $prefixLabelContactFrst,
136 'Individual Suffix' => $suffixLabelContactFrst,
137 'Gender' => $genderLabelContactFrst,
141 // Read CSV and fire assertions.
142 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
146 * Test Contact Export.
148 public function testContactExport() {
149 $this->webtestLogin();
152 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
153 $this->WebtestAddGroup($parentGroupName);
155 // Create new group and select the previously selected group as parent group for this new group.
156 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
157 $this->WebtestAddGroup($childGroupName, $parentGroupName);
159 // Adding Parent group contact
160 // We're using Quick Add block on the main page for this.
161 $firstName = 'a' . substr(sha1(rand()), 0, 7);
162 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
164 $sortName = "Smith, $firstName";
165 $displayName = "$firstName Smith";
167 // Add contact to parent group
169 $this->click("css=li#tab_group a");
170 $this->waitForElementPresent("group_id");
173 $this->select("group_id", "label=$parentGroupName");
174 $this->click("_qf_GroupContact_next");
175 $this->waitForAjaxContent();
177 // Adding child group contact
178 // We're using Quick Add block on the main page for this.
179 $childName = 'b' . substr(sha1(rand()), 0, 7);
180 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
182 $childSortName = "John, $childName";
183 $childDisplayName = "$childName John";
185 // Add contact to child group
187 $this->click("css=li#tab_group a");
188 $this->waitForElementPresent("group_id");
190 // Add to child group.
191 $this->select("group_id", "label=regexp:$childGroupName");
192 $this->click("_qf_GroupContact_next");
193 $this->waitForAjaxContent();
195 // Visit contact search page.
196 $this->openCiviPage("contact/search", "reset=1");
198 // Select contact type as Indiividual.
199 $this->select("contact_type", "value=Individual");
202 $this->select("group", "label=$parentGroupName");
205 $this->clickLink("_qf_Basic_refresh");
207 // Is contact present in search result?
208 $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
210 // Is contact present in search result?
211 $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!");
213 // select to export all the contasct from search result.
214 $this->click("CIVICRM_QFID_ts_all_4");
216 // Select the task action to export.
217 $this->click("task");
218 $this->select("task", "label=Export Contacts");
219 $this->waitForPageToLoad($this->getTimeoutMsec());
221 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
223 // Build header row for assertion.
224 require_once 'CRM/Contact/BAO/Contact.php';
225 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
227 $checkHeaders = array();
228 foreach ($expotableFields as $key => $field) {
229 // Exclude custom fields.
230 if ($key && (substr($key, 0, 6) == 'custom')) {
233 $checkHeaders[] = $field['title'];
236 // All other rows to be check.
239 'First Name' => $childName,
240 'Last Name' => 'John',
241 'Email' => "$childName.john@example.org",
242 'Sort Name' => $childSortName,
243 'Display Name' => $childDisplayName,
246 'First Name' => $firstName,
247 'Last Name' => 'Smith',
248 'Email' => "$firstName.smith@example.org",
249 'Sort Name' => $sortName,
250 'Display Name' => $displayName,
254 // Read CSV and fire assertions.
255 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
258 public function testMergeHousehold() {
259 $this->webtestLogin();
262 $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
263 $this->WebtestAddGroup($groupName);
265 // Adding Parent group contact
266 // We're using Quick Add block on the main page for this.
267 $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House';
269 $this->openCiviPage("contact/add", "reset=1&ct=Household");
270 $this->click('household_name');
271 $this->type('household_name', $houseHold);
274 $this->click("addressBlock");
275 $this->waitForElementPresent("address_1_street_address");
278 $this->click("//div[@id='addressBlockId']/div[1]");
279 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
280 $this->type("address_1_city", "Dumfries");
281 $this->type("address_1_postal_code", "1234");
282 $this->select("address_1_country_id", "United States");
283 $this->select("address_1_state_province_id", "value=1019");
285 $this->click('_qf_Contact_upload_view');
286 $this->waitForPageToLoad($this->getTimeoutMsec());
288 // Add contact to group
290 $this->click("css=li#tab_group a");
291 $this->waitForElementPresent("group_id");
294 $this->select("group_id", "label=$groupName");
295 $this->click("_qf_GroupContact_next");
296 $this->waitForAjaxContent();
298 $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
299 $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
301 $sortName1 = "Smith, {$firstName1}";
302 $displayName1 = "{$firstName1} Smith";
304 // Add contact to parent group
306 $this->click("css=li#tab_group a");
307 $this->waitForElementPresent("group_id");
310 $this->select("group_id", "label=$groupName");
311 $this->click("_qf_GroupContact_next");
312 $this->waitForAjaxContent();
314 $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
316 $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom");
317 $this->type('first_name', $firstName2);
318 $this->type('last_name', "Smith");
319 $this->type('email_1_email', "{$firstName2}.smith@example.org");
322 $this->click("addressBlock");
323 $this->waitForElementPresent("address_1_street_address");
325 $this->click("//div[@id='addressBlockId']/div[1]");
327 $this->click("address[1][use_shared_address]");
328 $this->waitForElementPresent("address_1_master_contact_id");
329 $this->select2('address_1_master_contact_id', $houseHold);
330 $this->waitForTextPresent("121A Sherman");
332 $this->click('_qf_Contact_upload_view-bottom');
333 $this->waitForPageToLoad($this->getTimeoutMsec());
335 $sortName2 = "Smith, {$firstName2}";
336 $displayName2 = "{$firstName2} Smith";
338 // Add contact to parent group
340 $this->click("css=li#tab_group a");
341 $this->waitForElementPresent("group_id");
344 $this->select("group_id", "label=$groupName");
345 $this->click("_qf_GroupContact_next");
346 $this->waitForAjaxContent();
348 $this->openCiviPage("contact/search", "reset=1", NULL);
351 $this->select("group", "label=$groupName");
354 $this->clickLink("_qf_Basic_refresh");
356 // Is contact present in search result?
357 $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!");
359 // Is contact present in search result?
360 $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!");
362 // Is contact present in search result?
363 $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!");
365 // select to export all the contasct from search result.
366 $this->click("CIVICRM_QFID_ts_all_4");
368 // Select the task action to export.
369 $this->click("task");
370 $this->select("task", "label=Export Contacts");
371 $this->waitForPageToLoad($this->getTimeoutMsec());
373 $this->click("CIVICRM_QFID_2_10");
375 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
377 // Build header row for assertion.
378 require_once 'CRM/Contact/BAO/Contact.php';
379 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
381 $checkHeaders = array();
382 foreach ($expotableFields as $key => $field) {
383 // Exclude custom fields.
384 if ($key && (substr($key, 0, 6) == 'custom')) {
387 $checkHeaders[] = $field['title'];
390 // All other rows to be check.
393 'Contact Type' => 'Household',
394 'Household Name' => $houseHold,
397 'Contact Type' => 'Individual',
398 'First Name' => $firstName1,
399 'Email' => "{$firstName1}.smith@example.org",
400 'Sort Name' => $sortName1,
401 'Display Name' => $displayName1,
405 // Read CSV and fire assertions.
406 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
410 * @param string $fname
411 * @param string $lname
413 * @param null $contactSubtype
417 public function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) {
418 $url = $this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Individual';
419 if ($contactSubtype) {
420 $url = $url . "&cst={$contactSubtype}";
423 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
425 $this->type('first_name', $fname);
426 $this->type('last_name', $lname);
427 if ($email === TRUE) {
428 $email = substr(sha1(rand()), 0, 7) . '@example.org';
431 $this->type('email_1_email', $email);
433 $genderLabelArray = array(
438 $prefix = rand(1, 4);
439 $suffix = rand(1, 8);
440 $gender = rand(1, 3);
441 $genderLabel = "civicrm_gender_" . $genderLabelArray[$gender] . "_$gender";
442 $this->select("prefix_id", "value=$prefix");
443 $this->select("suffix_id", "value=$suffix");
444 $this->click("demographics");
445 $this->waitForElementPresent("civicrm_gender_Female_1");
446 $this->click($genderLabel, "value=$gender");
447 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
448 $this->click('_qf_Contact_upload_view-bottom');
449 $this->waitForPageToLoad($this->getTimeoutMsec());
450 $prefixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_prefix', $prefix);
451 $suffixLabel = WebTest_Export_ContactTest
::getOptionLabel('individual_suffix', $suffix);
452 $genderLabel = WebTest_Export_ContactTest
::getOptionLabel('gender', $gender);
453 return array($email, $prefixLabel, $suffixLabel, $genderLabel);
457 * @param string $optionGroupName
458 * @param $optionValue
462 public function getOptionLabel($optionGroupName, $optionValue) {
466 'option_group_name' => $optionGroupName,
467 'value' => $optionValue,
470 $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue", $params);