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_SearchTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testQuickSearch() {
35 $this->webtestLogin();
38 // We're using Quick Add block on the main page for this.
39 $firstName = substr(sha1(rand()), 0, 7);
40 $this->webtestAddContact($firstName, "Anderson", "$firstName.anderson@example.org");
42 $sortName = "Anderson, $firstName";
43 $displayName = "$firstName Anderson";
45 $this->openCiviPage("dashboard", "reset=1");
47 // type sortname in autocomplete
48 $this->click("css=input#sort_name_navigation");
49 $this->type("css=input#sort_name_navigation", $sortName);
50 $this->typeKeys("css=input#sort_name_navigation", $sortName);
52 // wait for result list
53 $this->waitForElementPresent("css=div.ac_results-inner li");
55 // visit contact summary page
56 $this->click("css=div.ac_results-inner li");
57 $this->waitForPageToLoad($this->getTimeoutMsec());
59 // Is contact present?
60 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!");
63 function testQuickSearchPartial() {
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->webtestAddContact($firstName, "Adams", "{$firstName}.adams@example.org");
71 $sortName = "Adams, {$firstName}";
73 $this->openCiviPage("dashboard", "reset=1");
75 // type partial sortname in autocomplete
76 $this->click("css=input#sort_name_navigation");
77 $this->type("css=input#sort_name_navigation", 'ada');
78 $this->typeKeys("css=input#sort_name_navigation", 'ada');
80 $this->clickLink("_qf_Basic_refresh");
82 // make sure we're on search results page
83 $this->waitForElementPresent("alpha-filter");
85 // Is contact present in search result?
86 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
89 function testContactSearch() {
90 $this->webtestLogin();
93 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
94 self
::addTag($tagName, $this);
97 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
98 $this->WebtestAddGroup($groupName);
101 // We're using Quick Add block on the main page for this.
102 $firstName = substr(sha1(rand()), 0, 7);
103 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
105 $sortName = "Smith, $firstName";
106 $displayName = "$firstName Smith";
108 // add contact to group
110 $this->click("css=li#tab_group a");
111 $this->waitForElementPresent("group_id");
114 $this->select("group_id", "label=$groupName");
115 $this->click("_qf_GroupContact_next");
116 $this->waitForPageToLoad($this->getTimeoutMsec());
120 $this->click("css=li#tab_tag a");
121 $this->waitForElementPresent("css=div#tagtree");
124 $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
125 $this->waitForElementPresent("css=.success");
127 // visit contact search page
128 $this->openCiviPage("contact/search", "reset=1");
130 // fill name as first_name
131 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $firstName);
133 // select contact type as Indiividual
134 $this->select("contact_type", "value=Individual");
137 $this->select("group", "label=$groupName");
140 $this->select("tag", "label=$tagName");
143 $this->click("_qf_Basic_refresh");
144 $this->waitForPageToLoad($this->getTimeoutMsec());
146 // Is contact present in search result?
147 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
151 * This code is reused with advanced search, hence the reference to $self
155 static function addTag($tagName = 'New Tag', $self) {
156 $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next');
159 $self->type("name", $tagName);
162 $self->type("description", "Adding new tag.");
164 // select used for contact
165 $self->select("used_for", "value=civicrm_contact");
168 $self->click("is_reserved");
171 $self->click("_qf_Tag_next");
172 $self->waitForPageToLoad($self->getTimeoutMsec());
174 // Is status message correct?
175 $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved."));
179 function testContactSearchExport() {
180 $this->webtestLogin();
183 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
184 $this->WebtestAddGroup($parentGroupName);
186 // Create new group and select the previously selected group as parent group for this new group.
187 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
188 $this->WebtestAddGroup($childGroupName, $parentGroupName);
190 // Adding Parent group contact
191 $firstName = substr(sha1(rand()), 0, 7);
192 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
194 $sortName = "Smith, $firstName";
195 $displayName = "$firstName Smith";
197 // add contact to parent group
199 $this->click("css=li#tab_group a");
200 $this->waitForElementPresent("group_id");
203 $this->select("group_id", "label=$parentGroupName");
204 $this->click("_qf_GroupContact_next");
205 $this->waitForPageToLoad($this->getTimeoutMsec());
207 // Adding child group contact
208 // We're using Quick Add block on the main page for this.
209 $childName = substr(sha1(rand()), 0, 7);
210 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
212 $childSortName = "John, $childName";
213 $childDisplayName = "$childName John";
215 // add contact to child group
217 $this->click("css=li#tab_group a");
218 $this->waitForElementPresent("group_id");
220 // add to child group
221 $this->select("group_id", "*$childGroupName");
222 $this->click("_qf_GroupContact_next");
223 $this->waitForPageToLoad($this->getTimeoutMsec());
225 // visit contact search page
226 $this->openCiviPage("contact/search", "reset=1");
228 // select contact type as Indiividual
229 $this->select("contact_type", "value=Individual");
232 $this->select("group", "label=$parentGroupName");
235 $this->click("_qf_Basic_refresh");
236 $this->waitForPageToLoad($this->getTimeoutMsec());
238 // Is contact present in search result?
239 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
240 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $childSortName);
242 // select to export all the contasct from search result
243 $this->click("CIVICRM_QFID_ts_all_4");
245 // Select the task action to export
246 $this->click("task");
247 $this->select("task", "label=Export Contacts");
249 $this->waitForPageToLoad($this->getTimeoutMsec());
251 $this->click("_qf_Select_next-bottom");