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