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