INFRA-132 - Remove extra newlines from the bottom of docblocks
[civicrm-core.git] / CRM / Utils / System / UnitTests.php
CommitLineData
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 */
39class 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 *
76 * @return mixed false if no auth
77 * array(
78 * contactID, ufID, unique string ) if success
bb3a214a
EM
79 */
80 /**
81 * @param string $name
82 * @param string $password
83 * @param bool $loadCMSBootstrap
84 * @param null|string $realPath
85 *
86 * @return mixed
87 */
00be9182 88 public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
6a488035
TO
89 $retVal = array(1, 1, 12345);
90 return $retVal;
91 }
92
bb3a214a
EM
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
bb3a214a
EM
102 */
103 /**
104 * @param $breadCrumbs
105 */
00be9182 106 public function appendBreadCrumb($breadCrumbs) {
6a488035
TO
107 return;
108 }
109
00be9182 110 public function resetBreadCrumb() {
6a488035
TO
111 return;
112 }
113
bb3a214a
EM
114 /**
115 * Append a string to the head of the html file
116 *
77855840
TO
117 * @param string $header
118 * The new string to be appended.
bb3a214a
EM
119 *
120 * @return void
bb3a214a
EM
121 */
122 /**
123 * @param string $head
124 */
00be9182 125 public function addHTMLHead($head) {
6a488035
TO
126 return;
127 }
128
00be9182 129 public function mapConfigToSSL() {
6a488035
TO
130 global $base_url;
131 $base_url = str_replace('http://', 'https://', $base_url);
132 }
133
bb3a214a 134 /**
100fef9d 135 * Figure out the post url for the form
bb3a214a 136 *
77855840
TO
137 * @param mix $action
138 * The default action if one is pre-specified.
bb3a214a 139 *
a6c01b45
CW
140 * @return string
141 * 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 *
5a4f6742
CW
155 * @param string $path
156 * The path being linked to, such as "civicrm/add".
157 * @param string $query
158 * A query string to append to the link.
159 * @param bool $absolute
160 * 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.
5a4f6742
CW
163 * @param string $fragment
164 * A fragment identifier (named anchor) to append to the link.
165 * @param bool $htmlize
166 * whether to convert to html eqivalant.
167 * @param bool $frontend
168 * a gross joomla hack.
169 * @param bool $forceBackend
170 * a gross joomla hack.
bb3a214a 171 *
a6c01b45
CW
172 * @return string
173 * an HTML string containing a link to the given path.
bb3a214a
EM
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 ? '&amp;' : '&';
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
EM
269 */
270 /**
271 * @param string $message
272 */
00be9182 273 public function setMessage($message) {
6a488035
TO
274 return;
275 }
276
00be9182 277 public function permissionDenied() {
0499b0ad 278 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
279 }
280
00be9182 281 public function logout() {
6a488035
TO
282 session_destroy();
283 header("Location:index.php");
284 }
285
bb3a214a
EM
286 /**
287 * Get the locale set in the hosting CMS
288 *
a6c01b45
CW
289 * @return string
290 * with the locale or null for none
bb3a214a
EM
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 *
a6c01b45
CW
302 * @return array
303 * CRM_Core_Module
bb3a214a
EM
304 */
305 /**
306 * @return array
307 */
00be9182 308 public function getModules() {
6a488035
TO
309 return array();
310 }
311
312 /**
313 * Get user login URL for hosting CMS (method declared in each CMS system class)
314 *
77855840
TO
315 * @param string $destination
316 * If present, add destination to querystring (works for Drupal only).
6a488035 317 *
f4aaa82a 318 * @throws Exception
a6c01b45
CW
319 * @return string
320 * loginURL for the current CMS
6a488035
TO
321 * @static
322 */
323 public function getLoginURL($destination = '') {
324 throw new Exception("Method not implemented: getLoginURL");
325 }
450f494d 326
48ec57ab
TO
327 /**
328 * Over-ridable function to get timezone as a string eg.
a6c01b45
CW
329 * @return string
330 * Timezone e.g. 'America/Los_Angeles'
48ec57ab 331 */
00be9182 332 public function getTimeZoneString() {
48ec57ab
TO
333 // This class extends Drupal, but we don't want Drupal's behavior; reproduce CRM_Utils_System_Base::getTimeZoneString
334 return date_default_timezone_get();
335 }
1c4e4e61 336
00be9182 337 public function clearResourceCache() {
1c4e4e61
TO
338 // UGH. Obscure Drupal-specific implementation. Why does UnitTests extend Drupal?
339 // You should delete this function if the base-classes are properly rearranged.
340 }
6a488035 341}