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