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 | 40 | /** |
bb3a214a | 41 | */ |
00be9182 | 42 | public function __construct() { |
6a488035 | 43 | $this->is_drupal = FALSE; |
e7292422 | 44 | $this->supports_form_extensions = FALSE; |
6a488035 TO |
45 | } |
46 | ||
bb3a214a | 47 | /** |
100fef9d | 48 | * Sets the title of the page |
bb3a214a EM |
49 | * |
50 | * @param string $title | |
51 | * @param null $pageTitle | |
52 | * | |
53 | * @paqram string $pageTitle | |
54 | * | |
55 | * @return void | |
bb3a214a EM |
56 | */ |
57 | /** | |
58 | * @param string $title | |
59 | * @param null $pageTitle | |
60 | */ | |
00be9182 | 61 | public function setTitle($title, $pageTitle = NULL) { |
6a488035 TO |
62 | return; |
63 | } | |
64 | ||
bb3a214a EM |
65 | /** |
66 | * Authenticate the user against the drupal db | |
67 | * | |
77855840 TO |
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?. | |
bb3a214a EM |
74 | * @param NULL|string $realPath filename of script |
75 | * | |
72b3a70c CW |
76 | * @return array|bool |
77 | * [contactID, ufID, uniqueString] if success else false if no auth | |
bb3a214a EM |
78 | */ |
79 | /** | |
80 | * @param string $name | |
81 | * @param string $password | |
82 | * @param bool $loadCMSBootstrap | |
83 | * @param null|string $realPath | |
84 | * | |
85 | * @return mixed | |
86 | */ | |
00be9182 | 87 | public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { |
6a488035 TO |
88 | $retVal = array(1, 1, 12345); |
89 | return $retVal; | |
90 | } | |
91 | ||
bb3a214a EM |
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 | |
bb3a214a EM |
101 | */ |
102 | /** | |
103 | * @param $breadCrumbs | |
104 | */ | |
00be9182 | 105 | public function appendBreadCrumb($breadCrumbs) { |
6a488035 TO |
106 | return; |
107 | } | |
108 | ||
00be9182 | 109 | public function resetBreadCrumb() { |
6a488035 TO |
110 | return; |
111 | } | |
112 | ||
bb3a214a EM |
113 | /** |
114 | * Append a string to the head of the html file | |
115 | * | |
77855840 TO |
116 | * @param string $header |
117 | * The new string to be appended. | |
bb3a214a EM |
118 | * |
119 | * @return void | |
bb3a214a EM |
120 | */ |
121 | /** | |
122 | * @param string $head | |
123 | */ | |
00be9182 | 124 | public function addHTMLHead($head) { |
6a488035 TO |
125 | return; |
126 | } | |
127 | ||
00be9182 | 128 | public function mapConfigToSSL() { |
6a488035 TO |
129 | global $base_url; |
130 | $base_url = str_replace('http://', 'https://', $base_url); | |
131 | } | |
132 | ||
bb3a214a | 133 | /** |
100fef9d | 134 | * Figure out the post url for the form |
bb3a214a | 135 | * |
77855840 TO |
136 | * @param mix $action |
137 | * The default action if one is pre-specified. | |
bb3a214a | 138 | * |
a6c01b45 CW |
139 | * @return string |
140 | * the url to post the form | |
bb3a214a EM |
141 | */ |
142 | /** | |
143 | * @param mix $action | |
144 | * | |
145 | * @return string | |
146 | */ | |
00be9182 | 147 | public function postURL($action) { |
6a488035 TO |
148 | return; |
149 | } | |
150 | ||
bb3a214a EM |
151 | /** |
152 | * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) | |
153 | * | |
5a4f6742 CW |
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:). | |
bb3a214a EM |
160 | * Useful for links that will be displayed outside the site, such as in an |
161 | * RSS feed. | |
5a4f6742 CW |
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. | |
bb3a214a | 170 | * |
a6c01b45 CW |
171 | * @return string |
172 | * an HTML string containing a link to the given path. | |
bb3a214a EM |
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 | */ | |
a3e55d9c TO |
185 | function url( |
186 | $path = NULL, $query = NULL, $absolute = FALSE, | |
6a488035 TO |
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 | ||
bb3a214a EM |
243 | /** |
244 | * @param $user | |
245 | */ | |
00be9182 | 246 | public function getUserID($user) { |
6a488035 TO |
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 | ||
bb3a214a EM |
254 | /** |
255 | * @param $user | |
256 | * | |
257 | * @return bool | |
258 | */ | |
00be9182 | 259 | public function getAllowedToLogin($user) { |
6a488035 TO |
260 | return TRUE; |
261 | } | |
262 | ||
bb3a214a EM |
263 | /** |
264 | * Set a message in the UF to display to a user | |
265 | * | |
77855840 TO |
266 | * @param string $message |
267 | * The message to set. | |
bb3a214a EM |
268 | */ |
269 | /** | |
270 | * @param string $message | |
271 | */ | |
00be9182 | 272 | public function setMessage($message) { |
6a488035 TO |
273 | return; |
274 | } | |
275 | ||
00be9182 | 276 | public function permissionDenied() { |
0499b0ad | 277 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
278 | } |
279 | ||
00be9182 | 280 | public function logout() { |
6a488035 TO |
281 | session_destroy(); |
282 | header("Location:index.php"); | |
283 | } | |
284 | ||
bb3a214a EM |
285 | /** |
286 | * Get the locale set in the hosting CMS | |
287 | * | |
a6c01b45 CW |
288 | * @return string |
289 | * with the locale or null for none | |
bb3a214a EM |
290 | */ |
291 | /** | |
292 | * @return string | |
293 | */ | |
00be9182 | 294 | public function getUFLocale() { |
6a488035 TO |
295 | return NULL; |
296 | } | |
297 | ||
bb3a214a EM |
298 | /** |
299 | * Get a list of all installed modules, including enabled and disabled ones | |
300 | * | |
a6c01b45 CW |
301 | * @return array |
302 | * CRM_Core_Module | |
bb3a214a EM |
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 |
a6c01b45 CW |
318 | * @return string |
319 | * loginURL for the current CMS | |
6a488035 TO |
320 | * @static |
321 | */ | |
322 | public function getLoginURL($destination = '') { | |
323 | throw new Exception("Method not implemented: getLoginURL"); | |
324 | } | |
450f494d | 325 | |
48ec57ab TO |
326 | /** |
327 | * Over-ridable function to get timezone as a string eg. | |
a6c01b45 CW |
328 | * @return string |
329 | * Timezone e.g. 'America/Los_Angeles' | |
48ec57ab | 330 | */ |
00be9182 | 331 | public function getTimeZoneString() { |
48ec57ab TO |
332 | // This class extends Drupal, but we don't want Drupal's behavior; reproduce CRM_Utils_System_Base::getTimeZoneString |
333 | return date_default_timezone_get(); | |
334 | } | |
1c4e4e61 | 335 | |
00be9182 | 336 | public function clearResourceCache() { |
1c4e4e61 TO |
337 | // UGH. Obscure Drupal-specific implementation. Why does UnitTests extend Drupal? |
338 | // You should delete this function if the base-classes are properly rearranged. | |
339 | } | |
6a488035 | 340 | } |