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 +--------------------------------------------------------------------+
27 require_once 'WebTest/Export/ExportCiviSeleniumTestCase.php';
28 class WebTest_Export_ContactTest
extends ExportCiviSeleniumTestCase
{
30 protected function setUp() {
35 * Test Contact Export.
37 function testContactExport() {
38 $this->webtestLogin();
41 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
42 $this->addContactGroup($parentGroupName);
44 // Create new group and select the previously selected group as parent group for this new group.
45 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
46 $this->addContactGroup($childGroupName, $parentGroupName);
48 // Adding Parent group contact
49 // We're using Quick Add block on the main page for this.
50 $firstName = 'a' . substr(sha1(rand()), 0, 7);
51 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
53 $sortName = "Smith, $firstName";
54 $displayName = "$firstName Smith";
56 // Add contact to parent group
58 $this->click("css=li#tab_group a");
59 $this->waitForElementPresent("group_id");
62 $this->select("group_id", "label=$parentGroupName");
63 $this->click("_qf_GroupContact_next");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
66 // Adding child group contact
67 // We're using Quick Add block on the main page for this.
68 $childName = 'b' . substr(sha1(rand()), 0, 7);
69 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
71 $childSortName = "John, $childName";
72 $childDisplayName = "$childName John";
74 // Add contact to child group
76 $this->click("css=li#tab_group a");
77 $this->waitForElementPresent("group_id");
79 // Add to child group.
80 $this->select("group_id", "label=regexp:$childGroupName");
81 $this->click("_qf_GroupContact_next");
82 $this->waitForPageToLoad($this->getTimeoutMsec());
84 // Visit contact search page.
85 $this->openCiviPage("contact/search", "reset=1");
87 // Select contact type as Indiividual.
88 $this->select("contact_type", "value=Individual");
91 $this->select("group", "label=$parentGroupName");
94 $this->click("_qf_Basic_refresh");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
97 // Is contact present in search result?
98 $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!");
100 // Is contact present in search result?
101 $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!");
103 // select to export all the contasct from search result.
104 $this->click("CIVICRM_QFID_ts_all_4");
106 // Select the task action to export.
107 $this->click("task");
108 $this->select("task", "label=Export Contacts");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
112 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
114 // Build header row for assertion.
115 require_once 'CRM/Contact/BAO/Contact.php';
116 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
118 $checkHeaders = array();
119 foreach ($expotableFields as $key => $field) {
120 // Exclude custom fields.
121 if ($key && (substr($key, 0, 6) == 'custom')) {
124 $checkHeaders[] = $field['title'];
127 // All other rows to be check.
130 'First Name' => $firstName,
131 'Last Name' => 'Smith',
132 'Email' => "$firstName.smith@example.org",
133 'Sort Name' => $sortName,
134 'Display Name' => $displayName,
137 'First Name' => $childName,
138 'Last Name' => 'John',
139 'Email' => "$childName.john@example.org",
140 'Sort Name' => $childSortName,
141 'Display Name' => $childDisplayName,
145 // Read CSV and fire assertions.
146 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
149 function testMergeHousehold() {
150 $this->webtestLogin();
153 $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
154 $this->addContactGroup($groupName);
156 // Adding Parent group contact
157 // We're using Quick Add block on the main page for this.
158 $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House';
160 $this->openCiviPage("contact/add", "reset=1&ct=Household");
161 $this->click('household_name');
162 $this->type('household_name', $houseHold);
165 $this->click("addressBlock");
166 $this->waitForElementPresent("address_1_street_address");
169 $this->click("//div[@id='addressBlockId']/div[1]");
170 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
171 $this->type("address_1_city", "Dumfries");
172 $this->type("address_1_postal_code", "1234");
173 $this->assertElementContainsText('address_1', "- select - United States");
174 $this->select("address_1_state_province_id", "value=1019");
176 $this->click('_qf_Contact_upload_view');
177 $this->waitForPageToLoad($this->getTimeoutMsec());
179 // Add contact to group
181 $this->click("css=li#tab_group a");
182 $this->waitForElementPresent("group_id");
185 $this->select("group_id", "label=$groupName");
186 $this->click("_qf_GroupContact_next");
187 $this->waitForPageToLoad($this->getTimeoutMsec());
189 $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
190 $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
192 $sortName1 = "Smith, {$firstName1}";
193 $displayName1 = "{$firstName1} Smith";
195 // Add contact to parent group
197 $this->click("css=li#tab_group a");
198 $this->waitForElementPresent("group_id");
201 $this->select("group_id", "label=$groupName");
202 $this->click("_qf_GroupContact_next");
203 $this->waitForPageToLoad($this->getTimeoutMsec());
205 $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
207 $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom");
208 $this->type('first_name', $firstName2);
209 $this->type('last_name', "Smith");
210 $this->type('email_1_email', "{$firstName2}.smith@example.org");
213 $this->click("addressBlock");
214 $this->waitForElementPresent("address_1_street_address");
216 $this->click("//div[@id='addressBlockId']/div[1]");
218 $this->click("address[1][use_shared_address]");
219 $this->waitForElementPresent("contact_1");
220 $this->webtestFillAutocomplete($houseHold);
221 $this->waitForTextPresent("121A Sherman");
223 $this->click('_qf_Contact_upload_view-bottom');
224 $this->waitForPageToLoad($this->getTimeoutMsec());
226 $sortName2 = "Smith, {$firstName2}";
227 $displayName2 = "{$firstName2} Smith";
229 // Add contact to parent group
231 $this->click("css=li#tab_group a");
232 $this->waitForElementPresent("group_id");
235 $this->select("group_id", "label=$groupName");
236 $this->click("_qf_GroupContact_next");
237 $this->waitForPageToLoad($this->getTimeoutMsec());
239 $this->openCiviPage("contact/search", "reset=1", NULL);
242 $this->select("group", "label=$groupName");
245 $this->click("_qf_Basic_refresh");
246 $this->waitForPageToLoad($this->getTimeoutMsec());
248 // Is contact present in search result?
249 $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!");
251 // Is contact present in search result?
252 $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!");
254 // Is contact present in search result?
255 $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!");
257 // select to export all the contasct from search result.
258 $this->click("CIVICRM_QFID_ts_all_4");
260 // Select the task action to export.
261 $this->click("task");
262 $this->select("task", "label=Export Contacts");
264 $this->waitForPageToLoad($this->getTimeoutMsec());
266 $this->click("CIVICRM_QFID_2_10");
268 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
270 // Build header row for assertion.
271 require_once 'CRM/Contact/BAO/Contact.php';
272 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
274 $checkHeaders = array();
275 foreach ($expotableFields as $key => $field) {
276 // Exclude custom fields.
277 if ($key && (substr($key, 0, 6) == 'custom')) {
280 $checkHeaders[] = $field['title'];
283 // All other rows to be check.
286 'Contact Type' => 'Household',
287 'Household Name' => $houseHold,
290 'Contact Type' => 'Individual',
291 'First Name' => $firstName1,
292 'Email' => "{$firstName1}.smith@example.org",
293 'Sort Name' => $sortName1,
294 'Display Name' => $displayName1,
298 // Read CSV and fire assertions.
299 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
302 function addContactGroup($groupName = 'New Group', $parentGroupName = "- select -") {
303 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
306 $this->type("title", $groupName);
309 $this->type("description", "Adding new group.");
311 // Check Access Control.
312 $this->click("group_type[1]");
314 // Check Mailing List.
315 $this->click("group_type[2]");
317 // Select Visibility as Public Pages.
318 $this->select("visibility", "value=Public Pages");
320 // Select parent group.
321 $this->select("parents", "label=$parentGroupName");
324 $this->click("_qf_Edit_upload");
325 $this->waitForPageToLoad($this->getTimeoutMsec());
327 // Is status message correct?
328 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");