Merge pull request #159 from lcdservices/master
[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 // 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());
49
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);
54
55 // wait for result list
56 $this->waitForElementPresent("css=div.ac_results-inner li");
57
58 // visit contact summary page
59 $this->click("css=div.ac_results-inner li");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61
62 // Is contact present?
63 $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!");
64 }
65
66 function testQuickSearchPartial() {
67 $this->webtestLogin();
68
69 // Adding contact
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");
73
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());
78
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');
83
84 $this->click("_qf_Basic_refresh");
85
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");
92
93 // Is contact present in search result?
94 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
95 }
96
97 function testContactSearch() {
98 $this->webtestLogin();
99
100 // Create new tag.
101 $tagName = 'tag_' . substr(sha1(rand()), 0, 7);
102 self::addTag($tagName, $this);
103
104 // Create new group
105 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
106 $this->WebtestAddGroup($groupName);
107
108 // Adding contact
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");
112
113 $sortName = "Smith, $firstName";
114 $displayName = "$firstName Smith";
115
116 // add contact to group
117 // visit group tab
118 $this->click("css=li#tab_group a");
119 $this->waitForElementPresent("group_id");
120
121 // add to group
122 $this->select("group_id", "label=$groupName");
123 $this->click("_qf_GroupContact_next");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125
126 // tag a contact
127 // visit tag tab
128 $this->click("css=li#tab_tag a");
129 $this->waitForElementPresent("css=div#tagtree");
130
131 // select tag
132 $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
133 $this->waitForElementPresent("css=.success");
134
135 // visit contact search page
136 $this->open($this->sboxPath . "civicrm/contact/search?reset=1");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138
139 // fill name as first_name
140 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $firstName);
141
142 // select contact type as Indiividual
143 $this->select("contact_type", "value=Individual");
144
145 // select group
146 $this->select("group", "label=$groupName");
147
148 // select tag
149 $this->select("tag", "label=$tagName");
150
151 // click to search
152 $this->click("_qf_Basic_refresh");
153 $this->waitForPageToLoad($this->getTimeoutMsec());
154
155 // Is contact present in search result?
156 $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName);
157 }
158
159 /**
160 * This code is reused with advanced search, hence the reference to $self
161 *
162 * @static
163 */
164 static function addTag($tagName = 'New Tag', $self) {
165 $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next');
166
167 // fill tag name
168 $self->type("name", $tagName);
169
170 // fill description
171 $self->type("description", "Adding new tag.");
172
173 // select used for contact
174 $self->select("used_for", "value=civicrm_contact");
175
176 // check reserved
177 $self->click("is_reserved");
178
179 // Clicking save.
180 $self->click("_qf_Tag_next");
181 $self->waitForPageToLoad($self->getTimeoutMsec());
182
183 // Is status message correct?
184 $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved."));
185 }
186
187 // CRM-6586
188 function testContactSearchExport() {
189 $this->webtestLogin();
190
191 // Create new group
192 $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7);
193 $this->WebtestAddGroup($parentGroupName);
194
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);
198
199
200 // Adding Parent group contact
201 $firstName = substr(sha1(rand()), 0, 7);
202 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
203
204 $sortName = "Smith, $firstName";
205 $displayName = "$firstName Smith";
206
207 // add contact to parent group
208 // visit group tab
209 $this->click("css=li#tab_group a");
210 $this->waitForElementPresent("group_id");
211
212 // add to group
213 $this->select("group_id", "label=$parentGroupName");
214 $this->click("_qf_GroupContact_next");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
216
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");
221
222 $childSortName = "John, $childName";
223 $childDisplayName = "$childName John";
224
225 // add contact to child group
226 // visit group tab
227 $this->click("css=li#tab_group a");
228 $this->waitForElementPresent("group_id");
229
230 // add to child group
231 $this->select("group_id", "*$childGroupName");
232 $this->click("_qf_GroupContact_next");
233 $this->waitForPageToLoad($this->getTimeoutMsec());
234
235
236 // visit contact search page
237 $this->open($this->sboxPath . "civicrm/contact/search?reset=1");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
239
240
241 // select contact type as Indiividual
242 $this->select("contact_type", "value=Individual");
243
244 // select group
245 $this->select("group", "label=$parentGroupName");
246
247 // click to search
248 $this->click("_qf_Basic_refresh");
249 $this->waitForPageToLoad($this->getTimeoutMsec());
250
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);
254
255 // select to export all the contasct from search result
256 $this->click("CIVICRM_QFID_ts_all_4");
257
258 // Select the task action to export
259 $this->click("task");
260 $this->select("task", "label=Export Contacts");
261 $this->click("Go");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
263
264 $this->click("_qf_Select_next-bottom");
265 }
266 }