CRM-15603 - Standardize 'None found' messages
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvanceSearchPaneTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_AdvanceSearchPaneTest
31 */
6a488035
TO
32class WebTest_Contact_AdvanceSearchPaneTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Function to test individual pane seperatly.
40 */
41 function testIndividualPanes() {
6a488035
TO
42 $this->webtestLogin();
43
44 // Get all default advance search panes.
45 $allpanes = $this->_advanceSearchPanes();
46
47 // Test Individual panes.
48 foreach (array_keys($allpanes) as $pane) {
49 // Go to the Advance Search
d8bd5fb9 50 $this->openCiviPage('contact/search/advanced', 'reset=1');
6a488035
TO
51
52 // Select some fields from pane.
53 $this->_selectPaneFields($pane);
54
55 $this->click('_qf_Advanced_refresh');
56
57 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
58
59 // check the opened panes.
60 $this->_checkOpenedPanes(array($pane));
61 }
62 }
63
64 /*
65 * Function to test by selecting all panes at a time.
66 */
67 function testAllPanes() {
6a488035
TO
68 $this->webtestLogin();
69
70 // Get all default advance search panes.
71 $allpanes = $this->_advanceSearchPanes();
72
73 // Go to the Advance Search
d8bd5fb9 74 $this->openCiviPage('contact/search/advanced', 'reset=1');
6a488035
TO
75
76 // Select some fields from all default panes.
77 foreach (array_keys($allpanes) as $pane) {
78 $this->_selectPaneFields($pane);
79 }
80
81 $this->click('_qf_Advanced_refresh');
82
83 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
84
85 // check all opened panes.
86 $this->_checkOpenedPanes(array_keys($allpanes));
87 }
88
4cbe18b8
EM
89 /**
90 * @param array $openedPanes
91 */
6a488035
TO
92 function _checkOpenedPanes($openedPanes = array(
93 )) {
1eba7e53 94 if (!$this->isTextPresent('None found.')) {
6a488035
TO
95 $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header');
96 }
97
98 $allPanes = $this->_advanceSearchPanes();
99
100 foreach ($allPanes as $paneRef => $pane) {
101 if (in_array($paneRef, $openedPanes)) {
102 // assert for element present.
103 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
104 }
105 else {
106 $this->assertTrue(!$this->isElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}"));
107 }
108 }
109 }
110
4cbe18b8
EM
111 /**
112 * @param $paneRef
113 * @param array $selectFields
114 */
6a488035
TO
115 function _selectPaneFields($paneRef, $selectFields = array(
116 )) {
117 $pane = $this->_advanceSearchPanes($paneRef);
118
119 $this->click("css=div.crm-accordion-wrapper {$pane['headerLocator']}");
120 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
121
122 foreach ($pane['fields'] as $fld => $field) {
123 if (!empty($selectFields) && !in_array($fld, $selectFields)) {
124 continue;
125 }
126
127 $fldLocator = isset($field['locator']) ? $field['locator'] : '';
128
129 switch ($field['type']) {
130 case 'text':
131 $this->type($fldLocator, current($field['values']));
132 break;
133
134 case 'select':
135 foreach ($field['values'] as $op) {
136 $this->select($fldLocator, 'label=' . $op);
137 }
138 break;
139
140 case 'checkbox':
141 foreach ($field['values'] as $op) {
142 if (!$this->isChecked($op)) {
143 $this->click($op);
144 }
145 }
146 break;
147
148 case 'radio':
149 foreach ($field['values'] as $op) {
150 $this->click($op);
151 }
152 break;
153
ba6f320f
JP
154 case 'multiselect2':
155 foreach ($field['values'] as $op) {
156 $this->waitForVisible($fldLocator);
157 $this->multiselect2($fldLocator, $op);
158 }
159 break;
160
6a488035
TO
161 case 'date':
162 $this->webtestFillDate($fldLocator, current($field['values']));
163 break;
164 }
165 }
166 }
167
4cbe18b8
EM
168 /**
169 * @param null $paneRef
170 *
171 * @return array
172 */
6a488035
TO
173 function _advanceSearchPanes($paneRef = NULL) {
174 static $_advance_search_panes;
175
176 if (!isset($_advance_search_panes) || empty($_advance_search_panes)) {
177 $_advance_search_panes = array(
178 'location' =>
179 array(
180 'headerLocator' => 'div#location',
181 'bodyLocator' => 'select#country',
182 'title' => 'Address Fields',
183 'fields' =>
184 array(
185 'Location Type' =>
186 array(
ba6f320f
JP
187 'type' => 'multiselect2',
188 'locator' => 'location_type',
189 'values' => array(array('Home', 'Work')),
6a488035
TO
190 ),
191 'Country' =>
192 array(
193 'type' => 'select',
194 'locator' => 'country',
195 'values' => array('United States'),
196 ),
197 'State' =>
198 array(
ba6f320f 199 'type' => 'multiselect2',
6a488035 200 'locator' => 'state_province',
ba6f320f 201 'values' => array(array('Alabama', 'California', 'New Jersey', 'New York')),
6a488035
TO
202 ),
203 ),
204 ),
205 'custom' =>
206 array(
207 'headerLocator' => 'div#custom',
208 'bodyLocator' => 'div#constituent_information',
209 'title' => 'Custom Data',
210 'fields' =>
211 array(
212 'Marital Status' =>
213 array(
214 'type' => 'select',
215 'locator' => 'custom_2',
216 'values' => array('Single'),
217 ),
218 ),
219 ),
220 'activity' =>
221 array(
222 'headerLocator' => 'div#activity',
c02f3833 223 'bodyLocator' => 'input#activity_subject',
6a488035
TO
224 'title' => 'Activities',
225 'fields' =>
226 array(
227 'Activity Type' =>
228 array(
229 'type' => 'checkbox',
230 'values' => array('activity_type_id[6]', 'activity_type_id[3]', 'activity_type_id[5]', 'activity_type_id[7]'),
231 ),
232 'Activity Subject' =>
233 array(
234 'type' => 'text',
235 'locator' => 'activity_subject',
236 'values' => array('Test Subject'),
237 ),
238 'Activity Status' =>
239 array(
240 'type' => 'checkbox',
241 'values' => array('activity_status[1]', 'activity_status[2]'),
242 ),
243 ),
244 ),
245 'relationship' =>
246 array(
247 'headerLocator' => 'div#relationship',
248 'bodyLocator' => 'select#relation_type_id',
249 'title' => 'Relationships',
250 'fields' =>
251 array(
252 'Relation Type' =>
253 array(
254 'type' => 'select',
255 'locator' => 'relation_type_id',
256 'values' => array('Employee of'),
257 ),
258 'Relation Target' =>
259 array(
260 'type' => 'text',
261 'locator' => 'relation_target_name',
262 'values' => array('Test Contact'),
263 ),
264 ),
265 ),
266 'demographics' =>
267 array(
268 'headerLocator' => 'div#demographics',
269 'bodyLocator' => 'input#birth_date_low_display',
270 'title' => 'Demographics',
271 'fields' =>
272 array(
273 'Birth Date Range' =>
274 array(
275 'type' => 'select',
276 'locator' => 'birth_date_relative',
277 'values' => array('Choose Date Range'),
278 ),
279 'Birth Date from' =>
280 array(
281 'type' => 'date',
282 'locator' => 'birth_date_low',
283 'values' => array('10 September 1980'),
284 ),
285 'Birth Date to' =>
286 array(
287 'type' => 'date',
288 'locator' => 'birth_date_high',
289 'values' => array('10 September 2000'),
290 ),
291 ),
292 ),
293 'note' =>
294 array(
295 'headerLocator' => 'div#notes',
296 'bodyLocator' => 'input#note',
297 'title' => 'Notes',
298 'fields' =>
299 array(
300 'note' =>
301 array(
302 'type' => 'text',
303 'locator' => 'css=div#notes-search input#note',
304 'values' => array('Test Note'),
305 ),
306 ),
307 ),
308 'change_log' =>
309 array(
310 'headerLocator' => 'div#changeLog',
311 'bodyLocator' => 'input#changed_by',
312 'title' => 'Change Log',
313 'fields' =>
314 array(
315 'Modified By' =>
316 array(
317 'type' => 'text',
318 'locator' => 'changed_by',
319 'values' => array('Test User'),
320 ),
321 ),
322 ),
323 'contribution' =>
324 array(
325 'headerLocator' => 'div#CiviContribute',
326 'bodyLocator' => 'select#financial_type_id',
327 'title' => 'Contributions',
328 'fields' =>
329 array(
330 'Amount from' =>
331 array(
332 'type' => 'text',
333 'locator' => 'contribution_amount_low',
334 'values' => array('10'),
335 ),
336 'Amount to' =>
337 array(
338 'type' => 'text',
339 'locator' => 'contribution_amount_high',
340 'values' => array('1000'),
341 ),
76e86fd8
CW
342 'Financial Type' =>
343
6a488035
TO
344 array(
345 'type' => 'select',
346 'locator' => 'financial_type_id',
347 'values' => array('Donation'),
348 ),
349 'Contribution Status' =>
350 array(
351 'type' => 'checkbox',
352 'values' => array('contribution_status_id[1]', 'contribution_status_id[2]'),
353 ),
354 ),
355 ),
356 'membership' =>
357 array(
358 'headerLocator' => 'div#CiviMember',
359 'bodyLocator' => 'input#member_source',
360 'title' => 'Memberships',
361 'fields' =>
362 array(
363 'Membership Type' =>
364 array(
365 'type' => 'checkbox',
366 'values' => array('member_membership_type_id[1]', 'member_membership_type_id[2]'),
367 ),
368 'Membership Status' =>
369 array(
370 'type' => 'checkbox',
371 'values' => array('member_status_id[1]', 'member_status_id[2]'),
372 ),
373 ),
374 ),
375 'event' =>
376 array(
377 'headerLocator' => 'div#CiviEvent',
b5e4fcd9 378 'bodyLocator' => 'input#event_id',
6a488035
TO
379 'title' => 'Events',
380 'fields' =>
381 array(
382 'Participant Status' =>
383 array(
384 'type' => 'checkbox',
385 'values' => array('participant_status_id[1]', 'participant_status_id[2]'),
386 ),
387 'Participant Role' =>
388 array(
389 'type' => 'checkbox',
390 'values' => array('participant_role_id[1]', 'participant_role_id[2]'),
391 ),
392 ),
393 ),
394 );
395 }
396
397 if ($paneRef) {
398 return $_advance_search_panes[$paneRef];
399 }
400
401 return $_advance_search_panes;
402 }
403}
404