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 $this->webtestLogin();
39 $groupName = $this->WebtestAddGroup();
41 // Open the search builder
42 $this->openCiviPage('contact/search/builder', 'reset=1');
44 $this->enterValues(1, 1, 'Contacts', 'Group(s)', NULL, '=', array($groupName));
45 $this->enterValues(1, 2, 'Contacts', 'Country', NULL, '=', array('United States'));
46 $this->enterValues(1, 3, 'Individual', 'Gender', NULL, '=', array('Male'));
47 $this->click('_qf_Builder_refresh');
48 $this->waitForPageToLoad();
50 // We should get no results. But check the options are all still set
51 $this->waitForTextPresent('No matches found');
52 foreach (array($groupName, 'United States', 'Male') as $i => $label) {
53 $this->waitForElementPresent("//span[@id='crm_search_value_1_$i']/select/option[2]");
54 $this->assertSelectedLabel("//span[@id='crm_search_value_1_$i']/select", $label);
58 function testSearchBuilderRLIKE() {
59 $this->webtestLogin();
62 // We're using Quick Add block on the main page for this.
63 $firstName = substr(sha1(rand()), 0, 7);
64 $this->createDetailContact($firstName);
66 $sortName = "adv$firstName, $firstName";
67 $displayName = "$firstName adv$firstName";
69 $this->_searchBuilder("Postal Code", "100[0-9]", $sortName, "RLIKE");
72 // function to create contact with details (contact details, address, Constituent information ...)
73 function createDetailContact($firstName = NULL) {
76 $firstName = substr(sha1(rand()), 0, 7);
79 // create contact type Individual with subtype
80 // with most of values to required to search
82 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => 'Individual'), '_qf_Contact_cancel');
84 // --- fill few values in Contact Detail block
85 $this->type("first_name", "$firstName");
86 $this->type("middle_name", "mid$firstName");
87 $this->type("last_name", "adv$firstName");
88 $this->select("contact_sub_type", "label=- $Subtype");
89 $this->type("email_1_email", "$firstName@advsearch.co.in");
90 $this->type("phone_1_phone", "123456789");
91 $this->type("external_identifier", "extid$firstName");
93 // --- fill few values in address
94 $this->click("//form[@id='Contact']/div[2]/div[4]/div[1]");
95 $this->waitForElementPresent("address_1_geo_code_2");
96 $this->type("address_1_street_address", "street 1 $firstName");
97 $this->type("address_1_supplemental_address_1", "street supplement 1 $firstName");
98 $this->type("address_1_supplemental_address_2", "street supplement 2 $firstName");
99 $this->type("address_1_city", "city$firstName");
100 $this->type("address_1_postal_code", "100100");
101 $this->select("address_1_country_id", "United States");
102 $this->select("address_1_state_province_id", "Alaska");
105 $this->click("_qf_Contact_upload_view");
106 $this->waitForPageToLoad($this->getTimeoutMsec());
107 $this->assertTrue($this->isTextPresent("$firstName adv$firstName"));
110 function testSearchBuilderContacts(){
111 $this->webtestLogin();
114 $firstName = substr(sha1(rand()), 0, 7);
115 $streetName = "street $firstName";
116 $sortName = "adv$firstName, $firstName";
117 $this->_createContact('Individual', $firstName, "$firstName@advsearch.co.in", $streetName);
118 // search using search builder and advanced search
119 $this->_searchBuilder('Street Address', $streetName, $sortName, '=', '1');
120 $this->_advancedSearch($streetName, $sortName, 'Individual', '1', 'street_address');
123 $orgName = substr(sha1(rand()), 0, 7)."org";
124 $orgEmail = "ab".rand()."@{$orgName}.com";
125 $this->_createContact('Organization', $orgName, $orgEmail,"street $orgName");
126 // search using search builder and advanced search
127 $this->_searchBuilder('Email',$orgEmail, $orgName,'=','1');
128 $this->_advancedSearch($orgEmail, $orgName, 'Organization','1','email');
131 $householdName = "household".substr(sha1(rand()), 0, 7);
132 $householdEmail = "h1".rand()."@{$householdName}.com";
133 $this->_createContact('Household', $householdName, $householdEmail,"street $householdName");
134 // search using search builder and advanced search
135 $this->_searchBuilder('Email',$householdEmail, $householdName,'=','1');
136 $this->_advancedSearch($householdEmail, $householdName, 'Household','1','email');
138 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
140 // searching contacts whose email is not set
141 $firstName1 = "00a1".substr(sha1(rand()), 0, 7);
142 $this->type("first_name", $firstName1);
143 $this->type("last_name", "01adv$firstName1");
145 $this->click("_qf_Contact_upload_view");
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
149 $firstName2 = "00a2".substr(sha1(rand()), 0, 7);
150 $this->type("first_name", $firstName2);
151 $this->type("last_name", "02adv$firstName2");
153 $this->click("_qf_Contact_upload_view");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
155 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
157 $firstName3 = "00a3".substr(sha1(rand()), 0, 7);
158 $this->type("first_name", $firstName3);
159 $this->type("last_name", "03adv$firstName3");
161 $this->click("_qf_Contact_upload_view");
162 $this->waitForPageToLoad($this->getTimeoutMsec());
163 $this->_searchBuilder('Email',NULL,NULL,'IS NULL');
164 $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
165 $this->waitForPageToLoad($this->getTimeoutMsec());
166 $names = array( 1 => $firstName1,
170 foreach($names as $key => $value){
171 $this->assertTrue($this->isTextPresent($value));
173 //searching contacts whose phone field is empty
174 $this->_searchBuilder('Phone',NULL,NULL,'IS EMPTY');
175 foreach($names as $key => $value){
176 $this->assertTrue($this->isTextPresent($value));
178 //searching contacts whose phone field is not empty
179 $this->_searchBuilder('Phone',NULL,$firstName,'IS NOT EMPTY');
180 $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
181 $this->waitForPageToLoad($this->getTimeoutMsec());
182 $this->assertTrue($this->isTextPresent($firstName));
184 $firstName4 = "AB".substr(sha1(rand()), 0, 7);
185 $postalCode = rand();
186 $this->_createContact('Individual', $firstName4,"$firstName4@advsearch.co.in",NULL, $postalCode);
187 $firstName5 = "CD".substr(sha1(rand()), 0, 7);
188 $this->_createContact('Individual', $firstName5,"$firstName5@advsearch.co.in",NULL, $postalCode);
189 $firstName6 = "EF".substr(sha1(rand()), 0, 7);
190 $this->_createContact('Organization', $firstName6,"$firstName6@advsearch.co.in",NULL, $postalCode);
191 $firstName7 = "GH".substr(sha1(rand()), 0, 7);
192 $this->_createContact('Household', $firstName7,"$firstName7@advsearch.co.in",NULL, $postalCode);
194 // check if the resultset of search builder and advanced search match for the postal code
195 $this->_searchBuilder('Postal Code',$postalCode,NULL,'LIKE','4');
196 $this->_advancedSearch($postalCode,NULL,NULL,'4','postal_code');
198 $firstName8 = "abcc".substr(sha1(rand()), 0, 7);
199 $this->_createContact('Individual', $firstName8,"$firstName8@advsearch.co.in",NULL);
200 $this->_searchBuilder('Note(s): Body and Subject', "this is subject by $firstName8", $firstName8, 'LIKE');
201 $this->_searchBuilder('Note(s): Body and Subject', "this is notes by $firstName8", $firstName8, 'LIKE');
202 $this->_searchBuilder('Note(s): Subject only', "this is subject by $firstName8", $firstName8, 'LIKE');
203 $this->_searchBuilder('Note(s): Body only', "this is notes by $firstName8", $firstName8, 'LIKE');
204 $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_body', 'notes');
205 $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_subject', 'notes');
206 $this->_advancedSearch( "this is notes by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes');
207 $this->_advancedSearch( "this is subject by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes');
210 function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) {
211 // search builder using contacts(not using contactType)
212 $this->openCiviPage("contact/search/builder", "reset=1");
213 $this->enterValues(1, 1, 'Contacts', $field, NULL, $op, "$fieldValue");
214 $this->click("id=_qf_Builder_refresh");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
216 if (($op == '=' ||
$op == 'LIKE') && $fieldValue) {
217 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$fieldValue");
220 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name");
223 $this->assertElementContainsText('search-status', "$count Contact");
228 * Enter form values in a Search Builder row
230 function enterValues($set, $row, $entity, $field, $loc, $op, $value = '') {
231 if ($set > 1 && $row == 1) {
232 $this->click('addBlock');
235 $this->click("addMore_{$set}");
237 // In the DOM rows are 0 indexed and sets are 1 indexed, so normalizing
240 $this->waitForElementPresent("mapper_{$set}_{$row}_0");
241 $this->select("mapper_{$set}_{$row}_0", "label=$entity");
242 $this->select("mapper_{$set}_{$row}_1", "label=$field");
244 $this->select("mapper_{$set}_{$row}_2", "label=$loc");
246 $this->select("operator_{$set}_{$row}", "label=$op");
247 if (is_array($value)) {
248 $this->waitForElementPresent("css=#crm_search_value_{$set}_{$row} select option + option");
249 foreach ($value as $val) {
254 $select = 'addSelection';
256 $this->$select("css=#crm_search_value_{$set}_{$row} select", "label=$val");
259 elseif ($value && substr($value, 0, 5) == 'date:') {
260 $this->webtestFillDate("value_{$set}_{$row}", trim(substr($value, 5)));
263 $this->type("value_{$set}_{$row}", $value);
267 function _advancedSearch($fieldValue = NULL, $name = NULL, $contactType = NULL, $count = NULL, $field){
268 //advanced search by selecting the contactType
269 $this->openCiviPage("contact/search/advanced", "reset=1");
270 if (isset($contactType)){
271 $this->select("id=crmasmSelect0", "value=$contactType");
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");
279 elseif ($field == 'note_subject') {
280 $this->click("CIVICRM_QFID_3_note_option");
283 $this->click("CIVICRM_QFID_6_note_option");
285 $this->type("note",$fieldValue );
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 );
294 $this->type("$field",$fieldValue);
297 $this->click("_qf_Advanced_refresh");
298 $this->waitForPageToLoad($this->getTimeoutMsec());
300 //the search result should be same as the one that we got in search builder
302 $this->assertElementContainsText('Advanced', "$fieldValue");
305 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name");
308 $this->assertElementContainsText('search-status', "$count Contact");
312 function _createContact($contactType, $name, $email, $streetName = NULL, $postalCode = NULL){
313 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => $contactType), '_qf_Contact_cancel');
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);
322 $this->type("household_name",$name);
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);
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");
339 $this->click("_qf_Contact_upload_view");
340 $this->waitForPageToLoad($this->getTimeoutMsec());
341 $this->assertTrue($this->isTextPresent("$name has been created."));
345 * Webtest for CRM-12148
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();
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,
364 $this->addeditFinancialType($financialType);
365 $this->select('account_relationship', 'label=Income Account is');
366 $this->select('financial_account_id', 'label=Discounts');
367 $this->click('_qf_FinancialTypeAccount_next-botttom');
368 $this->waitForPageToLoad($this->getTimeoutMsec());
369 $financialType['name'] = $financialTypeName2;
370 $this->addeditFinancialType($financialType);
371 $this->select('account_relationship', 'label=Income Account is');
372 $this->select('financial_account_id', 'label=Discounts');
373 $this->click('_qf_FinancialTypeAccount_next-botttom');
374 $this->waitForPageToLoad($this->getTimeoutMsec());
375 //create 6 contribution
376 $this->openCiviPage("contribute/add", "reset=1&action=add&context=standalone", "_qf_Contribution_upload");
377 for ($i = 1; $i <= 6; $i++
) {
379 $financialType = $financialTypeName1;
382 $financialType = $financialTypeName2;
384 // create new contact using dialog
385 $firstName = substr(sha1(rand()), 0, 7);
386 $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
387 $this->select('financial_type_id', $financialType);
388 $this->type('total_amount', 100 * $i);
389 $this->click('_qf_Contribution_upload_new');
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 $this->waitForElementPresent('_qf_Contribution_upload_new');
393 $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
395 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
396 $this->click('_qf_Builder_refresh');
397 $this->waitForPageToLoad($this->getTimeoutMsec());
399 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
401 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
402 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
403 $this->click('_qf_Builder_refresh');
404 $this->waitForPageToLoad($this->getTimeoutMsec());
405 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
407 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
408 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, 'IN', array($financialTypeName1, $financialTypeName2));
409 $this->click('_qf_Builder_refresh');
410 $this->waitForPageToLoad($this->getTimeoutMsec());
411 $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');