3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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->markTestSkipped('Skipping for now as it works fine locally.');
40 $this->webtestLogin();
43 $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7);
44 $this->WebtestAddGroup($parentGroupName);
46 // Adding Parent group contact
47 // We're using Quick Add block on the main page for this.
48 $firstContactName = 'TestExport' . substr(sha1(rand()), 0, 7);
50 list($emailContactFirst, $prefixLabelContactFrst, $suffixLabelContactFrst, $genderLabelContactFrst) = WebTest_Export_ContactTest
::webtestAddContactWithGenderPrefixSuffix($firstContactName, "Smith", "$firstContactName.smith@example.org", NULL);
52 $sortFirstName = "Smith, $firstContactName";
53 $displayFirstName = "$firstContactName Smith";
55 // Add contact to parent group
57 $this->click("css=li#tab_group a");
58 $this->waitForElementPresent("group_id");
61 $this->select("group_id", "label=$parentGroupName");
62 $this->click("_qf_GroupContact_next");
63 $this->waitForAjaxContent();
65 $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7);
66 list($emailContactSecond, $prefixLabelContactScnd, $suffixLabelContactScnd, $genderLabelContactScnd) = WebTest_Export_ContactTest
::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", NULL);
68 $sortSecondName = "John, $secondContactName";
69 $displaySecondName = "$secondContactName John";
71 // Add contact to parent group
73 $this->click("css=li#tab_group a");
74 $this->waitForElementPresent("group_id");
77 $this->select("group_id", "label=$parentGroupName");
78 $this->click("_qf_GroupContact_next");
79 $this->waitForAjaxContent();
81 $this->openCiviPage("contact/search", "reset=1");
83 // Select contact type as Indiividual.
84 $this->select("contact_type", "value=Individual");
87 $this->select("group", "label=$parentGroupName");
90 $this->clickLink("_qf_Basic_refresh");
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' => $secondContactName,
125 'Last Name' => 'John',
126 'Email' => '' . strtolower($emailContactSecond) . '',
127 'Individual Suffix' => $suffixLabelContactScnd,
128 'Gender' => $genderLabelContactScnd,
131 'First Name' => $firstContactName,
132 'Last Name' => 'Smith',
133 'Email' => '' . strtolower($emailContactFirst) . '',
134 'Sort Name' => $sortFirstName,
135 'Display Name' => $prefixLabelContactFrst . ' ' . $displayFirstName . ' ' . $suffixLabelContactFrst,
136 'Individual Prefix' => $prefixLabelContactFrst,
137 'Individual Suffix' => $suffixLabelContactFrst,
138 'Gender' => $genderLabelContactFrst,
142 // Read CSV and fire assertions.
143 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
147 * Test Contact Export.
149 public function testContactExport() {
150 $this->markTestSkipped('Skipping for now as it works fine locally.');
151 $this->webtestLogin();
154 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
155 $this->WebtestAddGroup($parentGroupName);
157 // Create new group and select the previously selected group as parent group for this new group.
158 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
159 $this->WebtestAddGroup($childGroupName, $parentGroupName);
161 // Adding Parent group contact
162 // We're using Quick Add block on the main page for this.
163 $firstName = 'a' . substr(sha1(rand()), 0, 7);
164 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
166 $sortName = "Smith, $firstName";
167 $displayName = "$firstName Smith";
169 // Add contact to parent group
171 $this->click("css=li#tab_group a");
172 $this->waitForElementPresent("group_id");
175 $this->select("group_id", "label=$parentGroupName");
176 $this->click("_qf_GroupContact_next");
177 $this->waitForAjaxContent();
179 // Adding child group contact
180 // We're using Quick Add block on the main page for this.
181 $childName = 'b' . substr(sha1(rand()), 0, 7);
182 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
184 $childSortName = "John, $childName";
185 $childDisplayName = "$childName John";
187 // Add contact to child group
189 $this->click("css=li#tab_group a");
190 $this->waitForElementPresent("group_id");
192 // Add to child group.
193 $this->select("group_id", "label=regexp:$childGroupName");
194 $this->click("_qf_GroupContact_next");
195 $this->waitForAjaxContent();
197 // Visit contact search page.
198 $this->openCiviPage("contact/search", "reset=1");
200 // Select contact type as Indiividual.
201 $this->select("contact_type", "value=Individual");
204 $this->select("group", "label=$parentGroupName");
207 $this->clickLink("_qf_Basic_refresh");
209 // Is contact present in search result?
210 $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
212 // Is contact present in search result?
213 $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!");
215 // select to export all the contacts from search result.
216 $this->click("CIVICRM_QFID_ts_all_4");
218 // Select the task action to export.
219 $this->click("task");
220 $this->select("task", "label=Export contacts");
221 $this->waitForPageToLoad($this->getTimeoutMsec());
223 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
225 // Build header row for assertion.
226 require_once 'CRM/Contact/BAO/Contact.php';
227 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
229 $checkHeaders = array();
230 foreach ($expotableFields as $key => $field) {
231 // Exclude custom fields.
232 if ($key && (substr($key, 0, 6) == 'custom')) {
235 $checkHeaders[] = $field['title'];
238 // All other rows to be check.
241 'First Name' => $childName,
242 'Last Name' => 'John',
243 'Email' => "$childName.john@example.org",
244 'Sort Name' => $childSortName,
245 'Display Name' => $childDisplayName,
248 'First Name' => $firstName,
249 'Last Name' => 'Smith',
250 'Email' => "$firstName.smith@example.org",
251 'Sort Name' => $sortName,
252 'Display Name' => $displayName,
256 // Read CSV and fire assertions.
257 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
260 public function testMergeHousehold() {
261 $this->markTestSkipped('Skipping for now as it works fine locally.');
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);
478 * CRM-17286 - Test Contribution Export for Soft Credit fields.
480 public function testContributionExport() {
481 $this->webtestLogin();
483 // Create a contact to be used as soft creditor
484 $softCreditFname = substr(sha1(rand()), 0, 7);
485 $softCreditLname = substr(sha1(rand()), 0, 7);
486 $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE);
488 $firstName = 'a' . substr(sha1(rand()), 0, 7);
489 $this->openCiviPage('contribute/add', 'reset=1&action=add&context=standalone', '_qf_Contribution_upload-bottom');
490 $this->webtestNewDialogContact($firstName);
491 // select financial type
492 $this->select("financial_type_id", "value=1");
494 // fill in Received Date
495 $this->webtestFillDate('receive_date');
498 $this->type("source", "Mailer 1");
501 $this->type("total_amount", "100");
503 // create first soft credit
504 $this->click("softCredit");
505 $this->waitForElementPresent("soft_credit_amount_1");
506 $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 's2id_soft_credit_contact_id_1');
507 $this->type("soft_credit_amount_1", "50");
510 $this->clickLink("_qf_Contribution_upload");
512 $this->openCiviPage("contribute/search", "reset=1", "_qf_Search_refresh");
513 $this->type("sort_name", $firstName);
514 $this->clickLink("_qf_Search_refresh");
515 // Is contact present in search result?
516 $this->assertElementContainsText('css=div.crm-search-results', $firstName, "Contact did not found in search result!");
517 $contributionID = $this->urlArg('id', $this->getAttribute("xpath=//div[@id='contributionSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']@href"));
518 // select to export all the contacts from search result.
519 $this->click("toggleSelect");
521 // Select the task action to export.
522 $this->click("task");
523 $this->select("task", "label=Export contributions");
524 $this->waitForPageToLoad($this->getTimeoutMsec());
525 $this->click('CIVICRM_QFID_2_4');
526 $this->clickLink('_qf_Select_next-bottom');
528 $this->select("mapper_1_0_0", 'Contribution');
529 $this->select("mapper_1_0_1", 'Soft Credit Amount');
531 $this->select("mapper_1_1_0", 'Contribution');
532 $this->select("mapper_1_1_1", 'Soft Credit For');
534 $this->select("mapper_1_2_0", 'Contribution');
535 $this->select("mapper_1_2_1", 'Soft Credit For Contribution ID');
537 $this->select("mapper_1_3_0", 'Contribution');
538 $this->select("mapper_1_3_1", 'Soft Credit Type');
540 $csvFile = $this->downloadCSV("_qf_Map_next-bottom", 'CiviCRM_Contribution_Search.csv');
542 // All other rows to be check.
545 'Soft Credit Amount' => 50.00,
546 'Soft Credit For' => "{$softCreditLname}, {$softCreditFname}",
547 'Soft Credit For Contribution ID' => $contributionID,
548 'Soft Credit Type' => 'Solicited',
552 // Read CSV and fire assertions.
553 $this->reviewCSV($csvFile, array(), $checkRows, 1);