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