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