Merge pull request #15968 from eileenmcnaughton/bom
[civicrm-core.git] / CRM / Utils / System / UnitTests.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * Helper authentication class for unit tests
22 */
23 class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base {
24
25 /**
26 */
27 public function __construct() {
28 $this->is_drupal = FALSE;
29 $this->supports_form_extensions = FALSE;
30 }
31
32 /**
33 * @param string $name
34 * @param string $value
35 */
36 public function setHttpHeader($name, $value) {
37 Civi::$statics[__CLASS__]['header'][] = ("$name: $value");
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
44 $retVal = [1, 1, 12345];
45 return $retVal;
46 }
47
48 /**
49 * Bootstrap the phony CMS.
50 */
51 public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
52 return TRUE;
53 }
54
55 /**
56 * @inheritDoc
57 */
58 public function mapConfigToSSL() {
59 global $base_url;
60 $base_url = str_replace('http://', 'https://', $base_url);
61 }
62
63 /**
64 * @inheritDoc
65 */
66 public function postURL($action) {
67 return NULL;
68 }
69
70 /**
71 * @inheritDoc
72 */
73 public function url(
74 $path = NULL,
75 $query = NULL,
76 $absolute = FALSE,
77 $fragment = NULL,
78 $htmlize = TRUE,
79 $frontend = FALSE,
80 $forceBackend = FALSE
81 ) {
82 $config = CRM_Core_Config::singleton();
83 static $script = 'index.php';
84
85 if (isset($fragment)) {
86 $fragment = '#' . $fragment;
87 }
88
89 if (!isset($config->useFrameworkRelativeBase)) {
90 $base = parse_url($config->userFrameworkBaseURL);
91 $config->useFrameworkRelativeBase = $base['path'];
92 }
93 $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase;
94
95 $separator = $htmlize ? '&amp;' : '&';
96
97 if (!$config->cleanURL) {
98 if (isset($path)) {
99 if (isset($query)) {
100 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
101 }
102 else {
103 return $base . $script . '?q=' . $path . $fragment;
104 }
105 }
106 else {
107 if (isset($query)) {
108 return $base . $script . '?' . $query . $fragment;
109 }
110 else {
111 return $base . $fragment;
112 }
113 }
114 }
115 else {
116 if (isset($path)) {
117 if (isset($query)) {
118 return $base . $path . '?' . $query . $fragment;
119 }
120 else {
121 return $base . $path . $fragment;
122 }
123 }
124 else {
125 if (isset($query)) {
126 return $base . $script . '?' . $query . $fragment;
127 }
128 else {
129 return $base . $fragment;
130 }
131 }
132 }
133 }
134
135 /**
136 * @param $user
137 */
138 public function getUserID($user) {
139 //FIXME: look here a bit closer when testing UFMatch
140
141 // this puts the appropriate values in the session, so
142 // no need to return anything
143 CRM_Core_BAO_UFMatch::synchronize($user, TRUE, 'Standalone', 'Individual');
144 }
145
146 /**
147 * @inheritDoc
148 */
149 public function logout() {
150 session_destroy();
151 CRM_Utils_System::setHttpHeader("Location", "index.php");
152 }
153
154 /**
155 * @inheritDoc
156 */
157 public function getLoginURL($destination = '') {
158 throw new Exception("Method not implemented: getLoginURL");
159 }
160
161 }