Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Include configuration | |
30 | */ | |
31 | define('CIVICRM_SETTINGS_PATH', __DIR__ . '/civicrm.settings.dist.php'); | |
32 | define('CIVICRM_SETTINGS_LOCAL_PATH', __DIR__ . '/civicrm.settings.local.php'); | |
aa2733c0 | 33 | define('CIVICRM_WEBTEST', 1); |
6a488035 TO |
34 | |
35 | if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) { | |
36 | require_once CIVICRM_SETTINGS_LOCAL_PATH; | |
37 | } | |
38 | require_once CIVICRM_SETTINGS_PATH; | |
39 | ||
40 | /** | |
41 | * Base class for CiviCRM Selenium tests | |
42 | * | |
43 | * Common functions for unit tests | |
44 | * @package CiviCRM | |
45 | */ | |
46 | class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { | |
47 | ||
42daf119 CW |
48 | // Current logged-in user |
49 | protected $loggedInAs = NULL; | |
6a488035 | 50 | |
d3f2fd13 TO |
51 | private $settingCache; |
52 | ||
6a488035 | 53 | /** |
eceb18cc | 54 | * Constructor. |
6a488035 TO |
55 | * |
56 | * Because we are overriding the parent class constructor, we | |
57 | * need to show the same arguments as exist in the constructor of | |
58 | * PHPUnit_Framework_TestCase, since | |
59 | * PHPUnit_Framework_TestSuite::createTest() creates a | |
60 | * ReflectionClass of the Test class and checks the constructor | |
61 | * of that class to decide how to set up the test. | |
62 | * | |
e16033b4 TO |
63 | * @param string $name |
64 | * @param array $data | |
65 | * @param string $dataName | |
2a6da8d7 | 66 | * @param array $browser |
6a488035 | 67 | */ |
00be9182 | 68 | public function __construct($name = NULL, array$data = array(), $dataName = '', array$browser = array()) { |
6a488035 | 69 | parent::__construct($name, $data, $dataName, $browser); |
42daf119 | 70 | $this->loggedInAs = NULL; |
6a488035 TO |
71 | |
72 | require_once 'CiviSeleniumSettings.php'; | |
73 | $this->settings = new CiviSeleniumSettings(); | |
b5c0ad9a TO |
74 | if (property_exists($this->settings, 'serverStartupTimeOut') && $this->settings->serverStartupTimeOut) { |
75 | global $CiviSeleniumTestCase_polled; | |
76 | if (!$CiviSeleniumTestCase_polled) { | |
77 | $CiviSeleniumTestCase_polled = TRUE; | |
78 | CRM_Utils_Network::waitForServiceStartup( | |
79 | $this->drivers[0]->getHost(), | |
80 | $this->drivers[0]->getPort(), | |
81 | $this->settings->serverStartupTimeOut | |
82 | ); | |
83 | } | |
84 | } | |
6a488035 TO |
85 | |
86 | // autoload | |
87 | require_once 'CRM/Core/ClassLoader.php'; | |
88 | CRM_Core_ClassLoader::singleton()->register(); | |
89 | ||
90 | // also initialize a connection to the db | |
42daf119 | 91 | // FIXME: not necessary for most tests, consider moving into functions that need this |
6a488035 TO |
92 | $config = CRM_Core_Config::singleton(); |
93 | } | |
94 | ||
95 | protected function setUp() { | |
96 | $this->setBrowser($this->settings->browser); | |
97 | // Make sure that below strings have path separator at the end | |
98 | $this->setBrowserUrl($this->settings->sandboxURL); | |
99 | $this->sboxPath = $this->settings->sandboxPATH; | |
b5c0ad9a TO |
100 | if (property_exists($this->settings, 'rcHost') && $this->settings->rcHost) { |
101 | $this->setHost($this->settings->rcHost); | |
102 | } | |
103 | if (property_exists($this->settings, 'rcPort') && $this->settings->rcPort) { | |
104 | $this->setPort($this->settings->rcPort); | |
105 | } | |
d3f2fd13 | 106 | $this->settingCache = array(); |
6a488035 TO |
107 | } |
108 | ||
7fe37828 EM |
109 | /** |
110 | * @return string | |
111 | */ | |
bf446982 TO |
112 | protected function prepareTestSession() { |
113 | $result = parent::prepareTestSession(); | |
114 | ||
115 | // Set any cookies required by local installation | |
116 | // Note: considered doing this in setUp(), but the Selenium session wasn't yet initialized. | |
117 | if (property_exists($this->settings, 'cookies')) { | |
118 | // We don't really care about this page, but it seems we need | |
119 | // to open a page before setting a cookie. | |
120 | $this->open($this->sboxPath); | |
121 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
122 | $this->setCookies($this->settings->cookies); | |
123 | } | |
124 | return $result; | |
125 | } | |
126 | ||
127 | /** | |
e16033b4 | 128 | * @param array $cookies |
16b10e64 CW |
129 | * Each item is an Array with keys: |
130 | * - name: string | |
131 | * - value: string; note that RFC's don't define particular encoding scheme, so | |
bf446982 TO |
132 | * you must pick one yourself and pre-encode; does not allow values with |
133 | * commas, semicolons, or whitespace | |
16b10e64 CW |
134 | * - path: string; default: '/' |
135 | * - max_age: int; default: 1 week (7*24*60*60) | |
bf446982 TO |
136 | */ |
137 | protected function setCookies($cookies) { | |
138 | foreach ($cookies as $cookie) { | |
139 | if (!isset($cookie['path'])) { | |
140 | $cookie['path'] = '/'; | |
141 | } | |
142 | if (!isset($cookie['max_age'])) { | |
6c6e6187 | 143 | $cookie['max_age'] = 7 * 24 * 60 * 60; |
bf446982 TO |
144 | } |
145 | $this->deleteCookie($cookie['name'], $cookie['path']); | |
146 | $optionExprs = array(); | |
147 | foreach ($cookie as $key => $value) { | |
148 | if ($key != 'name' && $key != 'value') { | |
149 | $optionExprs[] = "$key=$value"; | |
150 | } | |
151 | } | |
152 | $this->createCookie("{$cookie['name']}={$cookie['value']}", implode(', ', $optionExprs)); | |
153 | } | |
154 | } | |
155 | ||
6a488035 | 156 | protected function tearDown() { |
6a488035 TO |
157 | } |
158 | ||
159 | /** | |
eceb18cc | 160 | * Authenticate as drupal user. |
5896d037 TO |
161 | * @param $user : (str) the key 'user' or 'admin', or a literal username |
162 | * @param $pass : (str) if $user is a literal username and not 'user' or 'admin', supply the password | |
6a488035 | 163 | */ |
00be9182 | 164 | public function webtestLogin($user = 'user', $pass = NULL) { |
42daf119 CW |
165 | // If already logged in as correct user, do nothing |
166 | if ($this->loggedInAs === $user) { | |
167 | return; | |
168 | } | |
169 | // If we are logged in as a different user, log out first | |
170 | if ($this->loggedInAs) { | |
171 | $this->webtestLogout(); | |
172 | } | |
6a488035 | 173 | $this->open("{$this->sboxPath}user"); |
42daf119 CW |
174 | // Lookup username & password if not supplied |
175 | $username = $user; | |
176 | if ($pass === NULL) { | |
177 | $pass = $user == 'admin' ? $this->settings->adminPassword : $this->settings->password; | |
178 | $username = $user == 'admin' ? $this->settings->adminUsername : $this->settings->username; | |
179 | } | |
6a488035 TO |
180 | // Make sure login form is available |
181 | $this->waitForElementPresent('edit-submit'); | |
182 | $this->type('edit-name', $username); | |
42daf119 | 183 | $this->type('edit-pass', $pass); |
6a488035 TO |
184 | $this->click('edit-submit'); |
185 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
42daf119 CW |
186 | $this->loggedInAs = $user; |
187 | } | |
188 | ||
00be9182 | 189 | public function webtestLogout() { |
42daf119 CW |
190 | if ($this->loggedInAs) { |
191 | $this->open($this->sboxPath . "user/logout"); | |
192 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
193 | } | |
194 | $this->loggedInAs = NULL; | |
6a488035 TO |
195 | } |
196 | ||
197 | /** | |
198 | * Open an internal path beginning with 'civicrm/' | |
199 | * | |
5a4f6742 CW |
200 | * @param string $url |
201 | * omit the 'civicrm/' it will be added for you. | |
202 | * @param string|array $args | |
203 | * optional url arguments. | |
e16033b4 TO |
204 | * @param $waitFor |
205 | * Page element to wait for - using this is recommended to ensure the document is fully loaded. | |
6a488035 TO |
206 | * |
207 | * Although it doesn't seem to do much now, using this function is recommended for | |
208 | * opening all civi pages, and using the $args param is also strongly encouraged | |
209 | * This will make it much easier to run webtests in other CMSs in the future | |
210 | */ | |
00be9182 | 211 | public function openCiviPage($url, $args = NULL, $waitFor = 'civicrm-footer') { |
6a488035 TO |
212 | // Construct full url with args |
213 | // This could be extended in future to work with other CMS style urls | |
214 | if ($args) { | |
215 | if (is_array($args)) { | |
216 | $sep = '?'; | |
217 | foreach ($args as $key => $val) { | |
218 | $url .= $sep . $key . '=' . $val; | |
219 | $sep = '&'; | |
220 | } | |
221 | } | |
222 | else { | |
223 | $url .= "?$args"; | |
224 | } | |
225 | } | |
226 | $this->open("{$this->sboxPath}civicrm/$url"); | |
42daf119 | 227 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
b50973e8 | 228 | $this->checkForErrorsOnPage(); |
6a488035 TO |
229 | if ($waitFor) { |
230 | $this->waitForElementPresent($waitFor); | |
231 | } | |
232 | } | |
233 | ||
b45c587e | 234 | /** |
eceb18cc | 235 | * Click on a link or button. |
b45c587e CW |
236 | * Wait for the page to load |
237 | * Wait for an element to be present | |
1e1fdcf6 EM |
238 | * @param $element |
239 | * @param string $waitFor | |
240 | * @param bool $waitForPageLoad | |
b45c587e | 241 | */ |
00be9182 | 242 | public function clickLink($element, $waitFor = 'civicrm-footer', $waitForPageLoad = TRUE) { |
b45c587e | 243 | $this->click($element); |
28154ee7 PJ |
244 | // conditional wait for page load e.g for ajax form save |
245 | if ($waitForPageLoad) { | |
246 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
b50973e8 | 247 | $this->checkForErrorsOnPage(); |
28154ee7 | 248 | } |
b45c587e CW |
249 | if ($waitFor) { |
250 | $this->waitForElementPresent($waitFor); | |
251 | } | |
252 | } | |
405bc6ee CW |
253 | |
254 | /** | |
eceb18cc | 255 | * Click a link or button and wait for an ajax dialog to load. |
50d95825 CW |
256 | * @param string $element |
257 | * @param string $waitFor | |
258 | */ | |
6c6e6187 | 259 | public function clickPopupLink($element, $waitFor = NULL) { |
a5d61f09 CW |
260 | $this->clickAjaxLink($element, 'css=.ui-dialog'); |
261 | if ($waitFor) { | |
262 | $this->waitForElementPresent($waitFor); | |
263 | } | |
264 | } | |
265 | ||
266 | /** | |
eceb18cc | 267 | * Click a link or button and wait for ajax content to load or refresh. |
a5d61f09 CW |
268 | * @param string $element |
269 | * @param string $waitFor | |
270 | */ | |
6c6e6187 | 271 | public function clickAjaxLink($element, $waitFor = NULL) { |
50d95825 | 272 | $this->click($element); |
50d95825 CW |
273 | if ($waitFor) { |
274 | $this->waitForElementPresent($waitFor); | |
275 | } | |
57d32317 | 276 | $this->waitForAjaxContent(); |
50d95825 CW |
277 | } |
278 | ||
279 | /** | |
280 | * Force a link to open full-page, even if it would normally open in a popup | |
e739afc3 | 281 | * @note: works with links only, not buttons |
50d95825 | 282 | * @param string $element |
405bc6ee CW |
283 | * @param string $waitFor |
284 | */ | |
00be9182 | 285 | public function clickLinkSuppressPopup($element, $waitFor = 'civicrm-footer') { |
405bc6ee CW |
286 | $link = $this->getAttribute($element . '@href'); |
287 | $this->open($link); | |
288 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
289 | if ($waitFor) { | |
290 | $this->waitForElementPresent($waitFor); | |
291 | } | |
292 | } | |
b45c587e | 293 | |
50d95825 | 294 | /** |
eceb18cc | 295 | * Wait for all ajax snippets to finish loading. |
50d95825 | 296 | */ |
00be9182 | 297 | public function waitForAjaxContent() { |
50d95825 | 298 | $this->waitForElementNotPresent('css=.blockOverlay'); |
e739afc3 CW |
299 | // Some ajax calls happen in pairs (e.g. submit a popup form then refresh the underlying content) |
300 | // So we'll wait a sec and recheck to see if any more stuff is loading | |
301 | sleep(1); | |
302 | if ($this->isElementPresent('css=.blockOverlay')) { | |
303 | $this->waitForAjaxContent(); | |
304 | } | |
50d95825 CW |
305 | } |
306 | ||
6a488035 | 307 | /** |
eceb18cc | 308 | * Call the API on the local server. |
6a488035 | 309 | * (kind of defeats the point of a webtest - see CRM-11889) |
1e1fdcf6 EM |
310 | * @param $entity |
311 | * @param $action | |
312 | * @param $params | |
313 | * @return array|int | |
6a488035 | 314 | */ |
00be9182 | 315 | public function webtest_civicrm_api($entity, $action, $params) { |
6a488035 TO |
316 | if (!isset($params['version'])) { |
317 | $params['version'] = 3; | |
318 | } | |
319 | ||
320 | $result = civicrm_api($entity, $action, $params); | |
ef9cbdb7 | 321 | $this->assertAPISuccess($result); |
6a488035 TO |
322 | return $result; |
323 | } | |
324 | ||
325 | /** | |
ef9cbdb7 TO |
326 | * Call the API on the remote server using the AJAX endpoint. |
327 | * | |
6a488035 | 328 | * @see CRM-11889 |
1e1fdcf6 EM |
329 | * @param $entity |
330 | * @param $action | |
331 | * @param array $params | |
332 | * @return mixed | |
6a488035 | 333 | */ |
00be9182 | 334 | public function rest_civicrm_api($entity, $action, $params = array()) { |
6a488035 TO |
335 | $params += array( |
336 | 'version' => 3, | |
337 | ); | |
ef9cbdb7 TO |
338 | static $reqId = 0; |
339 | $reqId++; | |
340 | ||
341 | $jsCmd = ' | |
342 | setTimeout(function(){ | |
343 | CRM.api3("@entity", "@action", @params).then(function(a){ | |
344 | cj("<textarea>").css("display", "none").prop("id","crmajax@reqId").val(JSON.stringify(a)).appendTo("body"); | |
345 | }); | |
346 | }, 500); | |
347 | '; | |
348 | $jsArgs = array( | |
349 | '@entity' => $entity, | |
350 | '@action' => $action, | |
351 | '@params' => json_encode($params), | |
352 | '@reqId' => $reqId, | |
6a488035 | 353 | ); |
ef9cbdb7 TO |
354 | $js = strtr($jsCmd, $jsArgs); |
355 | $this->runScript($js); | |
356 | $this->waitForElementPresent("crmajax{$reqId}"); | |
357 | $result = json_decode($this->getValue("crmajax{$reqId}"), TRUE); | |
358 | $this->runScript("cj('#crmajax{$reqId}').remove();"); | |
359 | return $result; | |
6a488035 TO |
360 | } |
361 | ||
4cbe18b8 | 362 | /** |
100fef9d | 363 | * @param string $option_group_name |
4cbe18b8 EM |
364 | * |
365 | * @return array|int | |
366 | */ | |
00be9182 | 367 | public function webtestGetFirstValueForOptionGroup($option_group_name) { |
6a488035 TO |
368 | $result = $this->webtest_civicrm_api("OptionValue", "getvalue", array( |
369 | 'option_group_name' => $option_group_name, | |
370 | 'option.limit' => 1, | |
21dfd5f5 | 371 | 'return' => 'value', |
6a488035 TO |
372 | )); |
373 | return $result; | |
374 | } | |
375 | ||
4cbe18b8 EM |
376 | /** |
377 | * @return mixed | |
378 | */ | |
00be9182 | 379 | public function webtestGetValidCountryID() { |
6a488035 TO |
380 | static $_country_id; |
381 | if (is_null($_country_id)) { | |
382 | $config_backend = $this->webtestGetConfig('countryLimit'); | |
383 | $_country_id = current($config_backend); | |
384 | } | |
385 | return $_country_id; | |
386 | } | |
387 | ||
4cbe18b8 EM |
388 | /** |
389 | * @param $entity | |
390 | * | |
391 | * @return mixed|null | |
392 | */ | |
00be9182 | 393 | public function webtestGetValidEntityID($entity) { |
6a488035 TO |
394 | // michaelmcandrew: would like to use getvalue but there is a bug |
395 | // for e.g. group where option.limit not working at the moment CRM-9110 | |
396 | $result = $this->webtest_civicrm_api($entity, "get", array('option.limit' => 1, 'return' => 'id')); | |
397 | if (!empty($result['values'])) { | |
398 | return current(array_keys($result['values'])); | |
399 | } | |
400 | return NULL; | |
401 | } | |
402 | ||
4cbe18b8 EM |
403 | /** |
404 | * @param $field | |
405 | * | |
406 | * @return mixed | |
407 | */ | |
00be9182 | 408 | public function webtestGetConfig($field) { |
6a488035 TO |
409 | static $_config_backend; |
410 | if (is_null($_config_backend)) { | |
411 | $result = $this->webtest_civicrm_api("Domain", "getvalue", array( | |
412 | 'current_domain' => 1, | |
413 | 'option.limit' => 1, | |
21dfd5f5 | 414 | 'return' => 'config_backend', |
6a488035 TO |
415 | )); |
416 | $_config_backend = unserialize($result); | |
417 | } | |
418 | return $_config_backend[$field]; | |
419 | } | |
420 | ||
d3f2fd13 TO |
421 | /** |
422 | * @param string $field | |
423 | * @return mixed | |
424 | */ | |
425 | public function webtestGetSetting($field) { | |
426 | if (!isset($this->settingCache[$field])) { | |
427 | $result = $this->webtest_civicrm_api("Setting", "getsingle", array( | |
428 | 'return' => $field, | |
429 | )); | |
430 | $this->settingCache[$field] = $result[$field]; | |
431 | } | |
432 | return $this->settingCache[$field]; | |
433 | } | |
434 | ||
1fbd57f8 | 435 | /** |
eceb18cc | 436 | * Ensures the required CiviCRM components are enabled. |
1e1fdcf6 | 437 | * @param $components |
1fbd57f8 | 438 | */ |
00be9182 | 439 | public function enableComponents($components) { |
1fbd57f8 CW |
440 | $this->openCiviPage("admin/setting/component", "reset=1", "_qf_Component_next-bottom"); |
441 | $enabledComponents = $this->getSelectOptions("enableComponents-t"); | |
442 | $added = FALSE; | |
443 | foreach ((array) $components as $comp) { | |
444 | if (!in_array($comp, $enabledComponents)) { | |
0bd37c06 | 445 | $this->addSelection("enableComponents-f", "label=$comp"); |
1fbd57f8 CW |
446 | $this->click("//option[@value='$comp']"); |
447 | $this->click("add"); | |
448 | $added = TRUE; | |
449 | } | |
450 | } | |
451 | if ($added) { | |
59843a57 CW |
452 | $this->clickLink("_qf_Component_next-bottom"); |
453 | $this->checkCRMAlert("Saved"); | |
1fbd57f8 CW |
454 | } |
455 | } | |
456 | ||
6a488035 | 457 | /** |
eceb18cc | 458 | * Add a contact with the given first and last names and either a given email. |
6a488035 TO |
459 | * (when specified), a random email (when true) or no email (when unspecified or null). |
460 | * | |
e16033b4 TO |
461 | * @param string $fname |
462 | * Contact’s first name. | |
463 | * @param string $lname | |
464 | * Contact’s last name. | |
465 | * @param mixed $email | |
466 | * Contact’s email (when string) or random email (when true) or no email (when null). | |
72b3a70c | 467 | * @param string $contactSubtype |
2a6da8d7 | 468 | * |
72b3a70c CW |
469 | * @return string|null |
470 | * either a string with the (either generated or provided) email or null (if no email) | |
6a488035 | 471 | */ |
00be9182 | 472 | public function webtestAddContact($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) { |
5c88df60 | 473 | $args = 'reset=1&ct=Individual'; |
6a488035 | 474 | if ($contactSubtype) { |
5c88df60 | 475 | $args .= "&cst={$contactSubtype}"; |
6a488035 | 476 | } |
5c88df60 | 477 | $this->openCiviPage('contact/add', $args, '_qf_Contact_upload_view-bottom'); |
6a488035 TO |
478 | $this->type('first_name', $fname); |
479 | $this->type('last_name', $lname); | |
480 | if ($email === TRUE) { | |
481 | $email = substr(sha1(rand()), 0, 7) . '@example.org'; | |
482 | } | |
483 | if ($email) { | |
484 | $this->type('email_1_email', $email); | |
485 | } | |
5c88df60 | 486 | $this->clickLink('_qf_Contact_upload_view-bottom'); |
6a488035 TO |
487 | return $email; |
488 | } | |
489 | ||
4cbe18b8 EM |
490 | /** |
491 | * @param string $householdName | |
492 | * @param null $email | |
493 | * | |
494 | * @return null|string | |
495 | */ | |
00be9182 | 496 | public function webtestAddHousehold($householdName = "Smith's Home", $email = NULL) { |
b45c587e | 497 | $this->openCiviPage("contact/add", "reset=1&ct=Household"); |
6a488035 TO |
498 | $this->click('household_name'); |
499 | $this->type('household_name', $householdName); | |
500 | ||
501 | if ($email === TRUE) { | |
502 | $email = substr(sha1(rand()), 0, 7) . '@example.org'; | |
503 | } | |
504 | if ($email) { | |
505 | $this->type('email_1_email', $email); | |
506 | } | |
507 | ||
5c88df60 | 508 | $this->clickLink('_qf_Contact_upload_view'); |
6a488035 TO |
509 | return $email; |
510 | } | |
511 | ||
4cbe18b8 EM |
512 | /** |
513 | * @param string $organizationName | |
514 | * @param null $email | |
515 | * @param null $contactSubtype | |
516 | * | |
517 | * @return null|string | |
518 | */ | |
00be9182 | 519 | public function webtestAddOrganization($organizationName = "Organization XYZ", $email = NULL, $contactSubtype = NULL) { |
5c88df60 | 520 | $args = 'reset=1&ct=Organization'; |
2ddaadeb | 521 | if ($contactSubtype) { |
5c88df60 | 522 | $args .= "&cst={$contactSubtype}"; |
2ddaadeb | 523 | } |
5c88df60 | 524 | $this->openCiviPage('contact/add', $args, '_qf_Contact_upload_view-bottom'); |
6a488035 TO |
525 | $this->click('organization_name'); |
526 | $this->type('organization_name', $organizationName); | |
527 | ||
528 | if ($email === TRUE) { | |
529 | $email = substr(sha1(rand()), 0, 7) . '@example.org'; | |
530 | } | |
531 | if ($email) { | |
532 | $this->type('email_1_email', $email); | |
533 | } | |
5c88df60 | 534 | $this->clickLink('_qf_Contact_upload_view'); |
6a488035 TO |
535 | return $email; |
536 | } | |
537 | ||
538 | /** | |
1e1fdcf6 EM |
539 | * @param $sortName |
540 | * @param string $fieldName | |
6a488035 | 541 | */ |
00be9182 | 542 | public function webtestFillAutocomplete($sortName, $fieldName = 'contact_id') { |
6c6e6187 | 543 | $this->select2($fieldName, $sortName); |
5320adf4 | 544 | //$this->assertContains($sortName, $this->getValue($fieldName), "autocomplete expected $sortName but didn’t find it in " . $this->getValue($fieldName)); |
6a488035 TO |
545 | } |
546 | ||
547 | /** | |
1e1fdcf6 | 548 | * @param $sortName |
6a488035 | 549 | */ |
00be9182 | 550 | public function webtestOrganisationAutocomplete($sortName) { |
33cf86bd | 551 | $this->clickAt("//*[@id='contact_id']/../div/a"); |
5320adf4 WA |
552 | $this->waitForElementPresent("//*[@id='select2-drop']/div/input"); |
553 | $this->keyDown("//*[@id='select2-drop']/div/input", " "); | |
554 | $this->type("//*[@id='select2-drop']/div/input", $sortName); | |
555 | $this->typeKeys("//*[@id='select2-drop']/div/input", $sortName); | |
556 | $this->waitForElementPresent("//*[@class='select2-result-label']"); | |
557 | $this->clickAt("//*[@class='select2-results']/li[1]"); | |
6a488035 TO |
558 | //$this->assertContains($sortName, $this->getValue('contact_1'), "autocomplete expected $sortName but didn’t find it in " . $this->getValue('contact_1')); |
559 | } | |
560 | ||
4cbe18b8 | 561 | /** |
c490a46a CW |
562 | * 1. By default, when no strtotime arg is specified, sets date to "now + 1 month" |
563 | * 2. Does not set time. For setting both date and time use webtestFillDateTime() method. | |
564 | * 3. Examples of $strToTime arguments - | |
565 | * webtestFillDate('start_date',"now") | |
566 | * webtestFillDate('start_date',"10 September 2000") | |
567 | * webtestFillDate('start_date',"+1 day") | |
568 | * webtestFillDate('start_date',"+1 week") | |
569 | * webtestFillDate('start_date',"+1 week 2 days 4 hours 2 seconds") | |
570 | * webtestFillDate('start_date',"next Thursday") | |
571 | * webtestFillDate('start_date',"last Monday") | |
4cbe18b8 EM |
572 | * @param $dateElement |
573 | * @param null $strToTimeArgs | |
574 | */ | |
cd71816e | 575 | public function webtestFillDate($dateElement, $strToTimeArgs = NULL, $multiselect = FALSE) { |
6a488035 TO |
576 | $timeStamp = strtotime($strToTimeArgs ? $strToTimeArgs : '+1 month'); |
577 | ||
578 | $year = date('Y', $timeStamp); | |
579 | // -1 ensures month number is inline with calender widget's month | |
580 | $mon = date('n', $timeStamp) - 1; | |
581 | $day = date('j', $timeStamp); | |
582 | ||
cd71816e | 583 | if (!$multiselect) { |
584 | $this->click("xpath=//input[starts-with(@id, '{$dateElement}_display_')]"); | |
585 | } | |
6a488035 TO |
586 | $this->waitForElementPresent("css=div#ui-datepicker-div.ui-datepicker div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-month"); |
587 | $this->select("css=div#ui-datepicker-div.ui-datepicker div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-month", "value=$mon"); | |
588 | $this->select("css=div#ui-datepicker-div div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-year", "value=$year"); | |
589 | $this->click("link=$day"); | |
590 | } | |
591 | ||
4cbe18b8 | 592 | /** |
c490a46a | 593 | * 1. set both date and time. |
4cbe18b8 EM |
594 | * @param $dateElement |
595 | * @param null $strToTimeArgs | |
596 | */ | |
00be9182 | 597 | public function webtestFillDateTime($dateElement, $strToTimeArgs = NULL) { |
6a488035 TO |
598 | $this->webtestFillDate($dateElement, $strToTimeArgs); |
599 | ||
600 | $timeStamp = strtotime($strToTimeArgs ? $strToTimeArgs : '+1 month'); | |
601 | $hour = date('h', $timeStamp); | |
602 | $min = date('i', $timeStamp); | |
603 | $meri = date('A', $timeStamp); | |
604 | ||
605 | $this->type("{$dateElement}_time", "{$hour}:{$min}{$meri}"); | |
606 | } | |
607 | ||
608 | /** | |
609 | * Verify that given label/value pairs are in *sibling* td cells somewhere on the page. | |
610 | * | |
e16033b4 TO |
611 | * @param array $expected |
612 | * Array of key/value pairs (like Status/Registered) to be checked. | |
613 | * @param string $xpathPrefix | |
614 | * Pass in an xpath locator to "get to" the desired table or tables. Will be prefixed to xpath. | |
6a488035 | 615 | * table path. Include leading forward slashes (e.g. "//div[@id='activity-content']"). |
e16033b4 TO |
616 | * @param string $tableId |
617 | * Pass in the id attribute of a table to be verified if you want to only check a specific table. | |
6a488035 TO |
618 | * on the web page. |
619 | */ | |
00be9182 | 620 | public function webtestVerifyTabularData($expected, $xpathPrefix = NULL, $tableId = NULL) { |
6a488035 TO |
621 | $tableLocator = ""; |
622 | if ($tableId) { | |
623 | $tableLocator = "[@id='$tableId']"; | |
624 | } | |
625 | foreach ($expected as $label => $value) { | |
626 | if ($xpathPrefix) { | |
5ddf4885 | 627 | $this->waitForElementPresent("xpath=//table{$tableLocator}/tbody/tr/td{$xpathPrefix}[text()='{$label}']/../following-sibling::td"); |
ba4a1892 | 628 | $this->verifyText("xpath=//table{$tableLocator}/tbody/tr/td{$xpathPrefix}[text()='{$label}']/../following-sibling::td", preg_quote($value)); |
6a488035 TO |
629 | } |
630 | else { | |
5ddf4885 | 631 | $this->waitForElementPresent("xpath=//table{$tableLocator}/tbody/tr/td[text()='{$label}']/following-sibling::td"); |
ba4a1892 | 632 | $this->verifyText("xpath=//table{$tableLocator}/tbody/tr/td[text()='{$label}']/following-sibling::td", preg_quote($value)); |
6a488035 TO |
633 | } |
634 | } | |
635 | } | |
636 | ||
637 | /** | |
eceb18cc | 638 | * Types text into a ckEditor rich text field in a form. |
6a488035 | 639 | * |
e16033b4 TO |
640 | * @param string $fieldName |
641 | * Form field name (as assigned by PHP buildForm class). | |
642 | * @param string $text | |
643 | * Text to type into the field. | |
644 | * @param string $editor | |
645 | * Which text editor (valid values are 'CKEditor', 'TinyMCE'). | |
6a488035 | 646 | * |
1e1fdcf6 EM |
647 | * @param bool $compressed |
648 | * @throws \PHPUnit_Framework_AssertionFailedError | |
6a488035 | 649 | */ |
00be9182 | 650 | public function fillRichTextField($fieldName, $text = 'Typing this text into editor.', $editor = 'CKEditor', $compressed = FALSE) { |
6a488035 TO |
651 | // make sure cursor focuses on the field |
652 | $this->fireEvent($fieldName, 'focus'); | |
653 | if ($editor == 'CKEditor') { | |
02e08b2e | 654 | if ($compressed) { |
000a086f | 655 | $this->click("xpath=//textarea[@id='{$fieldName}']/../div[1]"); |
02e08b2e | 656 | } |
6a488035 TO |
657 | $this->waitForElementPresent("xpath=//div[@id='cke_{$fieldName}']//iframe"); |
658 | $this->runScript("CKEDITOR.instances['{$fieldName}'].setData('<p>{$text}</p>');"); | |
659 | } | |
660 | elseif ($editor == 'TinyMCE') { | |
f97d29d1 RN |
661 | $this->waitForElementPresent("xpath=//iframe[@id='{$fieldName}_ifr']"); |
662 | $this->runScript("tinyMCE.activeEditor.setContent('<p>{$text}</p>');"); | |
6a488035 TO |
663 | } |
664 | else { | |
665 | $this->fail("Unknown editor value: $editor, failing (in CiviSeleniumTestCase::fillRichTextField ..."); | |
666 | } | |
667 | $this->selectFrame('relative=top'); | |
668 | } | |
669 | ||
670 | /** | |
eceb18cc | 671 | * Types option label and name into a table of multiple choice options. |
6a488035 TO |
672 | * (for price set fields of type select, radio, or checkbox) |
673 | * TODO: extend for custom field multiple choice table input | |
674 | * | |
e16033b4 TO |
675 | * @param array $options |
676 | * Form field name (as assigned by PHP buildForm class). | |
677 | * @param array $validateStrings | |
678 | * Appends label and name strings to this array so they can be validated later. | |
6a488035 TO |
679 | * |
680 | * @return void | |
681 | */ | |
00be9182 | 682 | public function addMultipleChoiceOptions($options, &$validateStrings) { |
6a488035 TO |
683 | foreach ($options as $oIndex => $oValue) { |
684 | $validateStrings[] = $oValue['label']; | |
685 | $validateStrings[] = $oValue['amount']; | |
a7488080 | 686 | if (!empty($oValue['membership_type_id'])) { |
6a488035 TO |
687 | $this->select("membership_type_id_{$oIndex}", "value={$oValue['membership_type_id']}"); |
688 | } | |
a7488080 | 689 | if (!empty($oValue['financial_type_id'])) { |
6a488035 TO |
690 | $this->select("option_financial_type_id_{$oIndex}", "label={$oValue['financial_type_id']}"); |
691 | } | |
692 | $this->type("option_label_{$oIndex}", $oValue['label']); | |
693 | $this->type("option_amount_{$oIndex}", $oValue['amount']); | |
694 | $this->click('link=another choice'); | |
695 | } | |
696 | } | |
697 | ||
698 | /** | |
eceb18cc | 699 | * Use a contact EntityRef field to add a new contact. |
e16033b4 TO |
700 | * @param string $field |
701 | * Selector. | |
80f3b91d | 702 | * @param string $contactType |
a6c01b45 | 703 | * @return array |
16b10e64 | 704 | * Array of contact attributes (id, names, email) |
80f3b91d | 705 | */ |
00be9182 | 706 | public function createDialogContact($field = 'contact_id', $contactType = 'Individual') { |
80f3b91d CW |
707 | $selectId = 's2id_' . $this->getAttribute($field . '@id'); |
708 | $this->clickAt("xpath=//div[@id='$selectId']/a"); | |
709 | $this->clickAjaxLink("xpath=//li[@class='select2-no-results']//a[contains(text(), 'New $contactType')]", '_qf_Edit_next'); | |
710 | ||
711 | $name = substr(sha1(rand()), 0, rand(6, 8)); | |
712 | $params = array(); | |
713 | if ($contactType == 'Individual') { | |
714 | $params['first_name'] = "$name $contactType"; | |
715 | $params['last_name'] = substr(sha1(rand()), 0, rand(5, 9)); | |
716 | } | |
717 | else { | |
718 | $params[strtolower($contactType) . '_name'] = "$name $contactType"; | |
719 | } | |
5896d037 | 720 | foreach ($params as $param => $val) { |
80f3b91d CW |
721 | $this->type($param, $val); |
722 | } | |
723 | $this->type('email-Primary', $params['email'] = "{$name}@example.com"); | |
724 | $this->clickAjaxLink('_qf_Edit_next'); | |
725 | ||
6c6e6187 | 726 | $this->waitForText("xpath=//div[@id='$selectId']", "$name"); |
80f3b91d CW |
727 | |
728 | $params['sort_name'] = $contactType == 'Individual' ? $params['last_name'] . ', ' . $params['first_name'] : "$name $contactType"; | |
729 | $params['display_name'] = $contactType == 'Individual' ? $params['first_name'] . ' ' . $params['last_name'] : $params['sort_name']; | |
730 | $params['id'] = $this->getValue($field); | |
731 | return $params; | |
732 | } | |
733 | ||
734 | /** | |
735 | * @deprecated in favor of createDialogContact | |
1e1fdcf6 EM |
736 | * @param string $fname |
737 | * @param string $lname | |
738 | * @param string $email | |
739 | * @param int $type | |
740 | * @param string $selectId | |
741 | * @param int $row | |
742 | * @param string $prefix | |
6a488035 | 743 | */ |
3bdca100 | 744 | public function webtestNewDialogContact( |
5896d037 TO |
745 | $fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz', |
746 | $type = 4, $selectId = 's2id_contact_id', $row = 1, $prefix = '') { | |
6a488035 TO |
747 | // 4 - Individual profile |
748 | // 5 - Organization profile | |
749 | // 6 - Household profile | |
0e32ba2d | 750 | $profile = array('4' => 'New Individual', '5' => 'New Organization', '6' => 'New Household'); |
201e298c | 751 | $this->clickAt("xpath=//div[@id='$selectId']/a"); |
a5d61f09 | 752 | $this->clickPopupLink("xpath=//li[@class='select2-no-results']//a[contains(text(),' $profile[$type]')]", '_qf_Edit_next'); |
6a488035 TO |
753 | |
754 | switch ($type) { | |
755 | case 4: | |
756 | $this->type('first_name', $fname); | |
757 | $this->type('last_name', $lname); | |
758 | break; | |
759 | ||
760 | case 5: | |
761 | $this->type('organization_name', $fname); | |
762 | break; | |
763 | ||
764 | case 6: | |
765 | $this->type('household_name', $fname); | |
766 | break; | |
767 | } | |
768 | ||
769 | $this->type('email-Primary', $email); | |
9c5c0056 | 770 | $this->clickAjaxLink('_qf_Edit_next'); |
6a488035 TO |
771 | |
772 | // Is new contact created? | |
773 | if ($lname) { | |
6c6e6187 | 774 | $this->waitForText("xpath=//div[@id='$selectId']", "$lname, $fname"); |
6a488035 TO |
775 | } |
776 | else { | |
6c6e6187 | 777 | $this->waitForText("xpath=//div[@id='$selectId']", "$fname"); |
6a488035 TO |
778 | } |
779 | } | |
780 | ||
781 | /** | |
eceb18cc | 782 | * Generic function to check that strings are present in the page. |
6a488035 TO |
783 | * |
784 | * @strings array array of strings or a single string | |
785 | * | |
2a6da8d7 | 786 | * @param $strings |
2b37475d | 787 | * @return void |
6a488035 | 788 | */ |
00be9182 | 789 | public function assertStringsPresent($strings) { |
6a488035 TO |
790 | foreach ((array) $strings as $string) { |
791 | $this->assertTrue($this->isTextPresent($string), "Could not find $string on page"); | |
792 | } | |
793 | } | |
794 | ||
795 | /** | |
796 | * Generic function to parse a URL string into it's elements.extract a variable value from a string (url) | |
797 | * | |
798 | * @url string url to parse or retrieve current url if null | |
799 | * | |
2a6da8d7 | 800 | * @param null $url |
a6c01b45 CW |
801 | * @return array |
802 | * returns an associative array containing any of the various components | |
6a488035 TO |
803 | * of the URL that are present. Querystring elements are returned in sub-array (elements.queryString) |
804 | * http://php.net/manual/en/function.parse-url.php | |
6a488035 | 805 | */ |
00be9182 | 806 | public function parseURL($url = NULL) { |
6a488035 TO |
807 | if (!$url) { |
808 | $url = $this->getLocation(); | |
809 | } | |
810 | ||
811 | $elements = parse_url($url); | |
812 | if (!empty($elements['query'])) { | |
813 | $elements['queryString'] = array(); | |
814 | parse_str($elements['query'], $elements['queryString']); | |
815 | } | |
816 | return $elements; | |
817 | } | |
818 | ||
efb29358 | 819 | /** |
eceb18cc | 820 | * Returns a single argument from the url query. |
1e1fdcf6 EM |
821 | * @param $arg |
822 | * @param null $url | |
823 | * @return null | |
efb29358 | 824 | */ |
6c6e6187 TO |
825 | public function urlArg($arg, $url = NULL) { |
826 | $elements = $this->parseURL($url); | |
827 | return isset($elements['queryString'][$arg]) ? $elements['queryString'][$arg] : NULL; | |
828 | } | |
efb29358 | 829 | |
6a488035 TO |
830 | /** |
831 | * Define a payment processor for use by a webtest. Default is to create Dummy processor | |
832 | * which is useful for testing online public forms (online contribution pages and event registration) | |
833 | * | |
e16033b4 TO |
834 | * @param string $processorName |
835 | * Name assigned to new processor. | |
836 | * @param string $processorType | |
837 | * Name for processor type (e.g. PayPal, Dummy, etc.). | |
838 | * @param array $processorSettings | |
839 | * Array of fieldname => value for required settings for the processor. | |
6a488035 | 840 | * |
2a6da8d7 EM |
841 | * @param string $financialAccount |
842 | * @throws PHPUnit_Framework_AssertionFailedError | |
57d32317 | 843 | * @return int |
6a488035 | 844 | */ |
00be9182 | 845 | public function webtestAddPaymentProcessor($processorName = 'Test Processor', $processorType = 'Dummy', $processorSettings = NULL, $financialAccount = 'Deposit Bank Account') { |
6a488035 TO |
846 | if (!$processorName) { |
847 | $this->fail("webTestAddPaymentProcessor requires $processorName."); | |
848 | } | |
e8eccbf5 CW |
849 | // Ensure we are logged in as admin before we proceed |
850 | $this->webtestLogin('admin'); | |
851 | ||
c3ad8633 CW |
852 | if ($processorName === 'Test Processor') { |
853 | // Use the default test processor, no need to create a new one | |
0512e9c6 | 854 | $this->openCiviPage('admin/paymentProcessor', 'action=update&id=1&reset=1', '_qf_PaymentProcessor_cancel-bottom'); |
c3ad8633 | 855 | $this->check('is_default'); |
39c74f87 | 856 | $this->select('financial_account_id', "label={$financialAccount}"); |
c3ad8633 CW |
857 | $this->clickLink('_qf_PaymentProcessor_next-bottom'); |
858 | return 1; | |
6a488035 | 859 | } |
e8eccbf5 CW |
860 | |
861 | if ($processorType == 'Dummy') { | |
862 | $processorSettings = array( | |
863 | 'user_name' => 'dummy', | |
864 | 'url_site' => 'http://dummy.com', | |
865 | 'test_user_name' => 'dummytest', | |
866 | 'test_url_site' => 'http://dummytest.com', | |
867 | ); | |
868 | } | |
6a488035 TO |
869 | elseif ($processorType == 'AuthNet') { |
870 | // FIXME: we 'll need to make a new separate account for testing | |
871 | $processorSettings = array( | |
599e7e41 | 872 | //dummy live username/password are passed to bypass processor validation on live credential |
873 | 'user_name' => '3HcY62mY', | |
874 | 'password' => '69943NrwaQA92b8J', | |
6a488035 | 875 | 'test_user_name' => '5ULu56ex', |
e390a377 | 876 | 'password' => '7ARxW575w736eF5p', |
6a488035 TO |
877 | 'test_password' => '7ARxW575w736eF5p', |
878 | ); | |
879 | } | |
880 | elseif ($processorType == 'Google_Checkout') { | |
881 | // FIXME: we 'll need to make a new separate account for testing | |
882 | $processorSettings = array( | |
883 | 'test_user_name' => '559999327053114', | |
884 | 'test_password' => 'R2zv2g60-A7GXKJYl0nR0g', | |
885 | ); | |
886 | } | |
887 | elseif ($processorType == 'PayPal') { | |
888 | $processorSettings = array( | |
889 | 'test_user_name' => '559999327053114', | |
3109a145 | 890 | 'user_name' => '559999327053114', |
6a488035 TO |
891 | 'test_password' => 'R2zv2g60-A7GXKJYl0nR0g', |
892 | 'test_signature' => 'R2zv2g60-A7GXKJYl0nR0g', | |
3109a145 | 893 | 'password' => 'R2zv2g60-A7GXKJYl0nR0g', |
894 | 'signature' => 'R2zv2g60-A7GXKJYl0nR0g', | |
6a488035 TO |
895 | ); |
896 | } | |
897 | elseif ($processorType == 'PayPal_Standard') { | |
898 | $processorSettings = array( | |
599e7e41 | 899 | 'user_name' => 'V18ki@9r5Bf.org', |
6a488035 TO |
900 | 'test_user_name' => 'V18ki@9r5Bf.org', |
901 | ); | |
902 | } | |
903 | elseif (empty($processorSettings)) { | |
904 | $this->fail("webTestAddPaymentProcessor requires $processorSettings array if processorType is not Dummy."); | |
905 | } | |
906 | $pid = CRM_Core_DAO::getFieldValue("CRM_Financial_DAO_PaymentProcessorType", $processorType, "id", "name"); | |
907 | if (empty($pid)) { | |
908 | $this->fail("$processorType processortype not found."); | |
909 | } | |
57d32317 | 910 | $this->openCiviPage('admin/paymentProcessor', 'action=add&reset=1&pp=' . $pid, 'name'); |
6a488035 TO |
911 | $this->type('name', $processorName); |
912 | $this->select('financial_account_id', "label={$financialAccount}"); | |
6c6e6187 | 913 | foreach ($processorSettings as $f => $v) { |
6a488035 TO |
914 | $this->type($f, $v); |
915 | } | |
14d071ba | 916 | |
57d32317 CW |
917 | // Save |
918 | $this->clickLink('_qf_PaymentProcessor_next-bottom'); | |
919 | ||
f48a56fc | 920 | $this->waitForTextPresent($processorName); |
6a488035 | 921 | |
57d32317 CW |
922 | // Get payment processor id |
923 | $paymentProcessorLink = $this->getAttribute("xpath=//table[@class='selector row-highlight']//tbody//tr/td[text()='{$processorName}']/../td[7]/span/a[1]@href"); | |
924 | return $this->urlArg('id', $paymentProcessorLink); | |
6a488035 | 925 | } |
5c88df60 | 926 | |
00be9182 | 927 | public function webtestAddCreditCardDetails() { |
6a488035 TO |
928 | $this->waitForElementPresent('credit_card_type'); |
929 | $this->select('credit_card_type', 'label=Visa'); | |
930 | $this->type('credit_card_number', '4807731747657838'); | |
931 | $this->type('cvv2', '123'); | |
932 | $this->select('credit_card_exp_date[M]', 'label=Feb'); | |
933 | $this->select('credit_card_exp_date[Y]', 'label=2019'); | |
934 | } | |
935 | ||
4cbe18b8 EM |
936 | /** |
937 | * @param null $firstName | |
938 | * @param null $middleName | |
939 | * @param null $lastName | |
940 | * | |
941 | * @return array | |
942 | */ | |
00be9182 | 943 | public function webtestAddBillingDetails($firstName = NULL, $middleName = NULL, $lastName = NULL) { |
6a488035 TO |
944 | if (!$firstName) { |
945 | $firstName = 'John'; | |
946 | } | |
947 | ||
948 | if (!$middleName) { | |
949 | $middleName = 'Apple'; | |
950 | } | |
951 | ||
952 | if (!$lastName) { | |
953 | $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); | |
954 | } | |
955 | ||
956 | $this->type('billing_first_name', $firstName); | |
957 | $this->type('billing_middle_name', $middleName); | |
958 | $this->type('billing_last_name', $lastName); | |
959 | ||
960 | $this->type('billing_street_address-5', '234 Lincoln Ave'); | |
961 | $this->type('billing_city-5', 'San Bernadino'); | |
86797006 | 962 | $this->select2('billing_country_id-5', 'UNITED STATES'); |
b3d40287 | 963 | $this->select2('billing_state_province_id-5', 'California'); |
6a488035 TO |
964 | $this->type('billing_postal_code-5', '93245'); |
965 | ||
966 | return array($firstName, $middleName, $lastName); | |
967 | } | |
968 | ||
4cbe18b8 EM |
969 | /** |
970 | * @param $fieldLocator | |
971 | * @param null $filePath | |
972 | * | |
973 | * @return null|string | |
974 | */ | |
00be9182 | 975 | public function webtestAttachFile($fieldLocator, $filePath = NULL) { |
6a488035 TO |
976 | if (!$filePath) { |
977 | $filePath = '/tmp/testfile_' . substr(sha1(rand()), 0, 7) . '.txt'; | |
978 | $fp = @fopen($filePath, 'w'); | |
3bdca100 | 979 | fwrite($fp, 'Test file created by selenium test.'); |
6a488035 TO |
980 | @fclose($fp); |
981 | } | |
982 | ||
983 | $this->assertTrue(file_exists($filePath), 'Not able to locate file: ' . $filePath); | |
984 | ||
985 | $this->attachFile($fieldLocator, "file://{$filePath}"); | |
986 | ||
987 | return $filePath; | |
988 | } | |
989 | ||
4cbe18b8 EM |
990 | /** |
991 | * @param $headers | |
992 | * @param $rows | |
993 | * @param null $filePath | |
994 | * | |
995 | * @return null|string | |
996 | */ | |
00be9182 | 997 | public function webtestCreateCSV($headers, $rows, $filePath = NULL) { |
6a488035 TO |
998 | if (!$filePath) { |
999 | $filePath = '/tmp/testcsv_' . substr(sha1(rand()), 0, 7) . '.csv'; | |
1000 | } | |
1001 | ||
1002 | $data = '"' . implode('", "', $headers) . '"' . "\r\n"; | |
1003 | ||
1004 | foreach ($rows as $row) { | |
1005 | $temp = array(); | |
1006 | foreach ($headers as $field => $header) { | |
1007 | $temp[$field] = isset($row[$field]) ? '"' . $row[$field] . '"' : '""'; | |
1008 | } | |
1009 | $data .= implode(', ', $temp) . "\r\n"; | |
1010 | } | |
1011 | ||
1012 | $fp = @fopen($filePath, 'w'); | |
1013 | @fwrite($fp, $data); | |
1014 | @fclose($fp); | |
1015 | ||
1016 | $this->assertTrue(file_exists($filePath), 'Not able to locate file: ' . $filePath); | |
1017 | ||
1018 | return $filePath; | |
1019 | } | |
1020 | ||
1021 | /** | |
1022 | * Create new relationship type w/ user specified params or default. | |
1023 | * | |
5a4f6742 | 1024 | * @param array $params |
72b3a70c | 1025 | * array of required params. |
6a488035 | 1026 | * |
72b3a70c CW |
1027 | * @return array |
1028 | * array of saved params values. | |
6a488035 | 1029 | */ |
00be9182 | 1030 | public function webtestAddRelationshipType($params = array()) { |
b45c587e | 1031 | $this->openCiviPage("admin/reltype", "reset=1&action=add"); |
6a488035 TO |
1032 | |
1033 | //build the params if not passed. | |
1034 | if (!is_array($params) || empty($params)) { | |
1035 | $params = array( | |
1036 | 'label_a_b' => 'Test Relationship Type A - B -' . rand(), | |
1037 | 'label_b_a' => 'Test Relationship Type B - A -' . rand(), | |
1038 | 'contact_types_a' => 'Individual', | |
1039 | 'contact_types_b' => 'Individual', | |
1040 | 'description' => 'Test Relationship Type Description', | |
1041 | ); | |
1042 | } | |
1043 | //make sure we have minimum required params. | |
1044 | if (!isset($params['label_a_b']) || empty($params['label_a_b'])) { | |
1045 | $params['label_a_b'] = 'Test Relationship Type A - B -' . rand(); | |
1046 | } | |
1047 | ||
1048 | //start the form fill. | |
1049 | $this->type('label_a_b', $params['label_a_b']); | |
1050 | $this->type('label_b_a', $params['label_b_a']); | |
1051 | $this->select('contact_types_a', "value={$params['contact_type_a']}"); | |
1052 | $this->select('contact_types_b', "value={$params['contact_type_b']}"); | |
1053 | $this->type('description', $params['description']); | |
1054 | ||
1055 | //save the data. | |
1056 | $this->click('_qf_RelationshipType_next-bottom'); | |
1057 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1058 | ||
1059 | //does data saved. | |
1060 | $this->assertTrue($this->isTextPresent('The Relationship Type has been saved.'), | |
1061 | "Status message didn't show up after saving!" | |
1062 | ); | |
1063 | ||
b45c587e | 1064 | $this->openCiviPage("admin/reltype", "reset=1"); |
6a488035 TO |
1065 | |
1066 | //validate data on selector. | |
1067 | $data = $params; | |
1068 | if (isset($data['description'])) { | |
1069 | unset($data['description']); | |
1070 | } | |
1071 | $this->assertStringsPresent($data); | |
1072 | ||
1073 | return $params; | |
1074 | } | |
1075 | ||
1076 | /** | |
1077 | * Create new online contribution page w/ user specified params or defaults. | |
b45c587e | 1078 | * FIXME: this function take an absurd number of params - very unwieldy :( |
6a488035 | 1079 | * |
2a6da8d7 EM |
1080 | * @param null $hash |
1081 | * @param null $rand | |
1082 | * @param null $pageTitle | |
1083 | * @param array $processor | |
1084 | * @param bool $amountSection | |
1085 | * @param bool $payLater | |
1086 | * @param bool $onBehalf | |
1087 | * @param bool $pledges | |
1088 | * @param bool $recurring | |
1089 | * @param bool $membershipTypes | |
100fef9d | 1090 | * @param int $memPriceSetId |
2a6da8d7 EM |
1091 | * @param bool $friend |
1092 | * @param int $profilePreId | |
1093 | * @param int $profilePostId | |
1094 | * @param bool $premiums | |
1095 | * @param bool $widget | |
1096 | * @param bool $pcp | |
1097 | * @param bool $isAddPaymentProcessor | |
1098 | * @param bool $isPcpApprovalNeeded | |
1099 | * @param bool $isSeparatePayment | |
1100 | * @param bool $honoreeSection | |
91d49cae | 1101 | * @param bool $allowOtherAmount |
2a6da8d7 EM |
1102 | * @param bool $isConfirmEnabled |
1103 | * @param string $financialType | |
1104 | * @param bool $fixedAmount | |
1105 | * @param bool $membershipsRequired | |
6a488035 | 1106 | * |
a6c01b45 CW |
1107 | * @return null |
1108 | * of newly created online contribution page. | |
6a488035 | 1109 | */ |
3bdca100 | 1110 | public function webtestAddContributionPage( |
5896d037 TO |
1111 | $hash = NULL, |
1112 | $rand = NULL, | |
1113 | $pageTitle = NULL, | |
1114 | $processor = array('Test Processor' => 'Dummy'), | |
1115 | $amountSection = TRUE, | |
1116 | $payLater = TRUE, | |
1117 | $onBehalf = TRUE, | |
1118 | $pledges = TRUE, | |
1119 | $recurring = FALSE, | |
1120 | $membershipTypes = TRUE, | |
1121 | $memPriceSetId = NULL, | |
1122 | $friend = TRUE, | |
1123 | $profilePreId = 1, | |
1124 | $profilePostId = 7, | |
1125 | $premiums = TRUE, | |
1126 | $widget = TRUE, | |
1127 | $pcp = TRUE, | |
1128 | $isAddPaymentProcessor = TRUE, | |
1129 | $isPcpApprovalNeeded = FALSE, | |
1130 | $isSeparatePayment = FALSE, | |
1131 | $honoreeSection = TRUE, | |
1132 | $allowOtherAmount = TRUE, | |
1133 | $isConfirmEnabled = TRUE, | |
1134 | $financialType = 'Donation', | |
1135 | $fixedAmount = TRUE, | |
1136 | $membershipsRequired = TRUE | |
6a488035 TO |
1137 | ) { |
1138 | if (!$hash) { | |
1139 | $hash = substr(sha1(rand()), 0, 7); | |
1140 | } | |
1141 | if (!$pageTitle) { | |
1142 | $pageTitle = 'Donate Online ' . $hash; | |
1143 | } | |
1144 | ||
1145 | if (!$rand) { | |
1146 | $rand = 2 * rand(2, 50); | |
1147 | } | |
1148 | ||
1149 | // Create a new payment processor if requested | |
1150 | if ($isAddPaymentProcessor) { | |
1151 | while (list($processorName, $processorType) = each($processor)) { | |
1152 | $this->webtestAddPaymentProcessor($processorName, $processorType); | |
1153 | } | |
1154 | } | |
1155 | ||
1156 | // go to the New Contribution Page page | |
b45c587e | 1157 | $this->openCiviPage('admin/contribute', 'action=add&reset=1'); |
6a488035 TO |
1158 | |
1159 | // fill in step 1 (Title and Settings) | |
1160 | $this->type('title', $pageTitle); | |
1161 | ||
1162 | //to select financial type | |
1163 | $this->select('financial_type_id', "label={$financialType}"); | |
1164 | ||
1165 | if ($onBehalf) { | |
1166 | $this->click('is_organization'); | |
d340a0e8 | 1167 | $this->select("xpath=//*[@class='crm-contribution-onbehalf_profile_id']//span[@class='crm-profile-selector-select']//select", 'label=On Behalf Of Organization'); |
6a488035 TO |
1168 | $this->type('for_organization', "On behalf $hash"); |
1169 | ||
1170 | if ($onBehalf == 'required') { | |
1171 | $this->click('CIVICRM_QFID_2_4'); | |
1172 | } | |
1173 | elseif ($onBehalf == 'optional') { | |
1174 | $this->click('CIVICRM_QFID_1_2'); | |
1175 | } | |
1176 | } | |
1177 | ||
1178 | $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor'); | |
1179 | $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor'); | |
1180 | ||
1181 | $this->type('goal_amount', 10 * $rand); | |
1182 | ||
1183 | // FIXME: handle Start/End Date/Time | |
1184 | if ($honoreeSection) { | |
1185 | $this->click('honor_block_is_active'); | |
1186 | $this->type('honor_block_title', "Honoree Section Title $hash"); | |
1187 | $this->type('honor_block_text', "Honoree Introductory Message $hash"); | |
5ddf4885 | 1188 | $this->click("//*[@id='s2id_soft_credit_types']/ul"); |
1189 | $this->waitForElementPresent("//*[@id='select2-drop']/ul"); | |
1190 | $this->waitForElementPresent("//*[@class='select2-result-label']"); | |
1191 | $this->clickAt("//*[@class='select2-results']/li[1]"); | |
6a488035 TO |
1192 | } |
1193 | ||
1194 | // is confirm enabled? it starts out enabled, so uncheck it if false | |
1195 | if (!$isConfirmEnabled) { | |
1196 | $this->click("id=is_confirm_enabled"); | |
1197 | } | |
1198 | ||
b45c587e CW |
1199 | // Submit form |
1200 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
1201 | ||
1202 | // Get contribution page id | |
1203 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
1204 | |
1205 | // fill in step 2 (Processor, Pay Later, Amounts) | |
1206 | if (!empty($processor)) { | |
1207 | reset($processor); | |
1208 | while (list($processorName) = each($processor)) { | |
1209 | // select newly created processor | |
1210 | $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]"; | |
1211 | $this->assertTrue($this->isTextPresent($processorName)); | |
1212 | $this->check($xpath); | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | if ($amountSection && !$memPriceSetId) { | |
1217 | if ($payLater) { | |
1218 | $this->click('is_pay_later'); | |
1219 | $this->type('pay_later_text', "Pay later label $hash"); | |
3c001b0e | 1220 | $this->fillRichTextField('pay_later_receipt', "Pay later instructions $hash"); |
6a488035 TO |
1221 | } |
1222 | ||
1223 | if ($pledges) { | |
1224 | $this->click('is_pledge_active'); | |
1225 | $this->click('pledge_frequency_unit[week]'); | |
1226 | $this->click('is_pledge_interval'); | |
1227 | $this->type('initial_reminder_day', 3); | |
1228 | $this->type('max_reminders', 2); | |
1229 | $this->type('additional_reminder_day', 1); | |
1230 | } | |
1231 | elseif ($recurring) { | |
1232 | $this->click('is_recur'); | |
1233 | $this->click("is_recur_interval"); | |
1234 | $this->click("is_recur_installments"); | |
1235 | } | |
91d49cae | 1236 | if ($allowOtherAmount) { |
6a488035 TO |
1237 | |
1238 | $this->click('is_allow_other_amount'); | |
1239 | ||
1240 | // there shouldn't be minimums and maximums on test contribution forms unless you specify it | |
1241 | //$this->type('min_amount', $rand / 2); | |
1242 | //$this->type('max_amount', $rand * 10); | |
1243 | } | |
91d49cae | 1244 | if ($fixedAmount || !$allowOtherAmount) { |
1019390e PN |
1245 | $this->type('label_1', "Label $hash"); |
1246 | $this->type('value_1', "$rand"); | |
1247 | } | |
77f1e6b1 | 1248 | $this->click('CIVICRM_QFID_1_4'); |
6a488035 TO |
1249 | } |
1250 | else { | |
1251 | $this->click('amount_block_is_active'); | |
1252 | } | |
1253 | ||
1254 | $this->click('_qf_Amount_next'); | |
1255 | $this->waitForElementPresent('_qf_Amount_next-bottom'); | |
1256 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1257 | $text = "'Amount' information has been saved."; | |
1258 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1259 | ||
1260 | if ($memPriceSetId || (($membershipTypes === TRUE) || (is_array($membershipTypes) && !empty($membershipTypes)))) { | |
1261 | // go to step 3 (memberships) | |
1262 | $this->click('link=Memberships'); | |
1263 | $this->waitForElementPresent('_qf_MembershipBlock_next-bottom'); | |
1264 | ||
1265 | // fill in step 3 (Memberships) | |
1266 | $this->click('member_is_active'); | |
1267 | $this->waitForElementPresent('displayFee'); | |
1268 | $this->type('new_title', "Title - New Membership $hash"); | |
1269 | $this->type('renewal_title', "Title - Renewals $hash"); | |
1270 | ||
1271 | if ($memPriceSetId) { | |
1272 | $this->click('member_price_set_id'); | |
1273 | $this->select('member_price_set_id', "value={$memPriceSetId}"); | |
1274 | } | |
1275 | else { | |
1276 | if ($membershipTypes === TRUE) { | |
0b49a3ec | 1277 | $membershipTypes = array(array('id' => 2, 'name' => 'Student', 'default' => 1)); |
6a488035 TO |
1278 | } |
1279 | ||
1280 | // FIXME: handle Introductory Message - New Memberships/Renewals | |
1281 | foreach ($membershipTypes as $mType) { | |
1282 | $this->click("membership_type_{$mType['id']}"); | |
1283 | if (array_key_exists('default', $mType)) { | |
0b49a3ec | 1284 | $this->click("xpath=//label[text() = '$mType[name]']/parent::td/parent::tr/td[2]/input"); |
6a488035 TO |
1285 | } |
1286 | if (array_key_exists('auto_renew', $mType)) { | |
1287 | $this->select("auto_renew_{$mType['id']}", "label=Give option"); | |
1288 | } | |
1289 | } | |
1019390e PN |
1290 | if ($membershipsRequired) { |
1291 | $this->click('is_required'); | |
1292 | } | |
6a488035 TO |
1293 | if ($isSeparatePayment) { |
1294 | $this->click('is_separate_payment'); | |
1295 | } | |
1296 | } | |
225a8648 | 1297 | $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom'); |
6a488035 | 1298 | $text = "'MembershipBlock' information has been saved."; |
0b49a3ec | 1299 | $this->isTextPresent($text); |
6a488035 TO |
1300 | } |
1301 | ||
1302 | // go to step 4 (thank-you and receipting) | |
1303 | $this->click('link=Receipt'); | |
1304 | $this->waitForElementPresent('_qf_ThankYou_next-bottom'); | |
1305 | ||
1306 | // fill in step 4 | |
1307 | $this->type('thankyou_title', "Thank-you Page Title $hash"); | |
1308 | // FIXME: handle Thank-you Message/Page Footer | |
1309 | $this->type('receipt_from_name', "Receipt From Name $hash"); | |
1310 | $this->type('receipt_from_email', "$hash@example.org"); | |
1311 | $this->type('receipt_text', "Receipt Message $hash"); | |
1312 | $this->type('cc_receipt', "$hash@example.net"); | |
1313 | $this->type('bcc_receipt', "$hash@example.com"); | |
1314 | ||
1315 | $this->click('_qf_ThankYou_next'); | |
1316 | $this->waitForElementPresent('_qf_ThankYou_next-bottom'); | |
1317 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1318 | $text = "'ThankYou' information has been saved."; | |
1319 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1320 | ||
1321 | if ($friend) { | |
1322 | // fill in step 5 (Tell a Friend) | |
1323 | $this->click('link=Tell a Friend'); | |
1324 | $this->waitForElementPresent('_qf_Contribute_next-bottom'); | |
1325 | $this->click('tf_is_active'); | |
1326 | $this->type('tf_title', "TaF Title $hash"); | |
1327 | $this->type('intro', "TaF Introduction $hash"); | |
1328 | $this->type('suggested_message', "TaF Suggested Message $hash"); | |
1329 | $this->type('general_link', "TaF Info Page Link $hash"); | |
1330 | $this->type('tf_thankyou_title', "TaF Thank-you Title $hash"); | |
1331 | $this->type('tf_thankyou_text', "TaF Thank-you Message $hash"); | |
1332 | ||
1333 | //$this->click('_qf_Contribute_next'); | |
1334 | $this->click('_qf_Contribute_next-bottom'); | |
1335 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1336 | $text = "'Friend' information has been saved."; | |
1337 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1338 | } | |
1339 | ||
1340 | if ($profilePreId || $profilePostId) { | |
1341 | // fill in step 6 (Include Profiles) | |
1342 | $this->click('css=li#tab_custom a'); | |
1343 | $this->waitForElementPresent('_qf_Custom_next-bottom'); | |
1344 | ||
1345 | if ($profilePreId) { | |
1421174e | 1346 | $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', "value={$profilePreId}"); |
6a488035 TO |
1347 | } |
1348 | ||
1349 | if ($profilePostId) { | |
1421174e | 1350 | $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_post_id span.crm-profile-selector-select select', "value={$profilePostId}"); |
6a488035 TO |
1351 | } |
1352 | ||
1353 | $this->click('_qf_Custom_next-bottom'); | |
1354 | //$this->waitForElementPresent('_qf_Custom_next-bottom'); | |
1355 | ||
1356 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1357 | $text = "'Custom' information has been saved."; | |
1358 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1359 | } | |
1360 | ||
1361 | if ($premiums) { | |
1362 | // fill in step 7 (Premiums) | |
1363 | $this->click('link=Premiums'); | |
1364 | $this->waitForElementPresent('_qf_Premium_next-bottom'); | |
1365 | $this->click('premiums_active'); | |
1366 | $this->type('premiums_intro_title', "Prem Title $hash"); | |
1367 | $this->type('premiums_intro_text', "Prem Introductory Message $hash"); | |
1368 | $this->type('premiums_contact_email', "$hash@example.info"); | |
1369 | $this->type('premiums_contact_phone', rand(100000000, 999999999)); | |
1370 | $this->click('premiums_display_min_contribution'); | |
1371 | $this->type('premiums_nothankyou_label', 'No thank-you'); | |
1372 | $this->click('_qf_Premium_next'); | |
1373 | $this->waitForElementPresent('_qf_Premium_next-bottom'); | |
1374 | ||
1375 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1376 | $text = "'Premium' information has been saved."; | |
1377 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
feb02c31 WA |
1378 | $this->openCiviPage("admin/contribute", "reset=1"); |
1379 | $this->waitForAjaxContent(); | |
a7011f01 | 1380 | $this->click("xpath=//table['dataTables_wrapper no-footer']/tbody//tr/td[1]/strong[text()='$pageTitle']/../../td[4]/div[1]/span/ul/li[8]/a[text()='Premiums']"); |
feb02c31 WA |
1381 | $this->waitForElementPresent('_qf_Premium_cancel-bottom'); |
1382 | $this->click("xpath=//div[@class='messages status no-popup']/a[text()='add one']"); | |
1383 | $this->waitForElementPresent('_qf_AddProduct_cancel-bottom'); | |
1384 | $this->select('product_id', "value=1"); | |
1385 | $this->click('_qf_AddProduct_next-bottom'); | |
1386 | $this->waitForElementPresent('_qf_Premium_cancel-bottom'); | |
1387 | $this->click('_qf_Premium_next-bottom'); | |
df90c6dd | 1388 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
6a488035 TO |
1389 | } |
1390 | ||
6a488035 TO |
1391 | if ($widget) { |
1392 | // fill in step 8 (Widget Settings) | |
1393 | $this->click('link=Widgets'); | |
1394 | $this->waitForElementPresent('_qf_Widget_next-bottom'); | |
6a488035 TO |
1395 | $this->click('is_active'); |
1396 | $this->type('url_logo', "URL to Logo Image $hash"); | |
1397 | $this->type('button_title', "Button Title $hash"); | |
1398 | // Type About text in ckEditor (fieldname, text to type, editor) | |
1399 | $this->fillRichTextField('about', 'This is for ' . $pageTitle, 'CKEditor'); | |
1400 | ||
1401 | $this->click('_qf_Widget_next'); | |
1402 | $this->waitForElementPresent('_qf_Widget_next-bottom'); | |
1403 | ||
1404 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1405 | $text = "'Widget' information has been saved."; | |
1406 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1407 | } | |
1408 | ||
1409 | if ($pcp) { | |
1410 | // fill in step 9 (Enable Personal Campaign Pages) | |
1411 | $this->click('link=Personal Campaigns'); | |
1412 | $this->waitForElementPresent('_qf_Contribute_next-bottom'); | |
1413 | $this->click('pcp_active'); | |
1414 | if (!$isPcpApprovalNeeded) { | |
1415 | $this->click('is_approval_needed'); | |
1416 | } | |
1417 | $this->type('notify_email', "$hash@example.name"); | |
1418 | $this->select('supporter_profile_id', 'value=2'); | |
1419 | $this->type('tellfriend_limit', 7); | |
1420 | $this->type('link_text', "'Create Personal Campaign Page' link text $hash"); | |
1421 | ||
1422 | $this->click('_qf_Contribute_next-bottom'); | |
1423 | //$this->waitForElementPresent('_qf_PCP_next-bottom'); | |
1424 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1425 | $text = "'Pcp' information has been saved."; | |
1426 | $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text); | |
1427 | } | |
1428 | ||
b45c587e | 1429 | return $pageId; |
6a488035 TO |
1430 | } |
1431 | ||
1432 | /** | |
100fef9d | 1433 | * Update default strict rule. |
6a488035 | 1434 | * |
2a6da8d7 | 1435 | * @param string $contactType |
e16033b4 TO |
1436 | * @param array $fields |
1437 | * Fields to be set for strict rule. | |
1438 | * @param int $threshold | |
1439 | * Rule's threshold value. | |
6a488035 | 1440 | */ |
00be9182 | 1441 | public function webtestStrictDedupeRuleDefault($contactType = 'Individual', $fields = array(), $threshold = 10) { |
6a488035 TO |
1442 | // set default strict rule. |
1443 | $strictRuleId = 4; | |
1444 | if ($contactType == 'Organization') { | |
1445 | $strictRuleId = 5; | |
1446 | } | |
1447 | elseif ($contactType == 'Household') { | |
1448 | $strictRuleId = 6; | |
1449 | } | |
1450 | ||
1451 | // Default dedupe fields for each Contact type. | |
1452 | if (empty($fields)) { | |
1453 | $fields = array('civicrm_email.email' => 10); | |
1454 | if ($contactType == 'Organization') { | |
1455 | $fields = array( | |
1456 | 'civicrm_contact.organization_name' => 10, | |
1457 | 'civicrm_email.email' => 10, | |
1458 | ); | |
1459 | } | |
1460 | elseif ($contactType == 'Household') { | |
1461 | $fields = array( | |
1462 | 'civicrm_contact.household_name' => 10, | |
1463 | 'civicrm_email.email' => 10, | |
1464 | ); | |
1465 | } | |
1466 | } | |
1467 | ||
b45c587e | 1468 | $this->openCiviPage('contact/deduperules', "action=update&id=$strictRuleId", '_qf_DedupeRules_next-bottom'); |
6a488035 TO |
1469 | |
1470 | $count = 0; | |
1471 | foreach ($fields as $field => $weight) { | |
1472 | $this->select("where_{$count}", "value={$field}"); | |
1473 | $this->type("length_{$count}", ''); | |
1474 | $this->type("weight_{$count}", $weight); | |
1475 | $count++; | |
1476 | } | |
1477 | ||
1478 | if ($count > 4) { | |
1479 | $this->type('threshold', $threshold); | |
1480 | // click save | |
1481 | $this->click('_qf_DedupeRules_next-bottom'); | |
1482 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1483 | return; | |
1484 | } | |
1485 | ||
1486 | for ($i = $count; $i <= 4; $i++) { | |
1487 | $this->select("where_{$i}", 'label=- none -'); | |
1488 | $this->type("length_{$i}", ''); | |
1489 | $this->type("weight_{$i}", ''); | |
1490 | } | |
1491 | ||
1492 | $this->type('threshold', $threshold); | |
1493 | ||
1494 | // click save | |
1495 | $this->click('_qf_DedupeRules_next-bottom'); | |
1496 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
1497 | } | |
1498 | ||
4cbe18b8 EM |
1499 | /** |
1500 | * @param string $period_type | |
1501 | * @param int $duration_interval | |
1502 | * @param string $duration_unit | |
1503 | * @param string $auto_renew | |
1504 | * | |
1505 | * @return array | |
1506 | */ | |
4da07767 | 1507 | public function webtestAddMembershipType($period_type = 'rolling', $duration_interval = 1, $duration_unit = 'year', $auto_renew = 'no', $minimumFee = 100) { |
6a488035 TO |
1508 | $membershipTitle = substr(sha1(rand()), 0, 7); |
1509 | $membershipOrg = $membershipTitle . ' memorg'; | |
1510 | $this->webtestAddOrganization($membershipOrg, TRUE); | |
1511 | ||
1512 | $title = 'Membership Type ' . substr(sha1(rand()), 0, 7); | |
1513 | $memTypeParams = array( | |
1514 | 'membership_type' => $title, | |
1515 | 'member_of_contact' => $membershipOrg, | |
1516 | 'financial_type' => 2, | |
1517 | 'period_type' => $period_type, | |
1518 | ); | |
1519 | ||
42daf119 | 1520 | $this->openCiviPage("admin/member/membershipType/add", "action=add&reset=1", '_qf_MembershipType_cancel-bottom'); |
6a488035 TO |
1521 | |
1522 | $this->type('name', $memTypeParams['membership_type']); | |
1523 | ||
1524 | // if auto_renew optional or required - a valid payment processor must be created first (e.g Auth.net) | |
1525 | // select the radio first since the element id changes after membership org search results are loaded | |
1526 | switch ($auto_renew) { | |
1527 | case 'optional': | |
1528 | $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]"); | |
1529 | break; | |
1530 | ||
1531 | case 'required': | |
1532 | $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Auto-renew required')]"); | |
1533 | break; | |
1534 | ||
1535 | default: | |
1536 | //check if for the element presence (the Auto renew options can be absent when proper payment processor not configured) | |
1537 | if ($this->isElementPresent("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'No auto-renew option')]")) { | |
1538 | $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'No auto-renew option')]"); | |
1539 | } | |
1540 | break; | |
1541 | } | |
1542 | ||
6c6e6187 | 1543 | $this->select2('member_of_contact_id', $membershipTitle); |
6a488035 | 1544 | |
4da07767 | 1545 | $this->type('minimum_fee', $minimumFee); |
6a488035 TO |
1546 | $this->select('financial_type_id', "value={$memTypeParams['financial_type']}"); |
1547 | ||
1548 | $this->type('duration_interval', $duration_interval); | |
1549 | $this->select('duration_unit', "label={$duration_unit}"); | |
1550 | ||
5ddf4885 | 1551 | $this->select('period_type', "value={$period_type}"); |
6a488035 TO |
1552 | |
1553 | $this->click('_qf_MembershipType_upload-bottom'); | |
1554 | $this->waitForElementPresent('link=Add Membership Type'); | |
1555 | $this->assertTrue($this->isTextPresent("The membership type '$title' has been saved.")); | |
1556 | ||
1557 | return $memTypeParams; | |
1558 | } | |
1559 | ||
4cbe18b8 EM |
1560 | /** |
1561 | * @param null $groupName | |
1562 | * @param null $parentGroupName | |
1563 | * | |
1564 | * @return null|string | |
1565 | */ | |
00be9182 | 1566 | public function WebtestAddGroup($groupName = NULL, $parentGroupName = NULL) { |
6a488035 TO |
1567 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom'); |
1568 | ||
1569 | // fill group name | |
1570 | if (!$groupName) { | |
1571 | $groupName = 'group_' . substr(sha1(rand()), 0, 7); | |
1572 | } | |
1573 | $this->type('title', $groupName); | |
1574 | ||
1575 | // fill description | |
1576 | $this->type('description', 'Adding new group.'); | |
1577 | ||
1578 | // check Access Control | |
1579 | $this->click('group_type[1]'); | |
1580 | ||
1581 | // check Mailing List | |
1582 | $this->click('group_type[2]'); | |
1583 | ||
1584 | // select Visibility as Public Pages | |
1585 | $this->select('visibility', 'value=Public Pages'); | |
1586 | ||
1587 | // select parent group | |
1588 | if ($parentGroupName) { | |
1589 | $this->select('parents', "*$parentGroupName"); | |
1590 | } | |
1591 | ||
1592 | // Clicking save. | |
225a8648 | 1593 | $this->clickLink('_qf_Edit_upload-bottom'); |
6a488035 TO |
1594 | |
1595 | // Is status message correct? | |
6c5f7368 | 1596 | $this->waitForText('crm-notification-container', "$groupName"); |
6a488035 TO |
1597 | return $groupName; |
1598 | } | |
1599 | ||
4cbe18b8 EM |
1600 | /** |
1601 | * @param string $activityType | |
1602 | * | |
1603 | * @return null | |
1604 | */ | |
00be9182 | 1605 | public function WebtestAddActivity($activityType = "Meeting") { |
6a488035 TO |
1606 | // Adding Adding contact with randomized first name for test testContactContextActivityAdd |
1607 | // We're using Quick Add block on the main page for this. | |
1608 | $firstName1 = substr(sha1(rand()), 0, 7); | |
1609 | $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name"); | |
1610 | $firstName2 = substr(sha1(rand()), 0, 7); | |
1611 | $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name"); | |
1612 | ||
6a488035 TO |
1613 | $this->click("css=li#tab_activity a"); |
1614 | ||
1615 | // waiting for the activity dropdown to show up | |
1616 | $this->waitForElementPresent("other_activity"); | |
1617 | ||
1618 | // Select the activity type from the activity dropdown | |
1619 | $this->select("other_activity", "label=Meeting"); | |
1620 | ||
1621 | $this->waitForElementPresent("_qf_Activity_upload-bottom"); | |
44a0d8ea | 1622 | $this->waitForElementPresent("s2id_target_contact_id"); |
6a488035 TO |
1623 | |
1624 | $this->assertTrue($this->isTextPresent("Anderson, " . $firstName2), "Contact not found in line " . __LINE__); | |
1625 | ||
1626 | // Typing contact's name into the field (using typeKeys(), not type()!)... | |
44a0d8ea | 1627 | $this->select2("assignee_contact_id", $firstName1, TRUE); |
6a488035 TO |
1628 | |
1629 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
1630 | $this->assertTrue($this->isTextPresent("Summerson, " . $firstName1), "Contact not found in line " . __LINE__); | |
1631 | ||
1632 | // Putting the contents into subject field - assigning the text to variable, it'll come in handy later | |
1633 | $subject = "This is subject of test activity being added through activity tab of contact summary screen."; | |
1634 | // For simple input fields we can use field id as selector | |
1635 | $this->type("subject", $subject); | |
1636 | $this->type("location", "Some location needs to be put in this field."); | |
1637 | ||
1638 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
1639 | ||
1640 | // Setting duration. | |
1641 | $this->type("duration", "30"); | |
1642 | ||
1643 | // Putting in details. | |
1644 | $this->type("details", "Really brief details information."); | |
1645 | ||
1646 | // Making sure that status is set to Scheduled (using value, not label). | |
1647 | $this->select("status_id", "value=1"); | |
1648 | ||
1649 | // Setting priority. | |
1650 | $this->select("priority_id", "value=1"); | |
1651 | ||
1652 | // Scheduling follow-up. | |
1653 | $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header"); | |
1654 | $this->select("followup_activity_type_id", "value=1"); | |
1655 | $this->webtestFillDateTime('followup_date', '+2 month 11:10PM'); | |
1656 | $this->type("followup_activity_subject", "This is subject of schedule follow-up activity"); | |
1657 | ||
1658 | // Clicking save. | |
1659 | $this->click("_qf_Activity_upload-bottom"); | |
44a0d8ea | 1660 | $this->waitForElementPresent("xpath=//div[@id='crm-notification-container']"); |
6a488035 TO |
1661 | |
1662 | // Is status message correct? | |
44a0d8ea | 1663 | $this->waitForText('crm-notification-container', "Activity '$subject' has been saved."); |
6a488035 | 1664 | |
bf333c47 | 1665 | $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody/tr[2]/td[8]/span/a[text()='View']"); |
6a488035 TO |
1666 | |
1667 | // click through to the Activity view screen | |
b3d40287 | 1668 | $this->clickLinkSuppressPopup("xpath=//div[@class='dataTables_wrapper no-footer']//table/tbody/tr[2]/td[8]/span/a[text()='View']", '_qf_Activity_cancel-bottom'); |
76e86fd8 | 1669 | |
efb29358 CW |
1670 | // parse URL to grab the activity id |
1671 | // pass id back to any other tests that call this class | |
1672 | return $this->urlArg('id'); | |
6a488035 TO |
1673 | } |
1674 | ||
4cbe18b8 EM |
1675 | /** |
1676 | * @return bool | |
1677 | */ | |
3bdca100 | 1678 | public static function checkDoLocalDBTest() { |
6a488035 TO |
1679 | if (defined('CIVICRM_WEBTEST_LOCAL_DB') && |
1680 | CIVICRM_WEBTEST_LOCAL_DB | |
1681 | ) { | |
1682 | require_once 'tests/phpunit/CiviTest/CiviDBAssert.php'; | |
1683 | return TRUE; | |
1684 | } | |
1685 | return FALSE; | |
1686 | } | |
1687 | ||
1688 | /** | |
eceb18cc | 1689 | * Generic function to compare expected values after an api call to retrieved. |
6a488035 TO |
1690 | * DB values. |
1691 | * | |
fcb93467 EM |
1692 | * @param string $daoName |
1693 | * DAO Name of object we're evaluating. | |
1694 | * @param int $id | |
1695 | * Id of object | |
1696 | * @param array $match | |
1697 | * Associative array of field name => expected value. Empty if asserting | |
6a488035 | 1698 | * that a DELETE occurred |
3bdca100 | 1699 | * @param bool $delete |
fcb93467 | 1700 | * are we checking that a DELETE action occurred? |
6a488035 | 1701 | */ |
00be9182 | 1702 | public function assertDBState($daoName, $id, $match, $delete = FALSE) { |
fcb93467 EM |
1703 | if (self::checkDoLocalDBTest()) { |
1704 | CiviDBAssert::assertDBState($this, $daoName, $id, $match, $delete); | |
6a488035 | 1705 | } |
6a488035 TO |
1706 | } |
1707 | ||
4cbe18b8 | 1708 | /** |
4f1f1f2a | 1709 | * Request a record from the DB by seachColumn+searchValue. Success if a record is found. |
c490a46a | 1710 | * @param string $daoName |
08caad8e EM |
1711 | * @param string $searchValue |
1712 | * @param string $returnColumn | |
1713 | * @param string $searchColumn | |
1714 | * @param string $message | |
4cbe18b8 | 1715 | */ |
00be9182 | 1716 | public function assertDBNotNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) { |
08caad8e EM |
1717 | if (self::checkDoLocalDBTest()) { |
1718 | CiviDBAssert::assertDBNotNull($this, $daoName, $searchValue, $returnColumn, $searchColumn, $message); | |
6a488035 | 1719 | } |
6a488035 TO |
1720 | } |
1721 | ||
4cbe18b8 | 1722 | /** |
08caad8e | 1723 | * Request a record from the DB by searchColumn+searchValue. Success if returnColumn value is NULL. |
c490a46a | 1724 | * @param string $daoName |
08caad8e EM |
1725 | * @param string $searchValue |
1726 | * @param string $returnColumn | |
1727 | * @param string $searchColumn | |
1728 | * @param string $message | |
4cbe18b8 | 1729 | */ |
00be9182 | 1730 | public function assertDBNull($daoName, $searchValue, $returnColumn, $searchColumn, $message) { |
08caad8e EM |
1731 | if (self::checkDoLocalDBTest()) { |
1732 | CiviDBAssert::assertDBNull($this, $daoName, $searchValue, $returnColumn, $searchColumn, $message); | |
6a488035 | 1733 | } |
6a488035 TO |
1734 | } |
1735 | ||
4cbe18b8 | 1736 | /** |
4f1f1f2a | 1737 | * Request a record from the DB by id. Success if row not found. |
c490a46a | 1738 | * @param string $daoName |
100fef9d | 1739 | * @param int $id |
9d06e7e6 | 1740 | * @param string $message |
4cbe18b8 | 1741 | */ |
08caad8e EM |
1742 | public function assertDBRowNotExist($daoName, $id, $message) { |
1743 | if (self::checkDoLocalDBTest()) { | |
1744 | CiviDBAssert::assertDBRowNotExist($this, $daoName, $id, $message); | |
6a488035 | 1745 | } |
6a488035 TO |
1746 | } |
1747 | ||
4cbe18b8 | 1748 | /** |
eceb18cc | 1749 | * Compare all values in a single retrieved DB record to an array of expected values. |
c490a46a | 1750 | * @param string $daoName |
100fef9d | 1751 | * @param array $searchParams |
4cbe18b8 EM |
1752 | * @param $expectedValues |
1753 | */ | |
00be9182 | 1754 | public function assertDBCompareValues($daoName, $searchParams, $expectedValues) { |
b7d77cba EM |
1755 | if (self::checkDoLocalDBTest()) { |
1756 | CiviDBAssert::assertDBCompareValues($this, $daoName, $searchParams, $expectedValues); | |
6a488035 | 1757 | } |
6a488035 TO |
1758 | } |
1759 | ||
4cbe18b8 EM |
1760 | /** |
1761 | * @param $expected | |
1762 | * @param $actual | |
1763 | * @param string $message | |
1764 | */ | |
00be9182 | 1765 | public function assertType($expected, $actual, $message = '') { |
b7d77cba | 1766 | $this->assertInternalType($expected, $actual, $message); |
6a488035 TO |
1767 | } |
1768 | ||
6a488035 | 1769 | /** |
eceb18cc | 1770 | * Add new Financial Account. |
f0be539a EM |
1771 | * @param $financialAccountTitle |
1772 | * @param bool $financialAccountDescription | |
1773 | * @param bool $accountingCode | |
1774 | * @param bool $firstName | |
1775 | * @param bool $financialAccountType | |
1776 | * @param bool $taxDeductible | |
1777 | * @param bool $isActive | |
1778 | * @param bool $isTax | |
1779 | * @param bool $taxRate | |
1780 | * @param bool $isDefault | |
6a488035 | 1781 | */ |
3bdca100 | 1782 | public function _testAddFinancialAccount( |
5896d037 TO |
1783 | $financialAccountTitle, |
1784 | $financialAccountDescription = FALSE, | |
1785 | $accountingCode = FALSE, | |
1786 | $firstName = FALSE, | |
1787 | $financialAccountType = FALSE, | |
1788 | $taxDeductible = FALSE, | |
1789 | $isActive = FALSE, | |
1790 | $isTax = FALSE, | |
1791 | $taxRate = FALSE, | |
1792 | $isDefault = FALSE | |
6a488035 TO |
1793 | ) { |
1794 | ||
b45c587e | 1795 | $this->openCiviPage("admin/financial/financialAccount", "reset=1"); |
6a488035 TO |
1796 | |
1797 | $this->click("link=Add Financial Account"); | |
1798 | $this->waitForElementPresent('_qf_FinancialAccount_cancel-botttom'); | |
1799 | ||
1800 | // Financial Account Name | |
1801 | $this->type('name', $financialAccountTitle); | |
1802 | ||
1803 | // Financial Description | |
1804 | if ($financialAccountDescription) { | |
1805 | $this->type('description', $financialAccountDescription); | |
1806 | } | |
1807 | ||
1808 | //Accounting Code | |
1809 | if ($accountingCode) { | |
1810 | $this->type('accounting_code', $accountingCode); | |
1811 | } | |
1812 | ||
1813 | // Autofill Organization | |
1814 | if ($firstName) { | |
1815 | $this->webtestOrganisationAutocomplete($firstName); | |
1816 | } | |
1817 | ||
1818 | // Financial Account Type | |
1819 | if ($financialAccountType) { | |
1820 | $this->select('financial_account_type_id', "label={$financialAccountType}"); | |
1821 | } | |
1822 | ||
1823 | // Is Tax Deductible | |
1824 | if ($taxDeductible) { | |
1825 | $this->check('is_deductible'); | |
1826 | } | |
1827 | else { | |
1828 | $this->uncheck('is_deductible'); | |
1829 | } | |
1830 | // Is Active | |
1831 | if (!$isActive) { | |
1832 | $this->check('is_active'); | |
1833 | } | |
1834 | else { | |
1835 | $this->uncheck('is_active'); | |
1836 | } | |
1837 | // Is Tax | |
1838 | if ($isTax) { | |
1839 | $this->check('is_tax'); | |
1840 | } | |
1841 | else { | |
1842 | $this->uncheck('is_tax'); | |
1843 | } | |
1844 | // Tax Rate | |
1845 | if ($taxRate) { | |
1846 | $this->type('tax_rate', $taxRate); | |
1847 | } | |
1848 | ||
1849 | // Set Default | |
1850 | if ($isDefault) { | |
1851 | $this->check('is_default'); | |
1852 | } | |
1853 | else { | |
1854 | $this->uncheck('is_default'); | |
1855 | } | |
1856 | $this->click('_qf_FinancialAccount_next-botttom'); | |
6a488035 TO |
1857 | } |
1858 | ||
6a488035 | 1859 | /** |
eceb18cc | 1860 | * Edit Financial Account. |
1e1fdcf6 EM |
1861 | * @param $editfinancialAccount |
1862 | * @param bool $financialAccountTitle | |
1863 | * @param bool $financialAccountDescription | |
1864 | * @param bool $accountingCode | |
1865 | * @param bool $firstName | |
1866 | * @param bool $financialAccountType | |
1867 | * @param bool $taxDeductible | |
1868 | * @param bool $isActive | |
1869 | * @param bool $isTax | |
1870 | * @param bool $taxRate | |
1871 | * @param bool $isDefault | |
6a488035 | 1872 | */ |
3bdca100 | 1873 | public function _testEditFinancialAccount( |
5896d037 | 1874 | $editfinancialAccount, |
92915c55 TO |
1875 | $financialAccountTitle = FALSE, |
1876 | $financialAccountDescription = FALSE, | |
1877 | $accountingCode = FALSE, | |
1878 | $firstName = FALSE, | |
1879 | $financialAccountType = FALSE, | |
1880 | $taxDeductible = FALSE, | |
1881 | $isActive = TRUE, | |
1882 | $isTax = FALSE, | |
1883 | $taxRate = FALSE, | |
1884 | $isDefault = FALSE | |
6a488035 TO |
1885 | ) { |
1886 | if ($firstName) { | |
b45c587e | 1887 | $this->openCiviPage("admin/financial/financialAccount", "reset=1"); |
6a488035 TO |
1888 | } |
1889 | ||
4a058f26 WA |
1890 | $this->waitForElementPresent("xpath=//table/tbody//tr/td[1]/div[text()='{$editfinancialAccount}']/../../td[9]/span/a[text()='Edit']"); |
1891 | $this->clickLink("xpath=//table/tbody//tr/td[1]/div[text()='{$editfinancialAccount}']/../../td[9]/span/a[text()='Edit']", '_qf_FinancialAccount_cancel-botttom', FALSE); | |
6a488035 TO |
1892 | |
1893 | // Change Financial Account Name | |
1894 | if ($financialAccountTitle) { | |
1895 | $this->type('name', $financialAccountTitle); | |
1896 | } | |
1897 | ||
1898 | // Financial Description | |
1899 | if ($financialAccountDescription) { | |
1900 | $this->type('description', $financialAccountDescription); | |
1901 | } | |
1902 | ||
1903 | //Accounting Code | |
1904 | if ($accountingCode) { | |
1905 | $this->type('accounting_code', $accountingCode); | |
1906 | } | |
1907 | ||
6a488035 TO |
1908 | // Autofill Edit Organization |
1909 | if ($firstName) { | |
1910 | $this->webtestOrganisationAutocomplete($firstName); | |
1911 | } | |
1912 | ||
1913 | // Financial Account Type | |
1914 | if ($financialAccountType) { | |
1915 | $this->select('financial_account_type_id', "label={$financialAccountType}"); | |
1916 | } | |
1917 | ||
1918 | // Is Tax Deductible | |
1919 | if ($taxDeductible) { | |
1920 | $this->check('is_deductible'); | |
1921 | } | |
1922 | else { | |
1923 | $this->uncheck('is_deductible'); | |
1924 | } | |
1925 | ||
1926 | // Is Tax | |
1927 | if ($isTax) { | |
1928 | $this->check('is_tax'); | |
1929 | } | |
1930 | else { | |
1931 | $this->uncheck('is_tax'); | |
1932 | } | |
1933 | ||
1934 | // Tax Rate | |
1935 | if ($taxRate) { | |
1936 | $this->type('tax_rate', $taxRate); | |
1937 | } | |
1938 | ||
1939 | // Set Default | |
1940 | if ($isDefault) { | |
1941 | $this->check('is_default'); | |
1942 | } | |
1943 | else { | |
1944 | $this->uncheck('is_default'); | |
1945 | } | |
1946 | ||
1947 | // Is Active | |
1948 | if ($isActive) { | |
1949 | $this->check('is_active'); | |
1950 | } | |
1951 | else { | |
1952 | $this->uncheck('is_active'); | |
1953 | } | |
1954 | $this->click('_qf_FinancialAccount_next-botttom'); | |
6cbe4dc3 | 1955 | $this->waitForElementPresent('link=Add Financial Account'); |
6a488035 TO |
1956 | } |
1957 | ||
6a488035 | 1958 | /** |
eceb18cc | 1959 | * Delete Financial Account. |
1e1fdcf6 | 1960 | * @param $financialAccountTitle |
6a488035 | 1961 | */ |
00be9182 | 1962 | public function _testDeleteFinancialAccount($financialAccountTitle) { |
4a058f26 | 1963 | $this->click("xpath=//table/tbody//tr/td[1]/div[text()='{$financialAccountTitle}']/../../td[9]/span/a[text()='Delete']"); |
6a488035 TO |
1964 | $this->waitForElementPresent('_qf_FinancialAccount_next-botttom'); |
1965 | $this->click('_qf_FinancialAccount_next-botttom'); | |
1966 | $this->waitForElementPresent('link=Add Financial Account'); | |
6cbe4dc3 | 1967 | $this->waitForText('crm-notification-container', "Selected Financial Account has been deleted."); |
6a488035 TO |
1968 | } |
1969 | ||
1970 | /** | |
eceb18cc | 1971 | * Verify data after ADD and EDIT. |
1e1fdcf6 | 1972 | * @param $verifyData |
6a488035 | 1973 | */ |
00be9182 | 1974 | public function _assertFinancialAccount($verifyData) { |
6a488035 TO |
1975 | foreach ($verifyData as $key => $expectedValue) { |
1976 | $actualValue = $this->getValue($key); | |
1977 | if ($key == 'parent_financial_account') { | |
1978 | $this->assertTrue((bool) preg_match("/^{$expectedValue}/", $actualValue)); | |
1979 | } | |
1980 | else { | |
1981 | $this->assertEquals($expectedValue, $actualValue); | |
1982 | } | |
1983 | } | |
1984 | } | |
1985 | ||
4cbe18b8 EM |
1986 | /** |
1987 | * @param $verifySelectFieldData | |
1988 | */ | |
00be9182 | 1989 | public function _assertSelectVerify($verifySelectFieldData) { |
6a488035 TO |
1990 | foreach ($verifySelectFieldData as $key => $expectedvalue) { |
1991 | $actualvalue = $this->getSelectedLabel($key); | |
1992 | $this->assertEquals($expectedvalue, $actualvalue); | |
1993 | } | |
1994 | } | |
1995 | ||
4cbe18b8 EM |
1996 | /** |
1997 | * @param $financialType | |
1998 | * @param string $option | |
1999 | */ | |
00be9182 | 2000 | public function addeditFinancialType($financialType, $option = 'new') { |
b45c587e | 2001 | $this->openCiviPage("admin/financial/financialType", "reset=1"); |
6a488035 TO |
2002 | |
2003 | if ($option == 'Delete') { | |
4a058f26 | 2004 | $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[name]']/../../td[7]/span[2]"); |
6a488035 | 2005 | $this->waitForElementPresent("css=span.btn-slide-active"); |
4a058f26 | 2006 | $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[name]']/../../td[7]/span[2]/ul/li[2]/a"); |
6a488035 TO |
2007 | $this->waitForElementPresent("_qf_FinancialType_next"); |
2008 | $this->click("_qf_FinancialType_next"); | |
6cbe4dc3 AS |
2009 | $this->waitForElementPresent("newFinancialType"); |
2010 | $this->waitForText('crm-notification-container', 'Selected financial type has been deleted.'); | |
6a488035 TO |
2011 | return; |
2012 | } | |
2013 | if ($option == 'new') { | |
2014 | $this->click("link=Add Financial Type"); | |
2015 | } | |
2016 | else { | |
4a058f26 | 2017 | $this->click("xpath=id('ltype')/div/table/tbody/tr/td[1]/div[text()='$financialType[oldname]']/../../td[7]/span/a[text()='Edit']"); |
6a488035 | 2018 | } |
c1d1bf14 | 2019 | $this->waitForElementPresent("name"); |
6a488035 TO |
2020 | $this->type('name', $financialType['name']); |
2021 | if ($option == 'new') { | |
2022 | $this->type('description', $financialType['name'] . ' description'); | |
2023 | } | |
2024 | ||
2025 | if ($financialType['is_reserved']) { | |
2026 | $this->check('is_reserved'); | |
2027 | } | |
2028 | else { | |
2029 | $this->uncheck('is_reserved'); | |
2030 | } | |
2031 | ||
2032 | if ($financialType['is_deductible']) { | |
2033 | $this->check('is_deductible'); | |
2034 | } | |
2035 | else { | |
2036 | $this->uncheck('is_deductible'); | |
2037 | } | |
2038 | ||
2039 | $this->click('_qf_FinancialType_next'); | |
6a488035 | 2040 | if ($option == 'new') { |
ba6f320f | 2041 | $text = "Your Financial \"{$financialType['name']}\" Type has been created, along with a corresponding income account \"{$financialType['name']}\". That income account, along with standard financial accounts \"Accounts Receivable\", \"Banking Fees\" and \"Premiums\" have been linked to the financial type. You may edit or replace those relationships here."; |
6a488035 TO |
2042 | } |
2043 | else { | |
c51f8adb | 2044 | $text = "The financial type \"{$financialType['name']}\" has been updated."; |
6a488035 | 2045 | } |
5c88df60 | 2046 | $this->checkCRMAlert($text); |
6a488035 TO |
2047 | } |
2048 | ||
42daf119 | 2049 | /** |
eceb18cc | 2050 | * Give the specified permissions. |
b45c587e | 2051 | * Note: this function logs in as 'admin' (logging out if necessary) |
1e1fdcf6 | 2052 | * @param $permission |
42daf119 | 2053 | */ |
00be9182 | 2054 | public function changePermissions($permission) { |
42daf119 CW |
2055 | $this->webtestLogin('admin'); |
2056 | $this->open("{$this->sboxPath}admin/people/permissions"); | |
6a488035 | 2057 | $this->waitForElementPresent('edit-submit'); |
42daf119 CW |
2058 | foreach ((array) $permission as $perm) { |
2059 | $this->check($perm); | |
6a488035 TO |
2060 | } |
2061 | $this->click('edit-submit'); | |
2062 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
2063 | $this->assertTrue($this->isTextPresent('The changes have been saved.')); | |
6a488035 TO |
2064 | } |
2065 | ||
4cbe18b8 EM |
2066 | /** |
2067 | * @param $profileTitle | |
2068 | * @param $profileFields | |
2069 | */ | |
00be9182 | 2070 | public function addProfile($profileTitle, $profileFields) { |
42daf119 | 2071 | $this->openCiviPage('admin/uf/group', "reset=1"); |
6a488035 | 2072 | |
39a2888d | 2073 | $this->clickLink('link=Add Profile', '_qf_Group_cancel-bottom'); |
6a488035 | 2074 | $this->type('title', $profileTitle); |
7df6dc24 | 2075 | $this->clickLink('_qf_Group_next-bottom'); |
6a488035 | 2076 | |
39a2888d | 2077 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
6a488035 TO |
2078 | |
2079 | foreach ($profileFields as $field) { | |
2080 | $this->waitForElementPresent('field_name_0'); | |
6a488035 TO |
2081 | $this->click("id=field_name_0"); |
2082 | $this->select("id=field_name_0", "label=" . $field['type']); | |
2083 | $this->waitForElementPresent('field_name_1'); | |
2084 | $this->click("id=field_name_1"); | |
2085 | $this->select("id=field_name_1", "label=" . $field['name']); | |
2086 | $this->waitForElementPresent('label'); | |
2087 | $this->type("id=label", $field['label']); | |
2088 | $this->click("id=_qf_Field_next_new-top"); | |
bf2c3b74 | 2089 | $this->waitForElementPresent("xpath=//select[@id='field_name_1'][@style='display: none;']"); |
6a488035 TO |
2090 | //$this->assertTrue($this->isTextPresent("Your CiviCRM Profile Field '" . $field['name'] . "' has been saved to '" . $profileTitle . "'. You can add another profile field.")); |
2091 | } | |
2092 | } | |
2093 | ||
4cbe18b8 | 2094 | /** |
100fef9d | 2095 | * @param string $name |
4cbe18b8 EM |
2096 | * @param $sku |
2097 | * @param $amount | |
2098 | * @param $price | |
2099 | * @param $cost | |
2100 | * @param $financialType | |
2101 | */ | |
00be9182 | 2102 | public function addPremium($name, $sku, $amount, $price, $cost, $financialType) { |
022def1d | 2103 | $this->waitForElementPresent("_qf_ManagePremiums_upload-bottom"); |
6a488035 TO |
2104 | $this->type("name", $name); |
2105 | $this->type("sku", $sku); | |
2106 | $this->click("CIVICRM_QFID_noImage_16"); | |
2107 | $this->type("min_contribution", $amount); | |
2108 | $this->type("price", $price); | |
2109 | $this->type("cost", $cost); | |
2110 | if ($financialType) { | |
2111 | $this->select("financial_type_id", "label={$financialType}"); | |
2112 | } | |
022def1d | 2113 | $this->click("_qf_ManagePremiums_upload-bottom"); |
6a488035 TO |
2114 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
2115 | } | |
2116 | ||
4cbe18b8 EM |
2117 | /** |
2118 | * @param $label | |
2119 | * @param $financialAccount | |
2120 | */ | |
00be9182 | 2121 | public function addPaymentInstrument($label, $financialAccount) { |
118e964e | 2122 | $this->openCiviPage('admin/options/payment_instrument', 'action=add&reset=1', "_qf_Options_next-bottom"); |
6a488035 | 2123 | $this->type("label", $label); |
45d22844 | 2124 | $this->type("value", "value" . $label); |
6a488035 TO |
2125 | $this->select("financial_account_id", "value=$financialAccount"); |
2126 | $this->click("_qf_Options_next-bottom"); | |
2127 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
2128 | } | |
2129 | ||
5ff68892 | 2130 | /** |
eceb18cc | 2131 | * Ensure we have a default mailbox set up for CiviMail. |
5ff68892 | 2132 | */ |
00be9182 | 2133 | public function setupDefaultMailbox() { |
5ff68892 CW |
2134 | $this->openCiviPage('admin/mailSettings', 'action=update&id=1&reset=1'); |
2135 | // Check if it hasn't already been set up | |
2136 | if (!$this->getSelectedValue('protocol')) { | |
2137 | $this->type('name', 'Test Domain'); | |
2138 | $this->select('protocol', "IMAP"); | |
2139 | $this->type('server', 'localhost'); | |
2140 | $this->type('domain', 'example.com'); | |
e739afc3 | 2141 | $this->clickLink('_qf_MailSettings_next-top'); |
5ff68892 CW |
2142 | } |
2143 | } | |
2144 | ||
6a488035 TO |
2145 | /** |
2146 | * Determine the default time-out in milliseconds. | |
2147 | * | |
2148 | * @return string, timeout expressed in milliseconds | |
2149 | */ | |
00be9182 | 2150 | public function getTimeoutMsec() { |
6a488035 TO |
2151 | // note: existing local versions of CiviSeleniumSettings may not declare $timeout, so use @ |
2152 | $timeout = ($this->settings && @$this->settings->timeout) ? ($this->settings->timeout * 1000) : 30000; | |
2153 | return (string) $timeout; // don't know why, but all our old code used a string | |
2154 | } | |
6a488035 | 2155 | |
c4e6d4e8 PJ |
2156 | /** |
2157 | * CRM-12378 | |
2158 | * checks custom fields rendering / loading properly on the fly WRT entity passed as parameter | |
2159 | * | |
2160 | * | |
e16033b4 TO |
2161 | * @param array $customSets |
2162 | * Custom sets i.e entity wise sets want to be created and checked. | |
16b10e64 | 2163 | * e.g $customSets = array(array('entity' => 'Contribution', 'subEntity' => 'Donation', |
5896d037 TO |
2164 | * 'triggerElement' => $triggerElement)) |
2165 | * array $triggerElement: the element which is responsible for custom group to load | |
2166 | * | |
2167 | * which uses the entity info as its selection value | |
e16033b4 TO |
2168 | * @param array $pageUrl |
2169 | * The url which on which the ajax custom group load takes place. | |
b7d77cba | 2170 | * @param string $beforeTriggering |
c4e6d4e8 PJ |
2171 | * @return void |
2172 | */ | |
00be9182 | 2173 | public function customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl, $beforeTriggering = NULL) { |
a40669b6 CW |
2174 | // FIXME: Testing a theory that these failures have something to do with permissions |
2175 | $this->webtestLogin('admin'); | |
2176 | ||
c4e6d4e8 PJ |
2177 | //add the custom set |
2178 | $return = $this->addCustomGroupField($customSets); | |
2179 | ||
87f534f9 | 2180 | // FIXME: Hack to ensure caches are properly cleared |
dc499911 CW |
2181 | if (TRUE) { |
2182 | $userName = $this->loggedInAs; | |
e42c089b | 2183 | $this->webtestLogout(); |
dc499911 | 2184 | $this->webtestLogin($userName); |
e42c089b CW |
2185 | } |
2186 | ||
87f534f9 | 2187 | $this->openCiviPage($pageUrl['url'], $pageUrl['args']); |
b50973e8 CW |
2188 | |
2189 | // FIXME: Try to find out what the heck is going on with these tests | |
2190 | $this->waitForAjaxContent(); | |
2191 | $this->checkForErrorsOnPage(); | |
2192 | ||
5896d037 | 2193 | foreach ($return as $values) { |
c4e6d4e8 PJ |
2194 | foreach ($values as $entityType => $customData) { |
2195 | //initiate necessary variables | |
2196 | list($entity, $entityData) = explode('_', $entityType); | |
2197 | $elementType = CRM_Utils_Array::value('type', $customData['triggerElement'], 'select'); | |
2198 | $elementName = CRM_Utils_Array::value('name', $customData['triggerElement']); | |
e42c089b | 2199 | if (is_callable($beforeTriggering)) { |
5b8ddc60 PJ |
2200 | call_user_func($beforeTriggering); |
2201 | } | |
c4e6d4e8 PJ |
2202 | if ($elementType == 'select') { |
2203 | //reset the select box, so triggering of ajax only happens | |
2204 | //WRT input of value in this function | |
2205 | $this->select($elementName, "index=0"); | |
2206 | } | |
2207 | if (!empty($entityData)) { | |
2208 | if ($elementType == 'select') { | |
2209 | $this->select($elementName, "label=regexp:{$entityData}"); | |
2210 | } | |
2211 | elseif ($elementType == 'checkbox') { | |
2212 | $val = explode(',', $entityData); | |
5896d037 | 2213 | foreach ($val as $v) { |
c4e6d4e8 PJ |
2214 | $checkId = $this->getAttribute("xpath=//label[text()='{$v}']/@for"); |
2215 | $this->check($checkId); | |
2216 | } | |
2217 | } | |
16345393 AS |
2218 | elseif ($elementType == 'select2') { |
2219 | $this->select2($elementName, $entityData); | |
2220 | } | |
c4e6d4e8 | 2221 | } |
a2cfaf9e CW |
2222 | // FIXME: Try to find out what the heck is going on with these tests |
2223 | $this->waitForAjaxContent(); | |
2224 | $this->checkForErrorsOnPage(); | |
a40669b6 | 2225 | |
c4e6d4e8 | 2226 | //checking for proper custom data which is loading through ajax |
a40669b6 | 2227 | $this->waitForElementPresent("css=.custom-group-{$customData['cgtitle']}"); |
16345393 | 2228 | $this->assertElementPresent("xpath=//div[contains(@class, 'custom-group-{$customData['cgtitle']}')]/div[contains(@class, 'crm-accordion-body')]/table/tbody/tr/td[2]/input", |
c4e6d4e8 PJ |
2229 | "The on the fly custom group field is not present for entity : {$entity} => {$entityData}"); |
2230 | } | |
2231 | } | |
2232 | } | |
2233 | ||
4cbe18b8 EM |
2234 | /** |
2235 | * @param $customSets | |
2236 | * | |
2237 | * @return array | |
2238 | */ | |
00be9182 | 2239 | public function addCustomGroupField($customSets) { |
57d32317 | 2240 | $return = array(); |
c4e6d4e8 PJ |
2241 | foreach ($customSets as $customSet) { |
2242 | $this->openCiviPage("admin/custom/group", "action=add&reset=1"); | |
2243 | ||
2244 | //fill custom group title | |
2245 | $customGroupTitle = "webtest_for_ajax_cd" . substr(sha1(rand()), 0, 4); | |
2246 | $this->click("title"); | |
2247 | $this->type("title", $customGroupTitle); | |
2248 | ||
2249 | //custom group extends | |
2250 | $this->click("extends_0"); | |
2251 | $this->select("extends_0", "value={$customSet['entity']}"); | |
2252 | if (!empty($customSet['subEntity'])) { | |
2253 | $this->addSelection("extends_1", "label={$customSet['subEntity']}"); | |
2254 | } | |
2255 | ||
2256 | // Don't collapse | |
2257 | $this->uncheck('collapse_display'); | |
2258 | ||
2259 | // Save | |
2260 | $this->click('_qf_Group_next-bottom'); | |
c4e6d4e8 PJ |
2261 | |
2262 | //Is custom group created? | |
2263 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added."); | |
5dac229e | 2264 | |
c4e6d4e8 | 2265 | $gid = $this->urlArg('gid'); |
5dac229e | 2266 | $this->waitForTextPresent("{$customGroupTitle} - New Field"); |
c4e6d4e8 PJ |
2267 | |
2268 | $fieldLabel = "custom_field_for_{$customSet['entity']}_{$customSet['subEntity']}" . substr(sha1(rand()), 0, 4); | |
c3ad8633 | 2269 | $this->waitForElementPresent('label'); |
c4e6d4e8 | 2270 | $this->type('label', $fieldLabel); |
50d95825 | 2271 | $this->click('_qf_Field_done-bottom'); |
c4e6d4e8 | 2272 | |
c3ad8633 CW |
2273 | $this->waitForText('crm-notification-container', $fieldLabel); |
2274 | $this->waitForAjaxContent(); | |
2275 | ||
2276 | $customGroupTitle = preg_replace('/\s/', '_', trim($customGroupTitle)); | |
c4e6d4e8 | 2277 | $return[] = array( |
5896d037 TO |
2278 | "{$customSet['entity']}_{$customSet['subEntity']}" => array( |
2279 | 'cgtitle' => $customGroupTitle, | |
2280 | 'gid' => $gid, | |
21dfd5f5 TO |
2281 | 'triggerElement' => $customSet['triggerElement'], |
2282 | ), | |
5896d037 | 2283 | ); |
e739afc3 CW |
2284 | |
2285 | // Go home for a sec to give time for caches to clear | |
2286 | $this->openCiviPage(''); | |
c4e6d4e8 PJ |
2287 | } |
2288 | return $return; | |
2289 | } | |
5320adf4 WA |
2290 | |
2291 | /** | |
e4f46be0 | 2292 | * Type and select first occurrence of autocomplete. |
1e1fdcf6 EM |
2293 | * @param $fieldName |
2294 | * @param $label | |
2295 | * @param bool $multiple | |
2296 | * @param bool $xpath | |
5320adf4 | 2297 | */ |
0b49a3ec | 2298 | public function select2($fieldName, $labels, $multiple = FALSE, $xpath = FALSE) { |
57d32317 CW |
2299 | // In the case of chainSelect, wait for options to load |
2300 | $this->waitForElementNotPresent('css=select.loading'); | |
2af8120a | 2301 | if ($multiple) { |
761fe7bb | 2302 | foreach ((array) $labels as $label) { |
0b49a3ec | 2303 | $this->clickAt("//*[@id='$fieldName']/../div/ul/li"); |
2304 | $this->keyDown("//*[@id='$fieldName']/../div/ul/li//input", " "); | |
2305 | $this->type("//*[@id='$fieldName']/../div/ul/li//input", $label); | |
2306 | $this->typeKeys("//*[@id='$fieldName']/../div/ul/li//input", $label); | |
2307 | $this->waitForElementPresent("//*[@class='select2-result-label']"); | |
2308 | $this->clickAt("//*[contains(@class,'select2-result-selectable')]/div[contains(@class, 'select2-result-label')]"); | |
2309 | } | |
2af8120a AS |
2310 | } |
2311 | else { | |
3e60ff7f JP |
2312 | if ($xpath) { |
2313 | $this->clickAt($fieldName); | |
2314 | } | |
2315 | else { | |
2316 | $this->clickAt("//*[@id='$fieldName']/../div/a"); | |
2317 | } | |
2af8120a AS |
2318 | $this->waitForElementPresent("//*[@id='select2-drop']/div/input"); |
2319 | $this->keyDown("//*[@id='select2-drop']/div/input", " "); | |
0b49a3ec | 2320 | $this->type("//*[@id='select2-drop']/div/input", $labels); |
2321 | $this->typeKeys("//*[@id='select2-drop']/div/input", $labels); | |
2af8120a | 2322 | $this->waitForElementPresent("//*[@class='select2-result-label']"); |
e9322446 | 2323 | $this->clickAt("//*[contains(@class,'select2-result-selectable')]/div[contains(@class, 'select2-result-label')]"); |
2af8120a | 2324 | } |
e739afc3 CW |
2325 | // Wait a sec for select2 to update the original element |
2326 | sleep(1); | |
5320adf4 | 2327 | } |
f1690d4a | 2328 | |
2329 | /** | |
eceb18cc | 2330 | * Select multiple options. |
1e1fdcf6 EM |
2331 | * @param $fieldid |
2332 | * @param $params | |
06dfe3b5 | 2333 | * @param $isDate if multiple date is to be selected from datepicker |
f1690d4a | 2334 | */ |
06dfe3b5 | 2335 | public function multiselect2($fieldid, $params, $isDate = FALSE) { |
50d95825 CW |
2336 | // In the case of chainSelect, wait for options to load |
2337 | $this->waitForElementNotPresent('css=select.loading'); | |
5896d037 | 2338 | foreach ($params as $value) { |
06dfe3b5 | 2339 | if ($isDate) { |
06dfe3b5 | 2340 | $this->clickAt("xpath=//*[@id='$fieldid']/../div/ul//li/input"); |
cd71816e | 2341 | $this->webtestFillDate($fieldid, $value, TRUE); |
06dfe3b5 | 2342 | } |
2343 | else { | |
2344 | $this->clickAt("xpath=//*[@id='$fieldid']/../div/ul//li/input"); | |
2345 | $this->waitForElementPresent("xpath=//ul[@class='select2-results']"); | |
2346 | $this->clickAt("xpath=//ul[@class='select2-results']//li/div[text()='$value']"); | |
2347 | $this->assertElementContainsText("xpath=//*[@id='$fieldid']/preceding-sibling::div[1]/", $value); | |
2348 | } | |
f1690d4a | 2349 | } |
e739afc3 CW |
2350 | // Wait a sec for select2 to update the original element |
2351 | sleep(1); | |
f1690d4a | 2352 | } |
c41b442d CW |
2353 | |
2354 | /** | |
5c88df60 | 2355 | * Check for unobtrusive status message as set by CRM.status |
1e1fdcf6 | 2356 | * @param null $text |
c41b442d | 2357 | */ |
6c6e6187 | 2358 | public function checkCRMStatus($text = NULL) { |
c41b442d | 2359 | $this->waitForElementPresent("css=.crm-status-box-outer.status-success"); |
5c88df60 CW |
2360 | if ($text) { |
2361 | $this->assertElementContainsText("css=.crm-status-box-outer.status-success", $text); | |
2362 | } | |
c41b442d | 2363 | } |
5c88df60 | 2364 | |
dcba1580 | 2365 | /** |
5c88df60 | 2366 | * Check for obtrusive status message as set by CRM.alert |
1e1fdcf6 EM |
2367 | * @param $text |
2368 | * @param string $type | |
dcba1580 | 2369 | */ |
6c6e6187 | 2370 | public function checkCRMAlert($text, $type = 'success') { |
5c88df60 CW |
2371 | $this->waitForElementPresent("css=div.ui-notify-message.$type"); |
2372 | $this->waitForText("css=div.ui-notify-message.$type", $text); | |
9c5c0056 CW |
2373 | // We got the message, now let's close it so the webtest doesn't get confused by lots of open alerts |
2374 | $this->click('css=.ui-notify-cross'); | |
dcba1580 | 2375 | } |
5c88df60 | 2376 | |
d8d3508a | 2377 | /** |
100fef9d | 2378 | * Enable or disable Pop-ups via Display Preferences |
b7d77cba | 2379 | * @param bool $enabled |
d8d3508a | 2380 | */ |
00be9182 | 2381 | public function enableDisablePopups($enabled = TRUE) { |
d8d3508a DG |
2382 | $this->openCiviPage('admin/setting/preferences/display', 'reset=1'); |
2383 | $isChecked = $this->isChecked('ajaxPopupsEnabled'); | |
2384 | if (($isChecked && !$enabled) || (!$isChecked && $enabled)) { | |
6c6e6187 | 2385 | $this->click('ajaxPopupsEnabled'); |
d8d3508a DG |
2386 | } |
2387 | if ($enabled) { | |
5c88df60 | 2388 | $this->assertChecked('ajaxPopupsEnabled'); |
d8d3508a DG |
2389 | } |
2390 | else { | |
2391 | $this->assertNotChecked('ajaxPopupsEnabled'); | |
2392 | } | |
c41b442d | 2393 | $this->clickLink("_qf_Display_next-bottom"); |
d8d3508a | 2394 | } |
b50973e8 CW |
2395 | |
2396 | /** | |
eceb18cc | 2397 | * Attempt to get information about what went wrong if we encounter an error when loading a page. |
b50973e8 | 2398 | */ |
00be9182 | 2399 | public function checkForErrorsOnPage() { |
b50973e8 | 2400 | foreach (array('Access denied', 'Page not found') as $err) { |
037454ae CW |
2401 | if ($this->isElementPresent("xpath=//h1[contains(., '$err')]")) { |
2402 | $this->fail("'$err' encountered at " . $this->getLocation() . "\nwhile logged in as '{$this->loggedInAs}'"); | |
b50973e8 CW |
2403 | } |
2404 | } | |
2405 | if ($this->isElementPresent("xpath=//span[text()='Sorry but we are not able to provide this at the moment.']")) { | |
2406 | $msg = '"Fatal Error" encountered at ' . $this->getLocation(); | |
2407 | if ($this->isElementPresent('css=div.crm-section.crm-error-message')) { | |
2408 | $msg .= "\nError Message: " . $this->getText('css=div.crm-section.crm-error-message'); | |
2409 | } | |
2410 | $this->fail($msg); | |
2411 | } | |
2412 | } | |
96025800 | 2413 | |
ef9cbdb7 TO |
2414 | /** |
2415 | * @return array | |
2416 | * Contact record (per APIv3). | |
2417 | */ | |
2418 | public function webtestGetLoggedInContact() { | |
2419 | $result = $this->rest_civicrm_api('Contact', 'get', array( | |
2420 | 'id' => 'user_contact_id', | |
2421 | )); | |
2422 | $this->assertAPISuccess($result, 'Load logged-in contact'); | |
2423 | return CRM_Utils_Array::first($result['values']); | |
2424 | } | |
2425 | ||
2426 | public function assertAPISuccess($apiResult, $prefix = '') { | |
2427 | if (!empty($prefix)) { | |
2428 | $prefix .= ': '; | |
2429 | } | |
2430 | $errorMessage = empty($apiResult['error_message']) ? '' : " " . $apiResult['error_message']; | |
2431 | ||
2432 | if (!empty($apiResult['debug_information'])) { | |
2433 | $errorMessage .= "\n " . print_r($apiResult['debug_information'], TRUE); | |
2434 | } | |
2435 | if (!empty($apiResult['trace'])) { | |
2436 | $errorMessage .= "\n" . print_r($apiResult['trace'], TRUE); | |
2437 | } | |
2438 | $this->assertFalse(civicrm_error($apiResult), $prefix . $errorMessage); | |
2439 | //$this->assertEquals(0, $apiResult['is_error']); | |
2440 | } | |
2441 | ||
65c1908a | 2442 | } |