Merge pull request #4812 from colemanw/CRM-15495
[civicrm-core.git] / CRM / Utils / System / UnitTests.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public 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 */
58 /**
59 * @param string $title
60 * @param null $pageTitle
61 */
62 public function setTitle($title, $pageTitle = NULL) {
63 return;
64 }
65
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
77 */
78 /**
79 * @param string $name
80 * @param string $password
81 * @param bool $loadCMSBootstrap
82 * @param null|string $realPath
83 *
84 * @return mixed
85 */
86 public static function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
87 $retVal = array(1, 1, 12345);
88 return $retVal;
89 }
90
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
100 */
101 /**
102 * @param $breadCrumbs
103 */
104 public function appendBreadCrumb($breadCrumbs) {
105 return;
106 }
107
108 public function resetBreadCrumb() {
109 return;
110 }
111
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
118 */
119 /**
120 * @param string $head
121 */
122 public function addHTMLHead($head) {
123 return;
124 }
125
126 public function mapConfigToSSL() {
127 global $base_url;
128 $base_url = str_replace('http://', 'https://', $base_url);
129 }
130
131 /**
132 * Figure out the post url for the form
133 *
134 * @param mix $action the default action if one is pre-specified
135 *
136 * @return string the url to post the form
137 */
138 /**
139 * @param mix $action
140 *
141 * @return string
142 */
143 public function postURL($action) {
144 return;
145 }
146
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.
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 */
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 ? '&amp;' : '&';
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
231 /**
232 * @param $user
233 */
234 public function getUserID($user) {
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
242 /**
243 * @param $user
244 *
245 * @return bool
246 */
247 public function getAllowedToLogin($user) {
248 return TRUE;
249 }
250
251 /**
252 * Set a message in the UF to display to a user
253 *
254 * @param string $message the message to set
255 *
256 */
257 /**
258 * @param string $message
259 */
260 public function setMessage($message) {
261 return;
262 }
263
264 public function permissionDenied() {
265 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
266 }
267
268 public function logout() {
269 session_destroy();
270 header("Location:index.php");
271 }
272
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 */
281 public function getUFLocale() {
282 return NULL;
283 }
284
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 */
293 public function getModules() {
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 *
302 * @throws Exception
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 }
309
310 /**
311 * Over-ridable function to get timezone as a string eg.
312 * @return string Timezone e.g. 'America/Los_Angeles'
313 */
314 public function getTimeZoneString() {
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 }
318
319 public function clearResourceCache() {
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 }
323 }