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