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