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