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