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_SearchTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testQuickSearch() {
36 $this->webtestLogin();
39 // We're using Quick Add block on the main page for this.
40 $firstName = substr(sha1(rand()), 0, 7);
41 $this->webtestAddContact($firstName, "Anderson", "$firstName.anderson@example.org");
43 $sortName = "Anderson, $firstName";
44 $displayName = "$firstName Anderson";
46 // Go directly to the URL of the screen that you will be testing (Home dashboard).
47 $this->open($this->sboxPath
. "civicrm/dashboard?reset=1");
48 $this->waitForPageToLoad($this->getTimeoutMsec());
50 // type sortname in autocomplete
51 $this->click("css=input#sort_name_navigation");
52 $this->type("css=input#sort_name_navigation", $sortName);
53 $this->typeKeys("css=input#sort_name_navigation", $sortName);
55 // wait for result list
56 $this->waitForElementPresent("css=div.ac_results-inner li");
58 // visit contact summary page
59 $this->click("css=div.ac_results-inner li");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
62 // Is contact present?
63 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!");
66 function testQuickSearchPartial() {
67 $this->webtestLogin();
70 // We're using Quick Add block on the main page for this.
71 $firstName = substr(sha1(rand()), 0, 7);
72 $this->webtestAddContact($firstName, "Adams", "{$firstName}.adams@example.org");
74 $sortName = "Adams, {$firstName}";
75 // Go directly to the URL of the screen that you will be testing (Home dashboard).
76 $this->open($this->sboxPath
. "civicrm/dashboard?reset=1");
77 $this->waitForPageToLoad($this->getTimeoutMsec());
79 // type partial sortname in autocomplete
80 $this->click("css=input#sort_name_navigation");
81 $this->type("css=input#sort_name_navigation", 'ada');
82 $this->typeKeys("css=input#sort_name_navigation", 'ada');
84 $this->click("_qf_Basic_refresh");
86 // wait for result list
87 $this->waitForPageToLoad($this->getTimeoutMsec());
88 // make sure we're on search results page
89 $this->waitForElementPresent("alpha-filter");
90 // wait for bottom of page to load (access is in footer)
91 $this->waitForElementPresent("access");
93 // Is contact present in search result?
94 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
97 function testContactSearch() {
98 $this->webtestLogin();
101 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
102 self
::addTag($tagName, $this);
105 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
106 $this->WebtestAddGroup($groupName);
109 // We're using Quick Add block on the main page for this.
110 $firstName = substr(sha1(rand()), 0, 7);
111 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
113 $sortName = "Smith, $firstName";
114 $displayName = "$firstName Smith";
116 // add contact to group
118 $this->click("css=li#tab_group a");
119 $this->waitForElementPresent("group_id");
122 $this->select("group_id", "label=$groupName");
123 $this->click("_qf_GroupContact_next");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
128 $this->click("css=li#tab_tag a");
129 $this->waitForElementPresent("css=div#tagtree");
132 $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
133 $this->waitForElementPresent("css=.success");
135 // visit contact search page
136 $this->open($this->sboxPath
. "civicrm/contact/search?reset=1");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
139 // fill name as first_name
140 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $firstName);
142 // select contact type as Indiividual
143 $this->select("contact_type", "value=Individual");
146 $this->select("group", "label=$groupName");
149 $this->select("tag", "label=$tagName");
152 $this->click("_qf_Basic_refresh");
153 $this->waitForPageToLoad($this->getTimeoutMsec());
155 // Is contact present in search result?
156 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
160 * This code is reused with advanced search, hence the reference to $self
164 static function addTag($tagName = 'New Tag', $self) {
165 $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next');
168 $self->type("name", $tagName);
171 $self->type("description", "Adding new tag.");
173 // select used for contact
174 $self->select("used_for", "value=civicrm_contact");
177 $self->click("is_reserved");
180 $self->click("_qf_Tag_next");
181 $self->waitForPageToLoad($self->getTimeoutMsec());
183 // Is status message correct?
184 $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved."));
188 function testContactSearchExport() {
189 $this->webtestLogin();
192 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
193 $this->WebtestAddGroup($parentGroupName);
195 // Create new group and select the previously selected group as parent group for this new group.
196 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
197 $this->WebtestAddGroup($childGroupName, $parentGroupName);
200 // Adding Parent group contact
201 $firstName = substr(sha1(rand()), 0, 7);
202 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
204 $sortName = "Smith, $firstName";
205 $displayName = "$firstName Smith";
207 // add contact to parent group
209 $this->click("css=li#tab_group a");
210 $this->waitForElementPresent("group_id");
213 $this->select("group_id", "label=$parentGroupName");
214 $this->click("_qf_GroupContact_next");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
217 // Adding child group contact
218 // We're using Quick Add block on the main page for this.
219 $childName = substr(sha1(rand()), 0, 7);
220 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
222 $childSortName = "John, $childName";
223 $childDisplayName = "$childName John";
225 // add contact to child group
227 $this->click("css=li#tab_group a");
228 $this->waitForElementPresent("group_id");
230 // add to child group
231 $this->select("group_id", "*$childGroupName");
232 $this->click("_qf_GroupContact_next");
233 $this->waitForPageToLoad($this->getTimeoutMsec());
236 // visit contact search page
237 $this->open($this->sboxPath
. "civicrm/contact/search?reset=1");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
241 // select contact type as Indiividual
242 $this->select("contact_type", "value=Individual");
245 $this->select("group", "label=$parentGroupName");
248 $this->click("_qf_Basic_refresh");
249 $this->waitForPageToLoad($this->getTimeoutMsec());
251 // Is contact present in search result?
252 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
253 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $childSortName);
255 // select to export all the contasct from search result
256 $this->click("CIVICRM_QFID_ts_all_4");
258 // Select the task action to export
259 $this->click("task");
260 $this->select("task", "label=Export Contacts");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
264 $this->click("_qf_Select_next-bottom");