3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
30 * Class WebTest_Contact_SearchTest
32 class WebTest_Contact_SearchTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testQuickSearch() {
39 $this->webtestLogin();
42 // We're using Quick Add block on the main page for this.
43 $firstName = substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName, "Anderson", "$firstName.anderson@example.org");
46 $sortName = "Anderson, $firstName";
47 $displayName = "$firstName Anderson";
49 $this->openCiviPage("dashboard", "reset=1");
51 // type sortname in autocomplete
52 $this->click("css=input#sort_name_navigation");
53 $this->type("css=input#sort_name_navigation", $sortName);
54 $this->typeKeys("css=input#sort_name_navigation", $sortName);
56 // wait for result list
57 $this->waitForElementPresent("xpath=//li[contains(text(), '$sortName :: $firstName.anderson@example.org')]");
59 // visit contact summary page
60 $this->click("xpath=//li[contains(text(), '$sortName :: $firstName.anderson@example.org')]");
61 $this->waitForPageToLoad($this->getTimeoutMsec());
63 // Is contact present?
64 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!");
67 public function testQuickSearchPartial() {
68 $this->webtestLogin();
71 // We're using Quick Add block on the main page for this.
72 $firstName = substr(sha1(rand()), 0, 7);
73 $this->webtestAddContact($firstName, "Adams", "{$firstName}.adams@example.org");
75 $sortName = "Adams, {$firstName}";
77 $this->openCiviPage("dashboard", "reset=1");
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->clickLink("_qf_Advanced_refresh");
86 // make sure we're on search results page
87 $this->waitForElementPresent("alpha-filter");
89 // Is contact present in search result?
90 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
93 public function testContactSearch() {
94 $this->webtestLogin();
97 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
98 self
::addTag($tagName, $this);
101 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
102 $this->WebtestAddGroup($groupName);
105 // We're using Quick Add block on the main page for this.
106 $firstName = substr(sha1(rand()), 0, 7);
107 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
109 $sortName = "Smith, $firstName";
110 $displayName = "$firstName Smith";
112 // add contact to group
114 $this->click("css=li#tab_group a");
115 $this->waitForElementPresent("group_id");
118 $this->select("group_id", "label=$groupName");
119 $this->click("_qf_GroupContact_next");
120 $this->waitForText("crm-notification-container", "Contact has been added to '$groupName'.");
124 $this->click("css=li#tab_tag a");
125 $this->waitForElementPresent("css=div#tagtree");
128 $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]");
129 $this->checkCRMStatus();
131 // visit contact search page
132 $this->openCiviPage("contact/search", "reset=1");
134 // fill name as first_name
135 $this->type("sort_name", $firstName);
137 // select contact type as Indiividual
138 $this->select("contact_type", "value=Individual");
141 $this->select("group", "label=$groupName");
144 $this->select("tag", "label=$tagName");
147 $this->click("_qf_Basic_refresh");
148 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']");
150 // Is contact present in search result?
151 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
155 * This code is reused with advanced search, hence the reference to $self
159 public static function addTag($tagName = 'New Tag', $self) {
160 $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next');
163 $self->type("name", $tagName);
166 $self->type("description", "Adding new tag.");
168 // select used for contact
169 $self->select("used_for", "value=civicrm_contact");
172 $self->click("is_reserved");
175 $self->click("_qf_Tag_next");
176 $self->waitForPageToLoad($self->getTimeoutMsec());
178 // Is status message correct?
179 $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved."));
185 public function testContactSearchExport() {
186 $this->webtestLogin();
189 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
190 $this->WebtestAddGroup($parentGroupName);
192 // Create new group and select the previously selected group as parent group for this new group.
193 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
194 $this->WebtestAddGroup($childGroupName, $parentGroupName);
196 // Adding Parent group contact
197 $firstName = substr(sha1(rand()), 0, 7);
198 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
200 $sortName = "Smith, $firstName";
201 $displayName = "$firstName Smith";
203 // add contact to parent group
205 $this->click("css=li#tab_group a");
206 $this->waitForElementPresent("group_id");
209 $this->select("group_id", "label=$parentGroupName");
210 $this->click("_qf_GroupContact_next");
211 $this->waitForText("crm-notification-container", "Contact has been added to '$parentGroupName'.");
213 // Adding child group contact
214 // We're using Quick Add block on the main page for this.
215 $childName = substr(sha1(rand()), 0, 7);
216 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
218 $childSortName = "John, $childName";
219 $childDisplayName = "$childName John";
221 // add contact to child group
223 $this->click("css=li#tab_group a");
224 $this->waitForElementPresent("group_id");
226 // add to child group
227 $this->select("group_id", "*$childGroupName");
228 $this->click("_qf_GroupContact_next");
229 $this->waitForText("crm-notification-container", "Contact has been added to '$childGroupName'.");
231 // visit contact search page
232 $this->openCiviPage("contact/search", "reset=1");
234 // select contact type as Indiividual
235 $this->select("contact_type", "value=Individual");
238 $this->select("group", "label=$parentGroupName");
241 $this->clickLink("_qf_Basic_refresh");
243 // Is contact present in search result?
244 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
245 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $childSortName);
247 // select to export all the contasct from search result
248 $this->click("CIVICRM_QFID_ts_all_4");
250 // Select the task action to export
251 $this->click("task");
252 $this->select("task", "label=Export Contacts");
253 $this->waitForPageToLoad($this->getTimeoutMsec());
255 $this->click("_qf_Select_next-bottom");