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 | ||
6a488035 TO |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
6a488035 | 34 | function testSearchBuilderOptions() { |
6a488035 TO |
35 | $this->webtestLogin(); |
36 | ||
37 | $groupName = $this->WebtestAddGroup(); | |
38 | ||
39 | // Open the search builder | |
40 | $this->openCiviPage('contact/search/builder', 'reset=1'); | |
41 | ||
42 | $this->enterValues(1, 1, 'Contacts', 'Group(s)', NULL, '=', array($groupName)); | |
43 | $this->enterValues(1, 2, 'Contacts', 'Country', NULL, '=', array('United States')); | |
44 | $this->enterValues(1, 3, 'Individual', 'Gender', NULL, '=', array('Male')); | |
45 | $this->click('_qf_Builder_refresh'); | |
46 | $this->waitForPageToLoad(); | |
47 | ||
48 | // We should get no results. But check the options are all still set | |
49 | $this->waitForTextPresent('No matches found'); | |
50 | foreach (array($groupName, 'United States', 'Male') as $i => $label) { | |
51 | $this->waitForElementPresent("//span[@id='crm_search_value_1_$i']/select/option[2]"); | |
52 | $this->assertSelectedLabel("//span[@id='crm_search_value_1_$i']/select", $label); | |
53 | } | |
54 | } | |
55 | ||
56 | function testSearchBuilderRLIKE() { | |
57 | $this->webtestLogin(); | |
58 | ||
59 | // Adding contact | |
60 | // We're using Quick Add block on the main page for this. | |
61 | $firstName = substr(sha1(rand()), 0, 7); | |
62 | $this->createDetailContact($firstName); | |
63 | ||
64 | $sortName = "adv$firstName, $firstName"; | |
65 | $displayName = "$firstName adv$firstName"; | |
66 | ||
67 | $this->_searchBuilder("Postal Code", "100[0-9]", $sortName, "RLIKE"); | |
68 | } | |
69 | ||
70 | // function to create contact with details (contact details, address, Constituent information ...) | |
71 | function createDetailContact($firstName = NULL) { | |
72 | ||
73 | if (!$firstName) { | |
74 | $firstName = substr(sha1(rand()), 0, 7); | |
75 | } | |
76 | ||
77 | // create contact type Individual with subtype | |
78 | // with most of values to required to search | |
79 | $Subtype = "Student"; | |
80 | $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => 'Individual'), '_qf_Contact_cancel'); | |
81 | ||
82 | // --- fill few values in Contact Detail block | |
83 | $this->type("first_name", "$firstName"); | |
84 | $this->type("middle_name", "mid$firstName"); | |
85 | $this->type("last_name", "adv$firstName"); | |
86 | $this->select("contact_sub_type", "label=- $Subtype"); | |
87 | $this->type("email_1_email", "$firstName@advsearch.co.in"); | |
88 | $this->type("phone_1_phone", "123456789"); | |
89 | $this->type("external_identifier", "extid$firstName"); | |
90 | ||
91 | // --- fill few values in address | |
92 | $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]"); | |
93 | $this->waitForElementPresent("address_1_geo_code_2"); | |
94 | $this->type("address_1_street_address", "street 1 $firstName"); | |
95 | $this->type("address_1_supplemental_address_1", "street supplement 1 $firstName"); | |
96 | $this->type("address_1_supplemental_address_2", "street supplement 2 $firstName"); | |
97 | $this->type("address_1_city", "city$firstName"); | |
98 | $this->type("address_1_postal_code", "100100"); | |
99 | $this->select("address_1_country_id", "United States"); | |
100 | $this->select("address_1_state_province_id", "Alaska"); | |
101 | ||
102 | // save contact | |
103 | $this->click("_qf_Contact_upload_view"); | |
104 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
105 | $this->assertTrue($this->isTextPresent("$firstName adv$firstName")); | |
106 | } | |
107 | ||
108 | function testSearchBuilderContacts(){ | |
6a488035 TO |
109 | $this->webtestLogin(); |
110 | ||
111 | //Individual | |
112 | $firstName = substr(sha1(rand()), 0, 7); | |
113 | $streetName = "street $firstName"; | |
114 | $sortName = "adv$firstName, $firstName"; | |
115 | $this->_createContact('Individual', $firstName, "$firstName@advsearch.co.in", $streetName); | |
116 | // search using search builder and advanced search | |
117 | $this->_searchBuilder('Street Address', $streetName, $sortName, '=', '1'); | |
118 | $this->_advancedSearch($streetName, $sortName, 'Individual', '1', 'street_address'); | |
119 | ||
120 | //Organization | |
121 | $orgName = substr(sha1(rand()), 0, 7)."org"; | |
122 | $orgEmail = "ab".rand()."@{$orgName}.com"; | |
123 | $this->_createContact('Organization', $orgName, $orgEmail,"street $orgName"); | |
124 | // search using search builder and advanced search | |
125 | $this->_searchBuilder('Email',$orgEmail, $orgName,'=','1'); | |
126 | $this->_advancedSearch($orgEmail, $orgName, 'Organization','1','email'); | |
127 | ||
128 | //Household | |
129 | $householdName = "household".substr(sha1(rand()), 0, 7); | |
130 | $householdEmail = "h1".rand()."@{$householdName}.com"; | |
131 | $this->_createContact('Household', $householdName, $householdEmail,"street $householdName"); | |
132 | // search using search builder and advanced search | |
133 | $this->_searchBuilder('Email',$householdEmail, $householdName,'=','1'); | |
134 | $this->_advancedSearch($householdEmail, $householdName, 'Household','1','email'); | |
135 | ||
289c8051 | 136 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
137 | |
138 | // searching contacts whose email is not set | |
139 | $firstName1 = "00a1".substr(sha1(rand()), 0, 7); | |
140 | $this->type("first_name", $firstName1); | |
141 | $this->type("last_name", "01adv$firstName1"); | |
142 | // save contact | |
143 | $this->click("_qf_Contact_upload_view"); | |
144 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
289c8051 | 145 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
146 | |
147 | $firstName2 = "00a2".substr(sha1(rand()), 0, 7); | |
148 | $this->type("first_name", $firstName2); | |
149 | $this->type("last_name", "02adv$firstName2"); | |
150 | // save contact | |
151 | $this->click("_qf_Contact_upload_view"); | |
152 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
289c8051 | 153 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
6a488035 TO |
154 | |
155 | $firstName3 = "00a3".substr(sha1(rand()), 0, 7); | |
156 | $this->type("first_name", $firstName3); | |
157 | $this->type("last_name", "03adv$firstName3"); | |
158 | // save contact | |
159 | $this->click("_qf_Contact_upload_view"); | |
160 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
161 | $this->_searchBuilder('Email',NULL,NULL,'IS NULL'); | |
162 | $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]"); | |
163 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
164 | $names = array( 1 => $firstName1, | |
165 | 2 => $firstName2, | |
166 | 3 => $firstName3, | |
167 | ); | |
168 | foreach($names as $key => $value){ | |
169 | $this->assertTrue($this->isTextPresent($value)); | |
170 | } | |
171 | //searching contacts whose phone field is empty | |
172 | $this->_searchBuilder('Phone',NULL,NULL,'IS EMPTY'); | |
173 | foreach($names as $key => $value){ | |
174 | $this->assertTrue($this->isTextPresent($value)); | |
175 | } | |
176 | //searching contacts whose phone field is not empty | |
177 | $this->_searchBuilder('Phone',NULL,$firstName,'IS NOT EMPTY'); | |
178 | $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]"); | |
179 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
180 | $this->assertTrue($this->isTextPresent($firstName)); | |
181 | ||
182 | $firstName4 = "AB".substr(sha1(rand()), 0, 7); | |
183 | $postalCode = rand(); | |
184 | $this->_createContact('Individual', $firstName4,"$firstName4@advsearch.co.in",NULL, $postalCode); | |
185 | $firstName5 = "CD".substr(sha1(rand()), 0, 7); | |
186 | $this->_createContact('Individual', $firstName5,"$firstName5@advsearch.co.in",NULL, $postalCode); | |
187 | $firstName6 = "EF".substr(sha1(rand()), 0, 7); | |
188 | $this->_createContact('Organization', $firstName6,"$firstName6@advsearch.co.in",NULL, $postalCode); | |
189 | $firstName7 = "GH".substr(sha1(rand()), 0, 7); | |
190 | $this->_createContact('Household', $firstName7,"$firstName7@advsearch.co.in",NULL, $postalCode); | |
191 | ||
192 | // check if the resultset of search builder and advanced search match for the postal code | |
193 | $this->_searchBuilder('Postal Code',$postalCode,NULL,'LIKE','4'); | |
194 | $this->_advancedSearch($postalCode,NULL,NULL,'4','postal_code'); | |
195 | ||
196 | $firstName8 = "abcc".substr(sha1(rand()), 0, 7); | |
197 | $this->_createContact('Individual', $firstName8,"$firstName8@advsearch.co.in",NULL); | |
198 | $this->_searchBuilder('Note(s): Body and Subject', "this is subject by $firstName8", $firstName8, 'LIKE'); | |
199 | $this->_searchBuilder('Note(s): Body and Subject', "this is notes by $firstName8", $firstName8, 'LIKE'); | |
200 | $this->_searchBuilder('Note(s): Subject only', "this is subject by $firstName8", $firstName8, 'LIKE'); | |
201 | $this->_searchBuilder('Note(s): Body only', "this is notes by $firstName8", $firstName8, 'LIKE'); | |
202 | $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_body', 'notes'); | |
203 | $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_subject', 'notes'); | |
204 | $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes'); | |
205 | $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes'); | |
206 | } | |
207 | ||
208 | function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) { | |
209 | // search builder using contacts(not using contactType) | |
289c8051 | 210 | $this->openCiviPage("contact/search/builder", "reset=1"); |
6a488035 TO |
211 | $this->enterValues(1, 1, 'Contacts', $field, NULL, $op, "$fieldValue"); |
212 | $this->click("id=_qf_Builder_refresh"); | |
213 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
214 | if (($op == '=' || $op == 'LIKE') && $fieldValue) { | |
215 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$fieldValue"); | |
216 | } | |
217 | if ($name) { | |
218 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name"); | |
219 | } | |
220 | if ($count) { | |
221 | $this->assertElementContainsText('search-status', "$count Contact"); | |
222 | } | |
223 | } | |
224 | ||
225 | /** | |
226 | * Enter form values in a Search Builder row | |
227 | */ | |
228 | function enterValues($set, $row, $entity, $field, $loc, $op, $value = '') { | |
229 | if ($set > 1 && $row == 1) { | |
230 | $this->click('addBlock'); | |
231 | } | |
232 | if ($row > 1) { | |
233 | $this->click("addMore_{$set}"); | |
234 | } | |
235 | // In the DOM rows are 0 indexed and sets are 1 indexed, so normalizing | |
236 | $row--; | |
237 | ||
238 | $this->waitForElementPresent("mapper_{$set}_{$row}_0"); | |
239 | $this->select("mapper_{$set}_{$row}_0", "label=$entity"); | |
240 | $this->select("mapper_{$set}_{$row}_1", "label=$field"); | |
241 | if ($loc) { | |
242 | $this->select("mapper_{$set}_{$row}_2", "label=$loc"); | |
243 | } | |
244 | $this->select("operator_{$set}_{$row}", "label=$op"); | |
245 | if (is_array($value)) { | |
246 | $this->waitForElementPresent("css=#crm_search_value_{$set}_{$row} select option + option"); | |
247 | foreach ($value as $val) { | |
289c8051 | 248 | if ($op != 'IN') { |
76e86fd8 CW |
249 | $select = 'select'; |
250 | ||
289c8051 PN |
251 | } |
252 | else { | |
76e86fd8 CW |
253 | $select = 'addSelection'; |
254 | ||
289c8051 PN |
255 | } |
256 | $this->$select("css=#crm_search_value_{$set}_{$row} select", "label=$val"); | |
6a488035 TO |
257 | } |
258 | } | |
259 | elseif ($value && substr($value, 0, 5) == 'date:') { | |
260 | $this->webtestFillDate("value_{$set}_{$row}", trim(substr($value, 5))); | |
261 | } | |
262 | elseif ($value) { | |
263 | $this->type("value_{$set}_{$row}", $value); | |
264 | } | |
265 | } | |
266 | ||
267 | function _advancedSearch($fieldValue = NULL, $name = NULL, $contactType = NULL, $count = NULL, $field){ | |
268 | //advanced search by selecting the contactType | |
289c8051 | 269 | $this->openCiviPage("contact/search/advanced", "reset=1"); |
6a488035 TO |
270 | if (isset($contactType)){ |
271 | $this->select("id=crmasmSelect0", "value=$contactType"); | |
272 | } | |
273 | if (substr($field, 0, 5) == 'note_') { | |
274 | $this->click("notes"); | |
275 | $this->waitForElementPresent("xpath=//div[@id='notes-search']/table/tbody/tr/td[2]/input[3]"); | |
276 | if ($field == 'note_body') { | |
277 | $this->click("CIVICRM_QFID_2_note_option"); | |
278 | } | |
279 | elseif ($field == 'note_subject') { | |
280 | $this->click("CIVICRM_QFID_3_note_option"); | |
281 | } | |
282 | else { | |
283 | $this->click("CIVICRM_QFID_6_note_option"); | |
284 | } | |
285 | $this->type("note",$fieldValue ); | |
286 | } | |
287 | else { | |
288 | $this->click("location"); | |
289 | $this->waitForElementPresent("xpath=//div[@id='location']/table/tbody/tr[2]/td/table/tbody/tr[4]/td[2]/select"); | |
290 | if ($contactType == 'Individual') { | |
291 | $this->type("$field",$fieldValue ); | |
292 | } | |
293 | else { | |
294 | $this->type("$field",$fieldValue); | |
295 | } | |
296 | } | |
297 | $this->click("_qf_Advanced_refresh"); | |
298 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
299 | ||
300 | //the search result should be same as the one that we got in search builder | |
301 | if ($fieldValue) { | |
302 | $this->assertElementContainsText('Advanced', "$fieldValue"); | |
303 | } | |
304 | if ($name) { | |
305 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name"); | |
306 | } | |
307 | if ($count) { | |
308 | $this->assertElementContainsText('search-status', "$count Contact"); | |
309 | } | |
310 | } | |
311 | ||
312 | function _createContact($contactType, $name, $email, $streetName = NULL, $postalCode = NULL){ | |
313 | $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => $contactType), '_qf_Contact_cancel'); | |
314 | ||
315 | if ($contactType == 'Individual'){ | |
316 | $this->type("first_name", "$name"); | |
317 | $this->type("last_name", "adv$name"); | |
318 | $name = "$name adv$name"; | |
319 | } elseif ($contactType == 'Organization') { | |
320 | $this->type("organization_name",$name); | |
321 | } else { | |
322 | $this->type("household_name",$name); | |
323 | } | |
324 | $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]"); | |
325 | $this->waitForElementPresent("address_1_geo_code_2"); | |
326 | $this->type("email_1_email",$email); | |
327 | $this->type("phone_1_phone","9876543210"); | |
328 | $this->type("address_1_street_address", $streetName); | |
329 | $this->select("address_1_country_id", "United States"); | |
330 | $this->select("address_1_state_province_id", "Alaska"); | |
331 | $this->type("address_1_postal_code",$postalCode); | |
332 | ||
333 | $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]"); | |
334 | $this->waitForElementPresent("note"); | |
335 | $this->type("subject", "this is subject by $name"); | |
336 | $this->type("note", "this is notes by $name"); | |
337 | ||
338 | // save contact | |
339 | $this->click("_qf_Contact_upload_view"); | |
340 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
341 | $this->assertTrue($this->isTextPresent("$name has been created.")); | |
342 | } | |
289c8051 PN |
343 | |
344 | /* | |
345 | * Webtest for CRM-12148 | |
346 | * | |
347 | */ | |
348 | function testSearchBuilderfinancialType() { | |
349 | // Logging in. Remember to wait for page to load. In most cases, | |
350 | // you can rely on 30000 as the value that allows your test to pass, however, | |
351 | // sometimes your test might fail because of this. In such cases, it's better to pick one element | |
352 | // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole | |
353 | // page contents loaded and you can continue your test execution. | |
354 | $this->webtestLogin(); | |
76e86fd8 | 355 | |
289c8051 PN |
356 | // add financial type |
357 | $financialTypeName1 = 'Financial Type' . substr(sha1(rand()), 0, 5);; | |
358 | $financialTypeName2 = 'Financial Type' . substr(sha1(rand()), 0, 5);; | |
359 | $financialType = array( | |
360 | 'name' => $financialTypeName1, | |
361 | 'is_reserved' => FALSE, | |
362 | 'is_deductible' => FALSE, | |
363 | ); | |
364 | $this->addeditFinancialType($financialType); | |
289c8051 PN |
365 | $financialType['name'] = $financialTypeName2; |
366 | $this->addeditFinancialType($financialType); | |
289c8051 PN |
367 | //create 6 contribution |
368 | $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", "_qf_Contribution_upload"); | |
369 | for ($i = 1; $i <= 6; $i++) { | |
370 | if ($i % 2 == 0) { | |
371 | $financialType = $financialTypeName1; | |
372 | } | |
373 | else { | |
374 | $financialType = $financialTypeName2; | |
375 | } | |
376 | // create new contact using dialog | |
377 | $firstName = substr(sha1(rand()), 0, 7); | |
378 | $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com'); | |
379 | $this->select('financial_type_id', $financialType); | |
380 | $this->type('total_amount', 100 * $i); | |
225a8648 | 381 | $this->clickLink('_qf_Contribution_upload_new', '_qf_Contribution_upload_new'); |
289c8051 PN |
382 | } |
383 | $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh"); | |
76e86fd8 | 384 | |
289c8051 PN |
385 | $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1)); |
386 | $this->click('_qf_Builder_refresh'); | |
387 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
76e86fd8 | 388 | |
289c8051 | 389 | $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts'); |
76e86fd8 | 390 | |
289c8051 PN |
391 | $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); |
392 | $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2)); | |
393 | $this->click('_qf_Builder_refresh'); | |
394 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
395 | $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts'); | |
76e86fd8 | 396 | |
289c8051 PN |
397 | $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']"); |
398 | $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, 'IN', array($financialTypeName1, $financialTypeName2)); | |
399 | $this->click('_qf_Builder_refresh'); | |
400 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
401 | $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts'); | |
402 | } | |
6a488035 | 403 | } |