Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_AdvanceSearchPaneTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_AdvanceSearchPaneTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
59f4c9ee TO |
38 | /** |
39 | * Test individual pane seperatly. | |
6a488035 | 40 | */ |
00be9182 | 41 | public function testIndividualPanes() { |
6a488035 TO |
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 | |
d8bd5fb9 | 50 | $this->openCiviPage('contact/search/advanced', 'reset=1'); |
6a488035 TO |
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 | ||
59f4c9ee TO |
64 | /** |
65 | * Test by selecting all panes at a time. | |
6a488035 | 66 | */ |
00be9182 | 67 | public function testAllPanes() { |
6a488035 TO |
68 | $this->webtestLogin(); |
69 | ||
70 | // Get all default advance search panes. | |
71 | $allpanes = $this->_advanceSearchPanes(); | |
72 | ||
73 | // Go to the Advance Search | |
d8bd5fb9 | 74 | $this->openCiviPage('contact/search/advanced', 'reset=1'); |
6a488035 TO |
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 | ||
4cbe18b8 EM |
89 | /** |
90 | * @param array $openedPanes | |
91 | */ | |
59f4c9ee | 92 | public function _checkOpenedPanes($openedPanes = array()) { |
1eba7e53 | 93 | if (!$this->isTextPresent('None found.')) { |
6a488035 TO |
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 | ||
4cbe18b8 EM |
110 | /** |
111 | * @param $paneRef | |
112 | * @param array $selectFields | |
113 | */ | |
59f4c9ee | 114 | public function _selectPaneFields($paneRef, $selectFields = array()) { |
6a488035 TO |
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 | ||
ba6f320f JP |
152 | case 'multiselect2': |
153 | foreach ($field['values'] as $op) { | |
b86fcc87 | 154 | $this->waitForElementPresent($fldLocator); |
ba6f320f JP |
155 | $this->multiselect2($fldLocator, $op); |
156 | } | |
157 | break; | |
158 | ||
6a488035 TO |
159 | case 'date': |
160 | $this->webtestFillDate($fldLocator, current($field['values'])); | |
161 | break; | |
162 | } | |
163 | } | |
164 | } | |
165 | ||
4cbe18b8 EM |
166 | /** |
167 | * @param null $paneRef | |
168 | * | |
169 | * @return array | |
170 | */ | |
00be9182 | 171 | public function _advanceSearchPanes($paneRef = NULL) { |
6a488035 TO |
172 | static $_advance_search_panes; |
173 | ||
174 | if (!isset($_advance_search_panes) || empty($_advance_search_panes)) { | |
175 | $_advance_search_panes = array( | |
59f4c9ee TO |
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', | |
86797006 | 189 | 'values' => array('UNITED STATES'), |
59f4c9ee TO |
190 | ), |
191 | 'State' => array( | |
192 | 'type' => 'multiselect2', | |
193 | 'locator' => 'state_province', | |
194 | 'values' => array( | |
195 | array('Alabama', 'California', 'New Jersey', 'New York'), | |
92915c55 | 196 | ), |
59f4c9ee | 197 | ), |
6a488035 | 198 | ), |
59f4c9ee TO |
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 | ), | |
6a488035 | 210 | ), |
59f4c9ee TO |
211 | ), |
212 | 'activity' => array( | |
213 | 'headerLocator' => 'div#activity', | |
214 | 'bodyLocator' => 'input#activity_subject', | |
215 | 'title' => 'Activities', | |
216 | 'fields' => array( | |
217 | 'Activity Type' => array( | |
bfc3faa2 | 218 | 'type' => 'multiselect2', |
219 | 'locator' => 'activity_type_id', | |
220 | 'values' => array(array('Contribution', 'Email', 'Event Registration', 'Membership Signup')), | |
59f4c9ee TO |
221 | ), |
222 | 'Activity Subject' => array( | |
223 | 'type' => 'text', | |
224 | 'locator' => 'activity_subject', | |
225 | 'values' => array('Test Subject'), | |
226 | ), | |
227 | 'Activity Status' => array( | |
bfc3faa2 | 228 | 'type' => 'multiselect2', |
229 | 'locator' => 'status_id', | |
230 | 'values' => array(array('Scheduled', 'Completed')), | |
59f4c9ee | 231 | ), |
6a488035 | 232 | ), |
59f4c9ee TO |
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 | ), | |
6a488035 | 249 | ), |
59f4c9ee TO |
250 | ), |
251 | 'demographics' => array( | |
252 | 'headerLocator' => 'div#demographics', | |
bfc3faa2 | 253 | 'bodyLocator' => 'input#birth_date_low', |
59f4c9ee TO |
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 | ), | |
6a488035 | 271 | ), |
59f4c9ee TO |
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 | ), | |
6a488035 | 283 | ), |
59f4c9ee TO |
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 | ), | |
6a488035 | 295 | ), |
59f4c9ee TO |
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( | |
bfc3faa2 | 318 | 'type' => 'multiselect2', |
319 | 'locator' => 'contribution_status_id', | |
320 | 'values' => array(array('Completed', 'Pending')), | |
59f4c9ee | 321 | ), |
6a488035 | 322 | ), |
59f4c9ee TO |
323 | ), |
324 | 'membership' => array( | |
325 | 'headerLocator' => 'div#CiviMember', | |
326 | 'bodyLocator' => 'input#member_source', | |
327 | 'title' => 'Memberships', | |
328 | 'fields' => array( | |
329 | 'Membership Type' => array( | |
fb93fc39 | 330 | 'type' => 'select2', |
994bde4e SB |
331 | 'locator' => 'membership_type_id', |
332 | 'values' => array(array('General', 'Student')), | |
59f4c9ee TO |
333 | ), |
334 | 'Membership Status' => array( | |
994bde4e SB |
335 | 'type' => 'multiselect2', |
336 | 'locator' => 'membership_status_id', | |
337 | 'values' => array(array('New', 'Current')), | |
59f4c9ee | 338 | ), |
6a488035 | 339 | ), |
59f4c9ee TO |
340 | ), |
341 | 'event' => array( | |
342 | 'headerLocator' => 'div#CiviEvent', | |
343 | 'bodyLocator' => 'input#event_id', | |
344 | 'title' => 'Events', | |
345 | 'fields' => array( | |
346 | 'Participant Status' => array( | |
bfc3faa2 | 347 | 'type' => 'multiselect2', |
348 | 'locator' => 'participant_status_id', | |
349 | 'values' => array(array('Registered', 'Attended')), | |
59f4c9ee TO |
350 | ), |
351 | 'Participant Role' => array( | |
bfc3faa2 | 352 | 'type' => 'multiselect2', |
353 | 'locator' => 'participant_role_id', | |
354 | 'values' => array(array('Attendee', 'Volunteer')), | |
59f4c9ee | 355 | ), |
6a488035 | 356 | ), |
59f4c9ee | 357 | ), |
6a488035 TO |
358 | ); |
359 | } | |
360 | ||
361 | if ($paneRef) { | |
362 | return $_advance_search_panes[$paneRef]; | |
363 | } | |
364 | ||
365 | return $_advance_search_panes; | |
366 | } | |
96025800 | 367 | |
6a488035 | 368 | } |