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 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_SearchBuilderTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
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();
44 $groupName = $this->WebtestAddGroup();
46 // Open the search builder
47 $this->openCiviPage('contact/search/builder', 'reset=1');
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();
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);
63 function testSearchBuilderRLIKE() {
64 $this->webtestLogin();
67 // We're using Quick Add block on the main page for this.
68 $firstName = substr(sha1(rand()), 0, 7);
69 $this->createDetailContact($firstName);
71 $sortName = "adv$firstName, $firstName";
72 $displayName = "$firstName adv$firstName";
74 $this->_searchBuilder("Postal Code", "100[0-9]", $sortName, "RLIKE");
77 // function to create contact with details (contact details, address, Constituent information ...)
78 function createDetailContact($firstName = NULL) {
81 $firstName = substr(sha1(rand()), 0, 7);
84 // create contact type Individual with subtype
85 // with most of values to required to search
87 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => 'Individual'), '_qf_Contact_cancel');
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");
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");
110 $this->click("_qf_Contact_upload_view");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
112 $this->assertTrue($this->isTextPresent("$firstName adv$firstName"));
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();
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');
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');
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');
148 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
150 // searching contacts whose email is not set
151 $firstName1 = "00a1".substr(sha1(rand()), 0, 7);
152 $this->type("first_name", $firstName1);
153 $this->type("last_name", "01adv$firstName1");
155 $this->click("_qf_Contact_upload_view");
156 $this->waitForPageToLoad($this->getTimeoutMsec());
157 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
159 $firstName2 = "00a2".substr(sha1(rand()), 0, 7);
160 $this->type("first_name", $firstName2);
161 $this->type("last_name", "02adv$firstName2");
163 $this->click("_qf_Contact_upload_view");
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
167 $firstName3 = "00a3".substr(sha1(rand()), 0, 7);
168 $this->type("first_name", $firstName3);
169 $this->type("last_name", "03adv$firstName3");
171 $this->click("_qf_Contact_upload_view");
172 $this->waitForPageToLoad($this->getTimeoutMsec());
173 $this->_searchBuilder('Email',NULL,NULL,'IS NULL');
174 $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
175 $this->waitForPageToLoad($this->getTimeoutMsec());
176 $names = array( 1 => $firstName1,
180 foreach($names as $key => $value){
181 $this->assertTrue($this->isTextPresent($value));
183 //searching contacts whose phone field is empty
184 $this->_searchBuilder('Phone',NULL,NULL,'IS EMPTY');
185 foreach($names as $key => $value){
186 $this->assertTrue($this->isTextPresent($value));
188 //searching contacts whose phone field is not empty
189 $this->_searchBuilder('Phone',NULL,$firstName,'IS NOT EMPTY');
190 $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
191 $this->waitForPageToLoad($this->getTimeoutMsec());
192 $this->assertTrue($this->isTextPresent($firstName));
194 $firstName4 = "AB".substr(sha1(rand()), 0, 7);
195 $postalCode = rand();
196 $this->_createContact('Individual', $firstName4,"$firstName4@advsearch.co.in",NULL, $postalCode);
197 $firstName5 = "CD".substr(sha1(rand()), 0, 7);
198 $this->_createContact('Individual', $firstName5,"$firstName5@advsearch.co.in",NULL, $postalCode);
199 $firstName6 = "EF".substr(sha1(rand()), 0, 7);
200 $this->_createContact('Organization', $firstName6,"$firstName6@advsearch.co.in",NULL, $postalCode);
201 $firstName7 = "GH".substr(sha1(rand()), 0, 7);
202 $this->_createContact('Household', $firstName7,"$firstName7@advsearch.co.in",NULL, $postalCode);
204 // check if the resultset of search builder and advanced search match for the postal code
205 $this->_searchBuilder('Postal Code',$postalCode,NULL,'LIKE','4');
206 $this->_advancedSearch($postalCode,NULL,NULL,'4','postal_code');
208 $firstName8 = "abcc".substr(sha1(rand()), 0, 7);
209 $this->_createContact('Individual', $firstName8,"$firstName8@advsearch.co.in",NULL);
210 $this->_searchBuilder('Note(s): Body and Subject', "this is subject by $firstName8", $firstName8, 'LIKE');
211 $this->_searchBuilder('Note(s): Body and Subject', "this is notes by $firstName8", $firstName8, 'LIKE');
212 $this->_searchBuilder('Note(s): Subject only', "this is subject by $firstName8", $firstName8, 'LIKE');
213 $this->_searchBuilder('Note(s): Body only', "this is notes by $firstName8", $firstName8, 'LIKE');
214 $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_body', 'notes');
215 $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_subject', 'notes');
216 $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes');
217 $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes');
220 function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) {
221 // search builder using contacts(not using contactType)
222 $this->openCiviPage("contact/search/builder", "reset=1");
223 $this->enterValues(1, 1, 'Contacts', $field, NULL, $op, "$fieldValue");
224 $this->click("id=_qf_Builder_refresh");
225 $this->waitForPageToLoad($this->getTimeoutMsec());
226 if (($op == '=' ||
$op == 'LIKE') && $fieldValue) {
227 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$fieldValue");
230 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name");
233 $this->assertElementContainsText('search-status', "$count Contact");
238 * Enter form values in a Search Builder row
240 function enterValues($set, $row, $entity, $field, $loc, $op, $value = '') {
241 if ($set > 1 && $row == 1) {
242 $this->click('addBlock');
245 $this->click("addMore_{$set}");
247 // In the DOM rows are 0 indexed and sets are 1 indexed, so normalizing
250 $this->waitForElementPresent("mapper_{$set}_{$row}_0");
251 $this->select("mapper_{$set}_{$row}_0", "label=$entity");
252 $this->select("mapper_{$set}_{$row}_1", "label=$field");
254 $this->select("mapper_{$set}_{$row}_2", "label=$loc");
256 $this->select("operator_{$set}_{$row}", "label=$op");
257 if (is_array($value)) {
258 $this->waitForElementPresent("css=#crm_search_value_{$set}_{$row} select option + option");
259 foreach ($value as $val) {
264 $select = 'addSelection';
266 $this->$select("css=#crm_search_value_{$set}_{$row} select", "label=$val");
269 elseif ($value && substr($value, 0, 5) == 'date:') {
270 $this->webtestFillDate("value_{$set}_{$row}", trim(substr($value, 5)));
273 $this->type("value_{$set}_{$row}", $value);
277 function _advancedSearch($fieldValue = NULL, $name = NULL, $contactType = NULL, $count = NULL, $field){
278 //advanced search by selecting the contactType
279 $this->openCiviPage("contact/search/advanced", "reset=1");
280 if (isset($contactType)){
281 $this->select("id=crmasmSelect0", "value=$contactType");
283 if (substr($field, 0, 5) == 'note_') {
284 $this->click("notes");
285 $this->waitForElementPresent("xpath=//div[@id='notes-search']/table/tbody/tr/td[2]/input[3]");
286 if ($field == 'note_body') {
287 $this->click("CIVICRM_QFID_2_note_option");
289 elseif ($field == 'note_subject') {
290 $this->click("CIVICRM_QFID_3_note_option");
293 $this->click("CIVICRM_QFID_6_note_option");
295 $this->type("note",$fieldValue );
298 $this->click("location");
299 $this->waitForElementPresent("xpath=//div[@id='location']/table/tbody/tr[2]/td/table/tbody/tr[4]/td[2]/select");
300 if ($contactType == 'Individual') {
301 $this->type("$field",$fieldValue );
304 $this->type("$field",$fieldValue);
307 $this->click("_qf_Advanced_refresh");
308 $this->waitForPageToLoad($this->getTimeoutMsec());
310 //the search result should be same as the one that we got in search builder
312 $this->assertElementContainsText('Advanced', "$fieldValue");
315 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name");
318 $this->assertElementContainsText('search-status', "$count Contact");
322 function _createContact($contactType, $name, $email, $streetName = NULL, $postalCode = NULL){
323 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => $contactType), '_qf_Contact_cancel');
325 if ($contactType == 'Individual'){
326 $this->type("first_name", "$name");
327 $this->type("last_name", "adv$name");
328 $name = "$name adv$name";
329 } elseif ($contactType == 'Organization') {
330 $this->type("organization_name",$name);
332 $this->type("household_name",$name);
334 $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]");
335 $this->waitForElementPresent("address_1_geo_code_2");
336 $this->type("email_1_email",$email);
337 $this->type("phone_1_phone","9876543210");
338 $this->type("address_1_street_address", $streetName);
339 $this->select("address_1_country_id", "United States");
340 $this->select("address_1_state_province_id", "Alaska");
341 $this->type("address_1_postal_code",$postalCode);
343 $this->click("//form[@id='Contact']/div[2]/div[6]/div[1]");
344 $this->waitForElementPresent("note");
345 $this->type("subject", "this is subject by $name");
346 $this->type("note", "this is notes by $name");
349 $this->click("_qf_Contact_upload_view");
350 $this->waitForPageToLoad($this->getTimeoutMsec());
351 $this->assertTrue($this->isTextPresent("$name has been created."));
355 * Webtest for CRM-12148
358 function testSearchBuilderfinancialType() {
359 // Logging in. Remember to wait for page to load. In most cases,
360 // you can rely on 30000 as the value that allows your test to pass, however,
361 // sometimes your test might fail because of this. In such cases, it's better to pick one element
362 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
363 // page contents loaded and you can continue your test execution.
364 $this->webtestLogin();
366 // add financial type
367 $financialTypeName1 = 'Financial Type' . substr(sha1(rand()), 0, 5);;
368 $financialTypeName2 = 'Financial Type' . substr(sha1(rand()), 0, 5);;
369 $financialType = array(
370 'name' => $financialTypeName1,
371 'is_reserved' => FALSE,
372 'is_deductible' => FALSE,
374 $this->addeditFinancialType($financialType);
375 $this->select('account_relationship', 'label=Income Account is');
376 $this->select('financial_account_id', 'label=Discounts');
377 $this->click('_qf_FinancialTypeAccount_next-botttom');
378 $this->waitForPageToLoad($this->getTimeoutMsec());
379 $financialType['name'] = $financialTypeName2;
380 $this->addeditFinancialType($financialType);
381 $this->select('account_relationship', 'label=Income Account is');
382 $this->select('financial_account_id', 'label=Discounts');
383 $this->click('_qf_FinancialTypeAccount_next-botttom');
384 $this->waitForPageToLoad($this->getTimeoutMsec());
385 //create 6 contribution
386 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", "_qf_Contribution_upload");
387 for ($i = 1; $i <= 6; $i++
) {
389 $financialType = $financialTypeName1;
392 $financialType = $financialTypeName2;
394 // create new contact using dialog
395 $firstName = substr(sha1(rand()), 0, 7);
396 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
397 $this->select('financial_type_id', $financialType);
398 $this->type('total_amount', 100 * $i);
399 $this->click('_qf_Contribution_upload_new');
400 $this->waitForPageToLoad($this->getTimeoutMsec());
401 $this->waitForElementPresent('_qf_Contribution_upload_new');
403 $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
405 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
406 $this->click('_qf_Builder_refresh');
407 $this->waitForPageToLoad($this->getTimeoutMsec());
409 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
411 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
412 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
413 $this->click('_qf_Builder_refresh');
414 $this->waitForPageToLoad($this->getTimeoutMsec());
415 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
417 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
418 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, 'IN', array($financialTypeName1, $financialTypeName2));
419 $this->click('_qf_Builder_refresh');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
421 $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');