| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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 | |
| 28 | /** |
| 29 | * |
| 30 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | /** |
| 37 | * Helper authentication class for unit tests |
| 38 | */ |
| 39 | class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { |
| 40 | /** |
| 41 | */ |
| 42 | public function __construct() { |
| 43 | $this->is_drupal = FALSE; |
| 44 | $this->supports_form_extensions = FALSE; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Sets the title of the page |
| 49 | * |
| 50 | * @param string $title |
| 51 | * @param null $pageTitle |
| 52 | * |
| 53 | * @paqram string $pageTitle |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | /** |
| 58 | * @param string $title |
| 59 | * @param null $pageTitle |
| 60 | */ |
| 61 | public function setTitle($title, $pageTitle = NULL) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Authenticate the user against the drupal db |
| 67 | * |
| 68 | * @param string $name |
| 69 | * The user name. |
| 70 | * @param string $password |
| 71 | * The password for the above user name. |
| 72 | * @param bool $loadCMSBootstrap |
| 73 | * Load cms bootstrap?. |
| 74 | * @param NULL|string $realPath filename of script |
| 75 | * |
| 76 | * @return array|bool |
| 77 | * [contactID, ufID, uniqueString] if success else false if no auth |
| 78 | */ |
| 79 | /** |
| 80 | * @param string $name |
| 81 | * @param string $password |
| 82 | * @param bool $loadCMSBootstrap |
| 83 | * @param null|string $realPath |
| 84 | * |
| 85 | * @return mixed |
| 86 | */ |
| 87 | public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { |
| 88 | $retVal = array(1, 1, 12345); |
| 89 | return $retVal; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Append an additional breadcrumb tag to the existing breadcrumb |
| 94 | * |
| 95 | * @param $breadCrumbs |
| 96 | * |
| 97 | * @internal param string $title |
| 98 | * @internal param string $url |
| 99 | * |
| 100 | * @return void |
| 101 | */ |
| 102 | /** |
| 103 | * @param $breadCrumbs |
| 104 | */ |
| 105 | public function appendBreadCrumb($breadCrumbs) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | public function resetBreadCrumb() { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Append a string to the head of the html file |
| 115 | * |
| 116 | * @param string $header |
| 117 | * The new string to be appended. |
| 118 | * |
| 119 | * @return void |
| 120 | */ |
| 121 | /** |
| 122 | * @param string $head |
| 123 | */ |
| 124 | public function addHTMLHead($head) { |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | public function mapConfigToSSL() { |
| 129 | global $base_url; |
| 130 | $base_url = str_replace('http://', 'https://', $base_url); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Figure out the post url for the form |
| 135 | * |
| 136 | * @param mix $action |
| 137 | * The default action if one is pre-specified. |
| 138 | * |
| 139 | * @return string |
| 140 | * the url to post the form |
| 141 | */ |
| 142 | /** |
| 143 | * @param mix $action |
| 144 | * |
| 145 | * @return string |
| 146 | */ |
| 147 | public function postURL($action) { |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) |
| 153 | * |
| 154 | * @param string $path |
| 155 | * The path being linked to, such as "civicrm/add". |
| 156 | * @param string $query |
| 157 | * A query string to append to the link. |
| 158 | * @param bool $absolute |
| 159 | * Whether to force the output to be an absolute link (beginning with http:). |
| 160 | * Useful for links that will be displayed outside the site, such as in an |
| 161 | * RSS feed. |
| 162 | * @param string $fragment |
| 163 | * A fragment identifier (named anchor) to append to the link. |
| 164 | * @param bool $htmlize |
| 165 | * whether to convert to html eqivalant. |
| 166 | * @param bool $frontend |
| 167 | * a gross joomla hack. |
| 168 | * @param bool $forceBackend |
| 169 | * a gross joomla hack. |
| 170 | * |
| 171 | * @return string |
| 172 | * an HTML string containing a link to the given path. |
| 173 | */ |
| 174 | /** |
| 175 | * @param null|string $path |
| 176 | * @param null|string $query |
| 177 | * @param bool $absolute |
| 178 | * @param null|string $fragment |
| 179 | * @param bool $htmlize |
| 180 | * @param bool $frontend |
| 181 | * @param bool $forceBackend |
| 182 | * |
| 183 | * @return string |
| 184 | */ |
| 185 | function url( |
| 186 | $path = NULL, $query = NULL, $absolute = FALSE, |
| 187 | $fragment = NULL, $htmlize = TRUE, |
| 188 | $frontend = FALSE, $forceBackend = FALSE |
| 189 | ) { |
| 190 | $config = CRM_Core_Config::singleton(); |
| 191 | static $script = 'index.php'; |
| 192 | |
| 193 | if (isset($fragment)) { |
| 194 | $fragment = '#' . $fragment; |
| 195 | } |
| 196 | |
| 197 | if (!isset($config->useFrameworkRelativeBase)) { |
| 198 | $base = parse_url($config->userFrameworkBaseURL); |
| 199 | $config->useFrameworkRelativeBase = $base['path']; |
| 200 | } |
| 201 | $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; |
| 202 | |
| 203 | $separator = $htmlize ? '&' : '&'; |
| 204 | |
| 205 | if (!$config->cleanURL) { |
| 206 | if (isset($path)) { |
| 207 | if (isset($query)) { |
| 208 | return $base . $script . '?q=' . $path . $separator . $query . $fragment; |
| 209 | } |
| 210 | else { |
| 211 | return $base . $script . '?q=' . $path . $fragment; |
| 212 | } |
| 213 | } |
| 214 | else { |
| 215 | if (isset($query)) { |
| 216 | return $base . $script . '?' . $query . $fragment; |
| 217 | } |
| 218 | else { |
| 219 | return $base . $fragment; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | else { |
| 224 | if (isset($path)) { |
| 225 | if (isset($query)) { |
| 226 | return $base . $path . '?' . $query . $fragment; |
| 227 | } |
| 228 | else { |
| 229 | return $base . $path . $fragment; |
| 230 | } |
| 231 | } |
| 232 | else { |
| 233 | if (isset($query)) { |
| 234 | return $base . $script . '?' . $query . $fragment; |
| 235 | } |
| 236 | else { |
| 237 | return $base . $fragment; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * @param $user |
| 245 | */ |
| 246 | public function getUserID($user) { |
| 247 | //FIXME: look here a bit closer when testing UFMatch |
| 248 | |
| 249 | // this puts the appropriate values in the session, so |
| 250 | // no need to return anything |
| 251 | CRM_Core_BAO_UFMatch::synchronize($user, TRUE, 'Standalone', 'Individual'); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * @param $user |
| 256 | * |
| 257 | * @return bool |
| 258 | */ |
| 259 | public function getAllowedToLogin($user) { |
| 260 | return TRUE; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Set a message in the UF to display to a user |
| 265 | * |
| 266 | * @param string $message |
| 267 | * The message to set. |
| 268 | */ |
| 269 | /** |
| 270 | * @param string $message |
| 271 | */ |
| 272 | public function setMessage($message) { |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | public function permissionDenied() { |
| 277 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
| 278 | } |
| 279 | |
| 280 | public function logout() { |
| 281 | session_destroy(); |
| 282 | header("Location:index.php"); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Get the locale set in the hosting CMS |
| 287 | * |
| 288 | * @return string |
| 289 | * with the locale or null for none |
| 290 | */ |
| 291 | /** |
| 292 | * @return string |
| 293 | */ |
| 294 | public function getUFLocale() { |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Get a list of all installed modules, including enabled and disabled ones |
| 300 | * |
| 301 | * @return array |
| 302 | * CRM_Core_Module |
| 303 | */ |
| 304 | /** |
| 305 | * @return array |
| 306 | */ |
| 307 | public function getModules() { |
| 308 | return array(); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Get user login URL for hosting CMS (method declared in each CMS system class) |
| 313 | * |
| 314 | * @param string $destination |
| 315 | * If present, add destination to querystring (works for Drupal only). |
| 316 | * |
| 317 | * @throws Exception |
| 318 | * @return string |
| 319 | * loginURL for the current CMS |
| 320 | */ |
| 321 | public function getLoginURL($destination = '') { |
| 322 | throw new Exception("Method not implemented: getLoginURL"); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Over-ridable function to get timezone as a string eg. |
| 327 | * @return string |
| 328 | * Timezone e.g. 'America/Los_Angeles' |
| 329 | */ |
| 330 | public function getTimeZoneString() { |
| 331 | // This class extends Drupal, but we don't want Drupal's behavior; reproduce CRM_Utils_System_Base::getTimeZoneString |
| 332 | return date_default_timezone_get(); |
| 333 | } |
| 334 | |
| 335 | public function clearResourceCache() { |
| 336 | // UGH. Obscure Drupal-specific implementation. Why does UnitTests extend Drupal? |
| 337 | // You should delete this function if the base-classes are properly rearranged. |
| 338 | } |
| 339 | } |