Merge pull request #2744 from pratik-joshi/CRM-13992_temp_fix
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SearchbyDateFilterTest.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 class WebTest_Contact_SearchbyDateFilterTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 /*
35 * Function to test individual pane seperatly.
36 */
37 function testAdvancedSearch() {
38 $this->webtestLogin();
39
40 // Get all default advance search panes.
41 $allpanes = $this->_advanceSearchPanesDateFilter();
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 // check the opened panes.
55 $this->_checkOpenedPanes(array($pane));
56 }
57
58 }
59
60 function testIndividualSearchPage(){
61 $this->webtestLogin();
62
63 $this->openCiviPage("contribute/search", "reset=1");
64 $this->select("contribution_date_relative","value=previous_before.quarter");
65 $this->click("_qf_Search_refresh");
66 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
67 $this->select("contribution_date_relative","value=previous_2.quarter");
68 $this->click("_qf_Search_refresh");
69 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
70 $this->select("contribution_date_relative","value=earlier.quarter");
71 $this->click("_qf_Search_refresh");
72 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
73 $this->select("contribution_date_relative","value=ending.year");
74
75 $this->click("_qf_Search_refresh");
76 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
77
78 $this->openCiviPage("member/search", "reset=1");
79 $this->select("member_end_date_relative","value=previous_before.month");
80 $this->click("_qf_Search_refresh");
81 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
82 $this->select("member_end_date_relative","value=previous_2.month");
83 $this->click("_qf_Search_refresh");
84 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
85 $this->select("member_end_date_relative","value=earlier.month");
86 $this->click("_qf_Search_refresh");
87 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
88 $this->select("member_end_date_relative","value=ending.month");
89 $this->click("_qf_Search_refresh");
90 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
91
92 $this->openCiviPage("event/search", "reset=1");
93 $this->select("event_relative","value=previous_before.week");
94 $this->click("_qf_Search_refresh");
95 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
96 $this->select("event_relative","value=previous_2.week");
97 $this->click("_qf_Search_refresh");
98 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
99 $this->select("event_relative","value=earlier.week");
100 $this->click("_qf_Search_refresh");
101 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
102 $this->select("event_relative","value=ending.week");
103 $this->click("_qf_Search_refresh");
104 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
105
106 $this->openCiviPage("activity/search", "reset=1");
107 $this->select("activity_date_relative","value=previous_before.day");
108 $this->click("_qf_Search_refresh");
109 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
110 $this->select("activity_date_relative","value=previous_2.day");
111 $this->click("_qf_Search_refresh");
112 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
113 $this->select("activity_date_relative","value=earlier.day");
114 $this->click("_qf_Search_refresh");
115 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
116 $this->select("activity_date_relative","value=ending.quarter");
117 $this->click("_qf_Search_refresh");
118 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
119
120 $this->openCiviPage("pledge/search", "reset=1");
121 $this->select("pledge_payment_date_relative","value=greater.week");
122 $this->click("_qf_Search_refresh");
123 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
124 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
125 $this->select("pledge_payment_date_relative","value=greater.day");
126 $this->click("_qf_Search_refresh");
127 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
128 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
129 $this->select("pledge_payment_date_relative","value=greater.quarter");
130 $this->click("_qf_Search_refresh");
131 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
132 $this->click("xpath=//form[@id='Search']/div[2]/div/div");
133 $this->select("pledge_payment_date_relative","value=greater.month");
134 $this->click("_qf_Search_refresh");
135 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
136
137 $this->openCiviPage("mailing", "reset=1");
138 $this->select("mailing_relative","value=previous_before.year");
139 $this->click("_qf_Search_refresh");
140 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
141 $this->select("mailing_relative","value=previous_2.year");
142 $this->click("_qf_Search_refresh");
143 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
144 $this->select("mailing_relative","value=earlier.year");
145 $this->click("_qf_Search_refresh");
146 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
147 $this->select("mailing_relative","value=greater.year");
148 $this->click("_qf_Search_refresh");
149 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
150 }
151
152 function _checkOpenedPanes($openedPanes = array(
153 )) {
154 if (!$this->isTextPresent('No matches found')) {
155 $this->click('css=div.crm-advanced_search_form-accordion div.crm-accordion-header');
156 }
157
158 $allPanes = $this->_advanceSearchPanesDateFilter();
159
160 foreach ($allPanes as $paneRef => $pane) {
161 if (in_array($paneRef, $openedPanes)) {
162 // assert for element present.
163 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
164 }
165 else {
166 $this->assertTrue(!$this->isElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}"));
167 }
168 }
169 }
170
171 function _selectPaneFields($paneRef, $selectFields = array(
172 )) {
173 $pane = $this->_advanceSearchPanesDateFilter($paneRef);
174
175 $this->click("css=div.crm-accordion-wrapper {$pane['headerLocator']}");
176 $this->waitForElementPresent("css=div.crm-accordion-wrapper div.crm-accordion-body {$pane['bodyLocator']}");
177
178 foreach ($pane['fields'] as $fld => $field) {
179 if (!empty($selectFields) && !in_array($fld, $selectFields)) {
180 continue;
181 }
182
183 $fldLocator = isset($field['locator']) ? $field['locator'] : '';
184
185 switch ($field['type']) {
186 case 'text':
187 $this->type($fldLocator, current($field['values']));
188 break;
189
190 case 'select':
191 foreach ($field['values'] as $op) {
192 $this->select($fldLocator, 'label=' . $op);
193 }
194 break;
195
196 case 'checkbox':
197 foreach ($field['values'] as $op) {
198 if (!$this->isChecked($op)) {
199 $this->click($op);
200 }
201 }
202 break;
203
204 case 'radio':
205 foreach ($field['values'] as $op) {
206 $this->click($op);
207 }
208 break;
209
210 case 'date':
211 $this->webtestFillDate($fldLocator, current($field['values']));
212 break;
213 }
214 }
215 }
216
217 function _advanceSearchPanesDateFilter($paneRef = NULL) {
218 static $_advance_search_panes;
219
220 if (!isset($_advance_search_panes) || empty($_advance_search_panes)) {
221 $_advance_search_panes = array(
222 'activity' =>
223 array(
224 'headerLocator' => 'div#activity',
225 'bodyLocator' => 'select#activity_date_relative',
226 'title' => 'Activities',
227 'fields' =>
228 array(
229 'Activity Dates' =>
230 array(
231 'type' => 'select',
232 'locator' => 'activity_date_relative',
233 'values' => array('This Year'),
234 ),
235 ),
236 ),
237 'demographics' =>
238 array(
239 'headerLocator' => 'div#demographics',
240 'bodyLocator' => 'input#birth_date_low_display',
241 'title' => 'Demographics',
242 'fields' =>
243 array(
244 'Deceased Dates' =>
245 array(
246 'type' => 'select',
247 'locator' => 'deceased_date_relative',
248 'values' => array('This Quarter'),
249 ),
250 ),
251 ),
252 'change_log' =>
253 array(
254 'headerLocator' => 'div#changeLog',
255 'bodyLocator' => 'input#changed_by',
256 'title' => 'Change Log',
257 'fields' =>
258 array(
259 'Modified Between' =>
260 array(
261 'type' => 'select',
262 'locator' => 'log_date_relative',
263 'values' => array('This Week'),
264 ),
265 ),
266 ),
267 'mailing' =>
268 array(
269 'headerLocator' => 'div#CiviMail',
270 'bodyLocator' => 'select#mailing_date_relative',
271 'title' => 'Mailings',
272 'fields' =>
273 array(
274 'Mailing Date' =>
275 array(
276 'type' => 'select',
277 'locator' => 'mailing_date_relative',
278 'values' => array('Prior to Previous Quarter'),
279 ),
280 ),
281 ),
282
283 'contribution' =>
284 array(
285 'headerLocator' => 'div#CiviContribute',
286 'bodyLocator' => 'select#financial_type_id',
287 'title' => 'Contributions',
288 'fields' =>
289 array(
290 'Contribution Dates' =>
291 array(
292 'type' => 'select',
293 'locator' => 'contribution_date_relative',
294 'values' => array('This Day'),
295 ),
296 ),
297 ),
298 'pledge' =>
299 array(
300 'headerLocator' => 'div#CiviPledge',
301 'bodyLocator' => 'select#pledge_payment_date_relative',
302 'title' => 'Pledges',
303 'fields' =>
304 array(
305 'Contribution Dates' =>
306 array(
307 'type' => 'select',
308 'locator' => 'pledge_payment_date_relative',
309 'values' => array('Prior to Previous Month'),
310 ),
311 ),
312 ),
313 'membership' =>
314 array(
315 'headerLocator' => 'div#CiviMember',
316 'bodyLocator' => 'input#member_source',
317 'title' => 'Memberships',
318 'fields' =>
319 array(
320 'Member Since' =>
321 array(
322 'type' => 'select',
323 'locator' => 'member_join_date_relative',
324 'values' => array('Previous Year'),
325 ),
326
327 ),
328 ),
329 'event' =>
330 array(
331 'headerLocator' => 'div#CiviEvent',
332 'bodyLocator' => 'input#event_id',
333 'title' => 'Events',
334 'fields' =>
335 array(
336 'Event Dates' =>
337 array(
338 'type' => 'select',
339 'locator' => 'event_relative',
340 'values' => array('Previous Week'),
341 ),
342 ),
343 ),
344
345 );
346 }
347
348 if ($paneRef) {
349 return $_advance_search_panes[$paneRef];
350 }
351
352 return $_advance_search_panes;
353 }
354 }
355