Merge pull request #5680 from elinw/restauthenticationjoomla
[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-2015 |
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 public 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 public 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' => array(
177 'headerLocator' => 'div#location',
178 'bodyLocator' => 'select#country',
179 'title' => 'Address Fields',
180 'fields' => array(
181 'Location Type' => array(
182 'type' => 'multiselect2',
183 'locator' => 'location_type',
184 'values' => array(array('Home', 'Work')),
185 ),
186 'Country' => array(
187 'type' => 'select',
188 'locator' => 'country',
189 'values' => array('United States'),
190 ),
191 'State' => array(
192 'type' => 'multiselect2',
193 'locator' => 'state_province',
194 'values' => array(
195 array('Alabama', 'California', 'New Jersey', 'New York'),
196 ),
197 ),
198 ),
199 ),
200 'custom' => array(
201 'headerLocator' => 'div#custom',
202 'bodyLocator' => 'div#constituent_information',
203 'title' => 'Custom Data',
204 'fields' => array(
205 'Marital Status' => array(
206 'type' => 'select',
207 'locator' => 'custom_2',
208 'values' => array('Single'),
209 ),
210 ),
211 ),
212 'activity' => array(
213 'headerLocator' => 'div#activity',
214 'bodyLocator' => 'input#activity_subject',
215 'title' => 'Activities',
216 'fields' => array(
217 'Activity Type' => array(
218 'type' => 'multiselect2',
219 'locator' => 'activity_type_id',
220 'values' => array(array('Contribution', 'Email', 'Event Registration', 'Membership Signup')),
221 ),
222 'Activity Subject' => array(
223 'type' => 'text',
224 'locator' => 'activity_subject',
225 'values' => array('Test Subject'),
226 ),
227 'Activity Status' => array(
228 'type' => 'multiselect2',
229 'locator' => 'status_id',
230 'values' => array(array('Scheduled', 'Completed')),
231 ),
232 ),
233 ),
234 'relationship' => array(
235 'headerLocator' => 'div#relationship',
236 'bodyLocator' => 'select#relation_type_id',
237 'title' => 'Relationships',
238 'fields' => array(
239 'Relation Type' => array(
240 'type' => 'select',
241 'locator' => 'relation_type_id',
242 'values' => array('Employee of'),
243 ),
244 'Relation Target' => array(
245 'type' => 'text',
246 'locator' => 'relation_target_name',
247 'values' => array('Test Contact'),
248 ),
249 ),
250 ),
251 'demographics' => array(
252 'headerLocator' => 'div#demographics',
253 'bodyLocator' => 'input#birth_date_low',
254 'title' => 'Demographics',
255 'fields' => array(
256 'Birth Date Range' => array(
257 'type' => 'select',
258 'locator' => 'birth_date_relative',
259 'values' => array('Choose Date Range'),
260 ),
261 'Birth Date from' => array(
262 'type' => 'date',
263 'locator' => 'birth_date_low',
264 'values' => array('10 September 1980'),
265 ),
266 'Birth Date to' => array(
267 'type' => 'date',
268 'locator' => 'birth_date_high',
269 'values' => array('10 September 2000'),
270 ),
271 ),
272 ),
273 'note' => array(
274 'headerLocator' => 'div#notes',
275 'bodyLocator' => 'input#note',
276 'title' => 'Notes',
277 'fields' => array(
278 'note' => array(
279 'type' => 'text',
280 'locator' => 'css=div#notes-search input#note',
281 'values' => array('Test Note'),
282 ),
283 ),
284 ),
285 'change_log' => array(
286 'headerLocator' => 'div#changeLog',
287 'bodyLocator' => 'input#changed_by',
288 'title' => 'Change Log',
289 'fields' => array(
290 'Modified By' => array(
291 'type' => 'text',
292 'locator' => 'changed_by',
293 'values' => array('Test User'),
294 ),
295 ),
296 ),
297 'contribution' => array(
298 'headerLocator' => 'div#CiviContribute',
299 'bodyLocator' => 'select#financial_type_id',
300 'title' => 'Contributions',
301 'fields' => array(
302 'Amount from' => array(
303 'type' => 'text',
304 'locator' => 'contribution_amount_low',
305 'values' => array('10'),
306 ),
307 'Amount to' => array(
308 'type' => 'text',
309 'locator' => 'contribution_amount_high',
310 'values' => array('1000'),
311 ),
312 'Financial Type' => array(
313 'type' => 'select',
314 'locator' => 'financial_type_id',
315 'values' => array('Donation'),
316 ),
317 'Contribution Status' => array(
318 'type' => 'multiselect2',
319 'locator' => 'contribution_status_id',
320 'values' => array(array('Completed', 'Pending')),
321 ),
322 ),
323 ),
324 'membership' => array(
325 'headerLocator' => 'div#CiviMember',
326 'bodyLocator' => 'input#member_source',
327 'title' => 'Memberships',
328 'fields' => array(
329 'Membership Type' => array(
330 'type' => 'multiselect2',
331 'locator' => 'membership_type_id',
332 'values' => array(array('General', 'Student')),
333 ),
334 'Membership Status' => array(
335 'type' => 'multiselect2',
336 'locator' => 'membership_status_id',
337 'values' => array(array('New', 'Current')),
338 ),
339 ),
340 ),
341 'event' => array(
342 'headerLocator' => 'div#CiviEvent',
343 'bodyLocator' => 'input#event_id',
344 'title' => 'Events',
345 'fields' => array(
346 'Participant Status' => array(
347 'type' => 'multiselect2',
348 'locator' => 'participant_status_id',
349 'values' => array(array('Registered', 'Attended')),
350 ),
351 'Participant Role' => array(
352 'type' => 'multiselect2',
353 'locator' => 'participant_role_id',
354 'values' => array(array('Attendee', 'Volunteer')),
355 ),
356 ),
357 ),
358 );
359 }
360
361 if ($paneRef) {
362 return $_advance_search_panes[$paneRef];
363 }
364
365 return $_advance_search_panes;
366 }
367
368 }