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