Merge pull request #4004 from civicrm/4.4
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvanceSearchPaneTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 * Function to test individual pane seperatly.
40 */
41 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 * Function to test by selecting all panes at a time.
66 */
67 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 )) {
94 if (!$this->isTextPresent('No matches found')) {
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
111 /**
112 * @param $paneRef
113 * @param array $selectFields
114 */
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
154 case 'date':
155 $this->webtestFillDate($fldLocator, current($field['values']));
156 break;
157 }
158 }
159 }
160
161 /**
162 * @param null $paneRef
163 *
164 * @return array
165 */
166 function _advanceSearchPanes($paneRef = NULL) {
167 static $_advance_search_panes;
168
169 if (!isset($_advance_search_panes) || empty($_advance_search_panes)) {
170 $_advance_search_panes = array(
171 'location' =>
172 array(
173 'headerLocator' => 'div#location',
174 'bodyLocator' => 'select#country',
175 'title' => 'Address Fields',
176 'fields' =>
177 array(
178 'Location Type' =>
179 array(
180 'type' => 'checkbox',
181 'values' => array('location_type[1]', 'location_type[2]'),
182 ),
183 'Country' =>
184 array(
185 'type' => 'select',
186 'locator' => 'country',
187 'values' => array('United States'),
188 ),
189 'State' =>
190 array(
191 'type' => 'select',
192 'locator' => 'state_province',
193 'values' => array('Alabama', 'California', 'New Jersey', 'New York'),
194 ),
195 ),
196 ),
197 'custom' =>
198 array(
199 'headerLocator' => 'div#custom',
200 'bodyLocator' => 'div#constituent_information',
201 'title' => 'Custom Data',
202 'fields' =>
203 array(
204 'Marital Status' =>
205 array(
206 'type' => 'select',
207 'locator' => 'custom_2',
208 'values' => array('Single'),
209 ),
210 ),
211 ),
212 'activity' =>
213 array(
214 'headerLocator' => 'div#activity',
215 'bodyLocator' => 'input#activity_subject',
216 'title' => 'Activities',
217 'fields' =>
218 array(
219 'Activity Type' =>
220 array(
221 'type' => 'checkbox',
222 'values' => array('activity_type_id[6]', 'activity_type_id[3]', 'activity_type_id[5]', 'activity_type_id[7]'),
223 ),
224 'Activity Subject' =>
225 array(
226 'type' => 'text',
227 'locator' => 'activity_subject',
228 'values' => array('Test Subject'),
229 ),
230 'Activity Status' =>
231 array(
232 'type' => 'checkbox',
233 'values' => array('activity_status[1]', 'activity_status[2]'),
234 ),
235 ),
236 ),
237 'relationship' =>
238 array(
239 'headerLocator' => 'div#relationship',
240 'bodyLocator' => 'select#relation_type_id',
241 'title' => 'Relationships',
242 'fields' =>
243 array(
244 'Relation Type' =>
245 array(
246 'type' => 'select',
247 'locator' => 'relation_type_id',
248 'values' => array('Employee of'),
249 ),
250 'Relation Target' =>
251 array(
252 'type' => 'text',
253 'locator' => 'relation_target_name',
254 'values' => array('Test Contact'),
255 ),
256 ),
257 ),
258 'demographics' =>
259 array(
260 'headerLocator' => 'div#demographics',
261 'bodyLocator' => 'input#birth_date_low_display',
262 'title' => 'Demographics',
263 'fields' =>
264 array(
265 'Birth Date Range' =>
266 array(
267 'type' => 'select',
268 'locator' => 'birth_date_relative',
269 'values' => array('Choose Date Range'),
270 ),
271 'Birth Date from' =>
272 array(
273 'type' => 'date',
274 'locator' => 'birth_date_low',
275 'values' => array('10 September 1980'),
276 ),
277 'Birth Date to' =>
278 array(
279 'type' => 'date',
280 'locator' => 'birth_date_high',
281 'values' => array('10 September 2000'),
282 ),
283 ),
284 ),
285 'note' =>
286 array(
287 'headerLocator' => 'div#notes',
288 'bodyLocator' => 'input#note',
289 'title' => 'Notes',
290 'fields' =>
291 array(
292 'note' =>
293 array(
294 'type' => 'text',
295 'locator' => 'css=div#notes-search input#note',
296 'values' => array('Test Note'),
297 ),
298 ),
299 ),
300 'change_log' =>
301 array(
302 'headerLocator' => 'div#changeLog',
303 'bodyLocator' => 'input#changed_by',
304 'title' => 'Change Log',
305 'fields' =>
306 array(
307 'Modified By' =>
308 array(
309 'type' => 'text',
310 'locator' => 'changed_by',
311 'values' => array('Test User'),
312 ),
313 ),
314 ),
315 'contribution' =>
316 array(
317 'headerLocator' => 'div#CiviContribute',
318 'bodyLocator' => 'select#financial_type_id',
319 'title' => 'Contributions',
320 'fields' =>
321 array(
322 'Amount from' =>
323 array(
324 'type' => 'text',
325 'locator' => 'contribution_amount_low',
326 'values' => array('10'),
327 ),
328 'Amount to' =>
329 array(
330 'type' => 'text',
331 'locator' => 'contribution_amount_high',
332 'values' => array('1000'),
333 ),
334 'Financial Type' =>
335
336 array(
337 'type' => 'select',
338 'locator' => 'financial_type_id',
339 'values' => array('Donation'),
340 ),
341 'Contribution Status' =>
342 array(
343 'type' => 'checkbox',
344 'values' => array('contribution_status_id[1]', 'contribution_status_id[2]'),
345 ),
346 ),
347 ),
348 'membership' =>
349 array(
350 'headerLocator' => 'div#CiviMember',
351 'bodyLocator' => 'input#member_source',
352 'title' => 'Memberships',
353 'fields' =>
354 array(
355 'Membership Type' =>
356 array(
357 'type' => 'checkbox',
358 'values' => array('member_membership_type_id[1]', 'member_membership_type_id[2]'),
359 ),
360 'Membership Status' =>
361 array(
362 'type' => 'checkbox',
363 'values' => array('member_status_id[1]', 'member_status_id[2]'),
364 ),
365 ),
366 ),
367 'event' =>
368 array(
369 'headerLocator' => 'div#CiviEvent',
370 'bodyLocator' => 'input#event_id',
371 'title' => 'Events',
372 'fields' =>
373 array(
374 'Participant Status' =>
375 array(
376 'type' => 'checkbox',
377 'values' => array('participant_status_id[1]', 'participant_status_id[2]'),
378 ),
379 'Participant Role' =>
380 array(
381 'type' => 'checkbox',
382 'values' => array('participant_role_id[1]', 'participant_role_id[2]'),
383 ),
384 ),
385 ),
386 );
387 }
388
389 if ($paneRef) {
390 return $_advance_search_panes[$paneRef];
391 }
392
393 return $_advance_search_panes;
394 }
395 }
396