Start migrating to use clickLink method
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_SearchTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testQuickSearch() {
36 $this->webtestLogin();
37
38 // Adding contact
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");
42
43 $sortName = "Anderson, $firstName";
44 $displayName = "$firstName Anderson";
45
46 $this->openCiviPage("dashboard", "reset=1");
47
48 // type sortname in autocomplete
49 $this->click("css=input#sort_name_navigation");
50 $this->type("css=input#sort_name_navigation", $sortName);
51 $this->typeKeys("css=input#sort_name_navigation", $sortName);
52
53 // wait for result list
54 $this->waitForElementPresent("css=div.ac_results-inner li");
55
56 // visit contact summary page
57 $this->click("css=div.ac_results-inner li");
58 $this->waitForPageToLoad($this->getTimeoutMsec());
59
60 // Is contact present?
61 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!");
62 }
63
64 function testQuickSearchPartial() {
65 $this->webtestLogin();
66
67 // Adding contact
68 // We're using Quick Add block on the main page for this.
69 $firstName = substr(sha1(rand()), 0, 7);
70 $this->webtestAddContact($firstName, "Adams", "{$firstName}.adams@example.org");
71
72 $sortName = "Adams, {$firstName}";
73
74 $this->openCiviPage("dashboard", "reset=1");
75
76 // type partial sortname in autocomplete
77 $this->click("css=input#sort_name_navigation");
78 $this->type("css=input#sort_name_navigation", 'ada');
79 $this->typeKeys("css=input#sort_name_navigation", 'ada');
80
81 $this->clickLink("_qf_Basic_refresh");
82
83 // make sure we're on search results page
84 $this->waitForElementPresent("alpha-filter");
85
86 // Is contact present in search result?
87 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
88 }
89
90 function testContactSearch() {
91 $this->webtestLogin();
92
93 // Create new tag.
94 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
95 self::addTag($tagName, $this);
96
97 // Create new group
98 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
99 $this->WebtestAddGroup($groupName);
100
101 // Adding contact
102 // We're using Quick Add block on the main page for this.
103 $firstName = substr(sha1(rand()), 0, 7);
104 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
105
106 $sortName = "Smith, $firstName";
107 $displayName = "$firstName Smith";
108
109 // add contact to group
110 // visit group tab
111 $this->click("css=li#tab_group a");
112 $this->waitForElementPresent("group_id");
113
114 // add to group
115 $this->select("group_id", "label=$groupName");
116 $this->click("_qf_GroupContact_next");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118
119 // tag a contact
120 // visit tag tab
121 $this->click("css=li#tab_tag a");
122 $this->waitForElementPresent("css=div#tagtree");
123
124 // select tag
125 $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
126 $this->waitForElementPresent("css=.success");
127
128 // visit contact search page
129 $this->openCiviPage("contact/search", "reset=1");
130
131 // fill name as first_name
132 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $firstName);
133
134 // select contact type as Indiividual
135 $this->select("contact_type", "value=Individual");
136
137 // select group
138 $this->select("group", "label=$groupName");
139
140 // select tag
141 $this->select("tag", "label=$tagName");
142
143 // click to search
144 $this->click("_qf_Basic_refresh");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146
147 // Is contact present in search result?
148 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
149 }
150
151 /**
152 * This code is reused with advanced search, hence the reference to $self
153 *
154 * @static
155 */
156 static function addTag($tagName = 'New Tag', $self) {
157 $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next');
158
159 // fill tag name
160 $self->type("name", $tagName);
161
162 // fill description
163 $self->type("description", "Adding new tag.");
164
165 // select used for contact
166 $self->select("used_for", "value=civicrm_contact");
167
168 // check reserved
169 $self->click("is_reserved");
170
171 // Clicking save.
172 $self->click("_qf_Tag_next");
173 $self->waitForPageToLoad($self->getTimeoutMsec());
174
175 // Is status message correct?
176 $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved."));
177 }
178
179 // CRM-6586
180 function testContactSearchExport() {
181 $this->webtestLogin();
182
183 // Create new group
184 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
185 $this->WebtestAddGroup($parentGroupName);
186
187 // Create new group and select the previously selected group as parent group for this new group.
188 $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7);
189 $this->WebtestAddGroup($childGroupName, $parentGroupName);
190
191
192 // Adding Parent group contact
193 $firstName = substr(sha1(rand()), 0, 7);
194 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
195
196 $sortName = "Smith, $firstName";
197 $displayName = "$firstName Smith";
198
199 // add contact to parent group
200 // visit group tab
201 $this->click("css=li#tab_group a");
202 $this->waitForElementPresent("group_id");
203
204 // add to group
205 $this->select("group_id", "label=$parentGroupName");
206 $this->click("_qf_GroupContact_next");
207 $this->waitForPageToLoad($this->getTimeoutMsec());
208
209 // Adding child group contact
210 // We're using Quick Add block on the main page for this.
211 $childName = substr(sha1(rand()), 0, 7);
212 $this->webtestAddContact($childName, "John", "$childName.john@example.org");
213
214 $childSortName = "John, $childName";
215 $childDisplayName = "$childName John";
216
217 // add contact to child group
218 // visit group tab
219 $this->click("css=li#tab_group a");
220 $this->waitForElementPresent("group_id");
221
222 // add to child group
223 $this->select("group_id", "*$childGroupName");
224 $this->click("_qf_GroupContact_next");
225 $this->waitForPageToLoad($this->getTimeoutMsec());
226
227 // visit contact search page
228 $this->openCiviPage("contact/search", "reset=1");
229
230 // select contact type as Indiividual
231 $this->select("contact_type", "value=Individual");
232
233 // select group
234 $this->select("group", "label=$parentGroupName");
235
236 // click to search
237 $this->click("_qf_Basic_refresh");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
239
240 // Is contact present in search result?
241 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
242 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $childSortName);
243
244 // select to export all the contasct from search result
245 $this->click("CIVICRM_QFID_ts_all_4");
246
247 // Select the task action to export
248 $this->click("task");
249 $this->select("task", "label=Export Contacts");
250 $this->click("Go");
251 $this->waitForPageToLoad($this->getTimeoutMsec());
252
253 $this->click("_qf_Select_next-bottom");
254 }
255 }