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 +--------------------------------------------------------------------+
28 require_once 'WebTest/Export/ExportCiviSeleniumTestCase.php';
29 class WebTest_Export_ContactTest
extends ExportCiviSeleniumTestCase
{
31 protected function setUp() {
36 * Test Contact Export.
38 function testContactExport() {
39 $this->open($this->sboxPath
);
41 // Logging in. Remember to wait for page to load. In most cases,
42 // you can rely on 30000 as the value that allows your test to pass, however,
43 // sometimes your test might fail because of this. In such cases, it's better to pick one element
44 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
45 // page contents loaded and you can continue your test execution.
46 $this->webtestLogin();
49 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
50 $this->addContactGroup($parentGroupName);
52 // Create new group and select the previously selected group as parent group for this new group.
53 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
54 $this->addContactGroup($childGroupName, $parentGroupName);
56 // Adding Parent group contact
57 // We're using Quick Add block on the main page for this.
58 $firstName = 'a' . substr(sha1(rand()), 0, 7);
59 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
61 $sortName = "Smith, $firstName";
62 $displayName = "$firstName Smith";
64 // Add contact to parent group
66 $this->click("css=li#tab_group a");
67 $this->waitForElementPresent("group_id");
70 $this->select("group_id", "label=$parentGroupName");
71 $this->click("_qf_GroupContact_next");
72 $this->waitForPageToLoad($this->getTimeoutMsec());
74 // Adding child group contact
75 // We're using Quick Add block on the main page for this.
76 $childName = 'b' . substr(sha1(rand()), 0, 7);
77 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
79 $childSortName = "John, $childName";
80 $childDisplayName = "$childName John";
82 // Add contact to child group
84 $this->click("css=li#tab_group a");
85 $this->waitForElementPresent("group_id");
87 // Add to child group.
88 $this->select("group_id", "label=regexp:$childGroupName");
89 $this->click("_qf_GroupContact_next");
90 $this->waitForPageToLoad($this->getTimeoutMsec());
92 // Visit contact search page.
93 $this->open($this->sboxPath
. "civicrm/contact/search?reset=1");
94 $this->waitForPageToLoad($this->getTimeoutMsec());
96 // Select contact type as Indiividual.
97 $this->select("contact_type", "value=Individual");
100 $this->select("group", "label=$parentGroupName");
103 $this->click("_qf_Basic_refresh");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
106 // Is contact present in search result?
107 $this->assertTrue($this->isTextPresent("$sortName"), "Contact did not found in search result!");
109 // Is contact present in search result?
110 $this->assertTrue($this->isTextPresent("$childSortName"), "Contact did not found in search result!");
112 // select to export all the contasct from search result.
113 $this->click("CIVICRM_QFID_ts_all_4");
115 // Select the task action to export.
116 $this->click("task");
117 $this->select("task", "label=Export Contacts");
119 $this->waitForPageToLoad($this->getTimeoutMsec());
121 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
123 // Build header row for assertion.
124 require_once 'CRM/Contact/BAO/Contact.php';
125 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
127 $checkHeaders = array();
128 foreach ($expotableFields as $key => $field) {
129 // Exclude custom fields.
130 if ($key && (substr($key, 0, 6) == 'custom')) {
133 $checkHeaders[] = $field['title'];
136 // All other rows to be check.
139 'First Name' => $firstName,
140 'Last Name' => 'Smith',
141 'Email' => "$firstName.smith@example.org",
142 'Sort Name' => $sortName,
143 'Display Name' => $displayName,
146 'First Name' => $childName,
147 'Last Name' => 'John',
148 'Email' => "$childName.john@example.org",
149 'Sort Name' => $childSortName,
150 'Display Name' => $childDisplayName,
154 // Read CSV and fire assertions.
155 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
158 function testMergeHousehold() {
159 $this->open($this->sboxPath
);
161 // Logging in. Remember to wait for page to load. In most cases,
162 // you can rely on 30000 as the value that allows your test to pass, however,
163 // sometimes your test might fail because of this. In such cases, it's better to pick one element
164 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
165 // page contents loaded and you can continue your test execution.
166 $this->webtestLogin();
169 $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7);
170 $this->addContactGroup($groupName);
172 // Adding Parent group contact
173 // We're using Quick Add block on the main page for this.
174 $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House';
176 $this->open($this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Household');
177 $this->click('household_name');
178 $this->type('household_name', $houseHold);
181 $this->click("addressBlock");
182 $this->waitForElementPresent("address_1_street_address");
185 $this->click("//div[@id='addressBlockId']/div[1]");
186 $this->type("address_1_street_address", "121A Sherman St. Apt. 12");
187 $this->type("address_1_city", "Dumfries");
188 $this->type("address_1_postal_code", "1234");
189 $this->assertTrue($this->isTextPresent("- select - United States"));
190 $this->select("address_1_state_province_id", "value=1019");
192 $this->click('_qf_Contact_upload_view');
193 $this->waitForPageToLoad($this->getTimeoutMsec());
195 // Add contact to 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());
206 $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
207 $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
209 $sortName1 = "Smith, {$firstName1}";
210 $displayName1 = "{$firstName1} Smith";
212 // Add contact to parent group
214 $this->click("css=li#tab_group a");
215 $this->waitForElementPresent("group_id");
218 $this->select("group_id", "label=$groupName");
219 $this->click("_qf_GroupContact_next");
220 $this->waitForPageToLoad($this->getTimeoutMsec());
222 $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
224 $this->open($this->sboxPath
. 'civicrm/contact/add?reset=1&ct=Individual');
225 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
226 $this->type('first_name', $firstName2);
227 $this->type('last_name', "Smith");
228 $this->type('email_1_email', "{$firstName2}.smith@example.org");
231 $this->click("addressBlock");
232 $this->waitForElementPresent("address_1_street_address");
234 $this->click("//div[@id='addressBlockId']/div[1]");
236 $this->click("address[1][use_shared_address]");
237 $this->waitForElementPresent("contact_1");
238 $this->webtestFillAutocomplete($houseHold);
239 $this->waitForTextPresent("121A Sherman");
241 $this->click('_qf_Contact_upload_view-bottom');
242 $this->waitForPageToLoad($this->getTimeoutMsec());
244 $sortName2 = "Smith, {$firstName2}";
245 $displayName2 = "{$firstName2} Smith";
247 // Add contact to parent group
249 $this->click("css=li#tab_group a");
250 $this->waitForElementPresent("group_id");
253 $this->select("group_id", "label=$groupName");
254 $this->click("_qf_GroupContact_next");
255 $this->waitForPageToLoad($this->getTimeoutMsec());
257 $this->open($this->sboxPath
. "civicrm/contact/search?reset=1");
258 $this->waitForPageToLoad($this->getTimeoutMsec());
261 $this->select("group", "label=$groupName");
264 $this->click("_qf_Basic_refresh");
265 $this->waitForPageToLoad($this->getTimeoutMsec());
267 // Is contact present in search result?
268 $this->assertTrue($this->isTextPresent("$sortName1"), "Contact did not found in search result!");
270 // Is contact present in search result?
271 $this->assertTrue($this->isTextPresent("$sortName2"), "Contact did not found in search result!");
273 // Is contact present in search result?
274 $this->assertTrue($this->isTextPresent("$houseHold"), "Contact did not found in search result!");
276 // select to export all the contasct from search result.
277 $this->click("CIVICRM_QFID_ts_all_4");
279 // Select the task action to export.
280 $this->click("task");
281 $this->select("task", "label=Export Contacts");
283 $this->waitForPageToLoad($this->getTimeoutMsec());
285 $this->click("CIVICRM_QFID_2_10");
287 $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
289 // Build header row for assertion.
290 require_once 'CRM/Contact/BAO/Contact.php';
291 $expotableFields = CRM_Contact_BAO_Contact
::exportableFields('All', FALSE, TRUE);
293 $checkHeaders = array();
294 foreach ($expotableFields as $key => $field) {
295 // Exclude custom fields.
296 if ($key && (substr($key, 0, 6) == 'custom')) {
299 $checkHeaders[] = $field['title'];
302 // All other rows to be check.
305 'Contact Type' => 'Household',
306 'Household Name' => $houseHold,
309 'Contact Type' => 'Individual',
310 'First Name' => $firstName1,
311 'Email' => "{$firstName1}.smith@example.org",
312 'Sort Name' => $sortName1,
313 'Display Name' => $displayName1,
317 // Read CSV and fire assertions.
318 $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
321 function addContactGroup($groupName = 'New Group', $parentGroupName = "- select -") {
322 $this->open($this->sboxPath
. "civicrm/group/add?reset=1");
324 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
325 // button at the end of this page to show up, to make sure it's fully loaded.
326 $this->waitForElementPresent("_qf_Edit_upload");
329 $this->type("title", $groupName);
332 $this->type("description", "Adding new group.");
334 // Check Access Control.
335 $this->click("group_type[1]");
337 // Check Mailing List.
338 $this->click("group_type[2]");
340 // Select Visibility as Public Pages.
341 $this->select("visibility", "value=Public Pages");
343 // Select parent group.
344 $this->select("parents", "label=$parentGroupName");
347 $this->click("_qf_Edit_upload");
348 $this->waitForPageToLoad($this->getTimeoutMsec());
350 // Is status message correct?
351 $this->assertTrue($this->isTextPresent("The Group '$groupName' has been saved."));