Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | ||
28 | require_once 'WebTest/Export/ExportCiviSeleniumTestCase.php'; | |
29 | class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | /** | |
36 | * Test Contact Export. | |
37 | */ | |
38 | function testContactExport() { | |
39 | $this->open($this->sboxPath); | |
40 | ||
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(); | |
47 | ||
48 | // Create new group | |
49 | $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7); | |
50 | $this->addContactGroup($parentGroupName); | |
51 | ||
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); | |
55 | ||
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"); | |
60 | ||
61 | $sortName = "Smith, $firstName"; | |
62 | $displayName = "$firstName Smith"; | |
63 | ||
64 | // Add contact to parent group | |
65 | // visit group tab. | |
66 | $this->click("css=li#tab_group a"); | |
67 | $this->waitForElementPresent("group_id"); | |
68 | ||
69 | // Add to group. | |
70 | $this->select("group_id", "label=$parentGroupName"); | |
71 | $this->click("_qf_GroupContact_next"); | |
72 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
73 | ||
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"); | |
78 | ||
79 | $childSortName = "John, $childName"; | |
80 | $childDisplayName = "$childName John"; | |
81 | ||
82 | // Add contact to child group | |
83 | // visit group tab. | |
84 | $this->click("css=li#tab_group a"); | |
85 | $this->waitForElementPresent("group_id"); | |
86 | ||
87 | // Add to child group. | |
88 | $this->select("group_id", "label=regexp:$childGroupName"); | |
89 | $this->click("_qf_GroupContact_next"); | |
90 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
91 | ||
92 | // Visit contact search page. | |
cb5b38f1 | 93 | $this->openCiviPage("contact/search", "reset=1"); |
6a488035 TO |
94 | |
95 | // Select contact type as Indiividual. | |
96 | $this->select("contact_type", "value=Individual"); | |
97 | ||
98 | // Select group. | |
99 | $this->select("group", "label=$parentGroupName"); | |
100 | ||
101 | // Click to search. | |
102 | $this->click("_qf_Basic_refresh"); | |
103 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
104 | ||
105 | // Is contact present in search result? | |
106 | $this->assertTrue($this->isTextPresent("$sortName"), "Contact did not found in search result!"); | |
107 | ||
108 | // Is contact present in search result? | |
109 | $this->assertTrue($this->isTextPresent("$childSortName"), "Contact did not found in search result!"); | |
110 | ||
111 | // select to export all the contasct from search result. | |
112 | $this->click("CIVICRM_QFID_ts_all_4"); | |
113 | ||
114 | // Select the task action to export. | |
115 | $this->click("task"); | |
116 | $this->select("task", "label=Export Contacts"); | |
117 | $this->click("Go"); | |
118 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
119 | ||
120 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); | |
121 | ||
122 | // Build header row for assertion. | |
123 | require_once 'CRM/Contact/BAO/Contact.php'; | |
124 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); | |
125 | ||
126 | $checkHeaders = array(); | |
127 | foreach ($expotableFields as $key => $field) { | |
128 | // Exclude custom fields. | |
129 | if ($key && (substr($key, 0, 6) == 'custom')) { | |
130 | continue; | |
131 | } | |
132 | $checkHeaders[] = $field['title']; | |
133 | } | |
134 | ||
135 | // All other rows to be check. | |
136 | $checkRows = array( | |
137 | 1 => array( | |
138 | 'First Name' => $firstName, | |
139 | 'Last Name' => 'Smith', | |
140 | 'Email' => "$firstName.smith@example.org", | |
141 | 'Sort Name' => $sortName, | |
142 | 'Display Name' => $displayName, | |
143 | ), | |
144 | 2 => array( | |
145 | 'First Name' => $childName, | |
146 | 'Last Name' => 'John', | |
147 | 'Email' => "$childName.john@example.org", | |
148 | 'Sort Name' => $childSortName, | |
149 | 'Display Name' => $childDisplayName, | |
150 | ), | |
151 | ); | |
152 | ||
153 | // Read CSV and fire assertions. | |
154 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); | |
155 | } | |
156 | ||
157 | function testMergeHousehold() { | |
158 | $this->open($this->sboxPath); | |
159 | ||
160 | // Logging in. Remember to wait for page to load. In most cases, | |
161 | // you can rely on 30000 as the value that allows your test to pass, however, | |
162 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
163 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
164 | // page contents loaded and you can continue your test execution. | |
165 | $this->webtestLogin(); | |
166 | ||
167 | // Create new group | |
168 | $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7); | |
169 | $this->addContactGroup($groupName); | |
170 | ||
171 | // Adding Parent group contact | |
172 | // We're using Quick Add block on the main page for this. | |
173 | $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House'; | |
174 | ||
cb5b38f1 | 175 | $this->openCiviPage("contact/add", "reset=1&ct=Household"); |
6a488035 TO |
176 | $this->click('household_name'); |
177 | $this->type('household_name', $houseHold); | |
178 | ||
179 | //address section | |
180 | $this->click("addressBlock"); | |
181 | $this->waitForElementPresent("address_1_street_address"); | |
182 | ||
183 | // fill in address | |
184 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
185 | $this->type("address_1_street_address", "121A Sherman St. Apt. 12"); | |
186 | $this->type("address_1_city", "Dumfries"); | |
187 | $this->type("address_1_postal_code", "1234"); | |
188 | $this->assertTrue($this->isTextPresent("- select - United States")); | |
189 | $this->select("address_1_state_province_id", "value=1019"); | |
190 | ||
191 | $this->click('_qf_Contact_upload_view'); | |
192 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
193 | ||
194 | // Add contact to group | |
195 | // visit group tab. | |
196 | $this->click("css=li#tab_group a"); | |
197 | $this->waitForElementPresent("group_id"); | |
198 | ||
199 | // Add to group. | |
200 | $this->select("group_id", "label=$groupName"); | |
201 | $this->click("_qf_GroupContact_next"); | |
202 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
203 | ||
204 | ||
205 | $firstName1 = 'aa' . substr(sha1(rand()), 0, 5); | |
206 | $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org"); | |
207 | ||
208 | $sortName1 = "Smith, {$firstName1}"; | |
209 | $displayName1 = "{$firstName1} Smith"; | |
210 | ||
211 | // Add contact to parent group | |
212 | // visit group tab. | |
213 | $this->click("css=li#tab_group a"); | |
214 | $this->waitForElementPresent("group_id"); | |
215 | ||
216 | // Add to group. | |
217 | $this->select("group_id", "label=$groupName"); | |
218 | $this->click("_qf_GroupContact_next"); | |
219 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
220 | ||
221 | $firstName2 = 'bb' . substr(sha1(rand()), 0, 5); | |
222 | ||
cb5b38f1 | 223 | $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom"); |
6a488035 TO |
224 | $this->type('first_name', $firstName2); |
225 | $this->type('last_name', "Smith"); | |
226 | $this->type('email_1_email', "{$firstName2}.smith@example.org"); | |
227 | ||
228 | //address section | |
229 | $this->click("addressBlock"); | |
230 | $this->waitForElementPresent("address_1_street_address"); | |
231 | ||
232 | $this->click("//div[@id='addressBlockId']/div[1]"); | |
233 | ||
234 | $this->click("address[1][use_shared_address]"); | |
235 | $this->waitForElementPresent("contact_1"); | |
236 | $this->webtestFillAutocomplete($houseHold); | |
237 | $this->waitForTextPresent("121A Sherman"); | |
238 | ||
239 | $this->click('_qf_Contact_upload_view-bottom'); | |
240 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
241 | ||
242 | $sortName2 = "Smith, {$firstName2}"; | |
243 | $displayName2 = "{$firstName2} Smith"; | |
244 | ||
245 | // Add contact to parent group | |
246 | // visit group tab. | |
247 | $this->click("css=li#tab_group a"); | |
248 | $this->waitForElementPresent("group_id"); | |
249 | ||
250 | // Add to group. | |
251 | $this->select("group_id", "label=$groupName"); | |
252 | $this->click("_qf_GroupContact_next"); | |
253 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
254 | ||
cb5b38f1 | 255 | $this->openCiviPage("contact/search", "reset=1"); |
6a488035 TO |
256 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
257 | ||
258 | // Select group. | |
259 | $this->select("group", "label=$groupName"); | |
260 | ||
261 | // Click to search. | |
262 | $this->click("_qf_Basic_refresh"); | |
263 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
264 | ||
265 | // Is contact present in search result? | |
266 | $this->assertTrue($this->isTextPresent("$sortName1"), "Contact did not found in search result!"); | |
267 | ||
268 | // Is contact present in search result? | |
269 | $this->assertTrue($this->isTextPresent("$sortName2"), "Contact did not found in search result!"); | |
270 | ||
271 | // Is contact present in search result? | |
272 | $this->assertTrue($this->isTextPresent("$houseHold"), "Contact did not found in search result!"); | |
273 | ||
274 | // select to export all the contasct from search result. | |
275 | $this->click("CIVICRM_QFID_ts_all_4"); | |
276 | ||
277 | // Select the task action to export. | |
278 | $this->click("task"); | |
279 | $this->select("task", "label=Export Contacts"); | |
280 | $this->click("Go"); | |
281 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
282 | ||
283 | $this->click("CIVICRM_QFID_2_10"); | |
284 | ||
285 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); | |
286 | ||
287 | // Build header row for assertion. | |
288 | require_once 'CRM/Contact/BAO/Contact.php'; | |
289 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); | |
290 | ||
291 | $checkHeaders = array(); | |
292 | foreach ($expotableFields as $key => $field) { | |
293 | // Exclude custom fields. | |
294 | if ($key && (substr($key, 0, 6) == 'custom')) { | |
295 | continue; | |
296 | } | |
297 | $checkHeaders[] = $field['title']; | |
298 | } | |
299 | ||
300 | // All other rows to be check. | |
301 | $checkRows = array( | |
302 | 1 => array( | |
303 | 'Contact Type' => 'Household', | |
304 | 'Household Name' => $houseHold, | |
305 | ), | |
306 | 2 => array( | |
307 | 'Contact Type' => 'Individual', | |
308 | 'First Name' => $firstName1, | |
309 | 'Email' => "{$firstName1}.smith@example.org", | |
310 | 'Sort Name' => $sortName1, | |
311 | 'Display Name' => $displayName1, | |
312 | ), | |
313 | ); | |
314 | ||
315 | // Read CSV and fire assertions. | |
316 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); | |
317 | } | |
318 | ||
319 | function addContactGroup($groupName = 'New Group', $parentGroupName = "- select -") { | |
cb5b38f1 | 320 | $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload"); |
6a488035 TO |
321 | |
322 | // Fill group name. | |
323 | $this->type("title", $groupName); | |
324 | ||
325 | // Fill description. | |
326 | $this->type("description", "Adding new group."); | |
327 | ||
328 | // Check Access Control. | |
329 | $this->click("group_type[1]"); | |
330 | ||
331 | // Check Mailing List. | |
332 | $this->click("group_type[2]"); | |
333 | ||
334 | // Select Visibility as Public Pages. | |
335 | $this->select("visibility", "value=Public Pages"); | |
336 | ||
337 | // Select parent group. | |
338 | $this->select("parents", "label=$parentGroupName"); | |
339 | ||
340 | // Clicking save. | |
341 | $this->click("_qf_Edit_upload"); | |
342 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
343 | ||
344 | // Is status message correct? | |
345 | $this->assertTrue($this->isTextPresent("The Group '$groupName' has been saved.")); | |
346 | } | |
347 | } | |
348 |