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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_SearchBuilderTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testSearchBuilderOptions() {
35 $this->webtestLogin();
37 $groupName = $this->WebtestAddGroup();
39 // Open the search builder
40 $this->openCiviPage('contact/search/builder', 'reset=1');
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();
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);
56 function testSearchBuilderRLIKE() {
57 $this->webtestLogin();
60 // We're using Quick Add block on the main page for this.
61 $firstName = substr(sha1(rand()), 0, 7);
62 $this->createDetailContact($firstName);
64 $sortName = "adv$firstName, $firstName";
65 $displayName = "$firstName adv$firstName";
67 $this->_searchBuilder("Postal Code", "100[0-9]", $sortName, "RLIKE");
70 // function to create contact with details (contact details, address, Constituent information ...)
71 function createDetailContact($firstName = NULL) {
74 $firstName = substr(sha1(rand()), 0, 7);
77 // create contact type Individual with subtype
78 // with most of values to required to search
80 $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => 'Individual'), '_qf_Contact_cancel');
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");
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");
103 $this->click("_qf_Contact_upload_view");
104 $this->waitForPageToLoad($this->getTimeoutMsec());
105 $this->assertTrue($this->isTextPresent("$firstName adv$firstName"));
108 function testSearchBuilderContacts(){
109 $this->webtestLogin();
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');
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');
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');
136 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
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");
143 $this->click("_qf_Contact_upload_view");
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
147 $firstName2 = "00a2".substr(sha1(rand()), 0, 7);
148 $this->type("first_name", $firstName2);
149 $this->type("last_name", "02adv$firstName2");
151 $this->click("_qf_Contact_upload_view");
152 $this->waitForPageToLoad($this->getTimeoutMsec());
153 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
155 $firstName3 = "00a3".substr(sha1(rand()), 0, 7);
156 $this->type("first_name", $firstName3);
157 $this->type("last_name", "03adv$firstName3");
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,
168 foreach($names as $key => $value){
169 $this->assertTrue($this->isTextPresent($value));
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));
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));
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);
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');
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');
208 function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) {
209 // search builder using contacts(not using contactType)
210 $this->openCiviPage("contact/search/builder", "reset=1");
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");
218 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', "$name");
221 $this->assertElementContainsText('search-status', "$count Contact");
226 * Enter form values in a Search Builder row
228 function enterValues($set, $row, $entity, $field, $loc, $op, $value = '') {
229 if ($set > 1 && $row == 1) {
230 $this->click('addBlock');
233 $this->click("addMore_{$set}");
235 // In the DOM rows are 0 indexed and sets are 1 indexed, so normalizing
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");
242 $this->select("mapper_{$set}_{$row}_2", "label=$loc");
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) {
253 $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->clickLink('_qf_Contribution_upload_new', '_qf_Contribution_upload_new');
391 $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
393 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
394 $this->click('_qf_Builder_refresh');
395 $this->waitForPageToLoad($this->getTimeoutMsec());
397 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
399 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
400 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
401 $this->click('_qf_Builder_refresh');
402 $this->waitForPageToLoad($this->getTimeoutMsec());
403 $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
405 $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
406 $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, 'IN', array($financialTypeName1, $financialTypeName2));
407 $this->click('_qf_Builder_refresh');
408 $this->waitForPageToLoad($this->getTimeoutMsec());
409 $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');