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