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