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