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