Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Helper authentication class for unit tests | |
20 | */ | |
66e42142 | 21 | class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { |
6714d8d2 | 22 | |
bb3a214a | 23 | /** |
bb3a214a | 24 | */ |
00be9182 | 25 | public function __construct() { |
6a488035 | 26 | $this->is_drupal = FALSE; |
e7292422 | 27 | $this->supports_form_extensions = FALSE; |
6a488035 TO |
28 | } |
29 | ||
df2b1bc5 TO |
30 | public function initialize() { |
31 | parent::initialize(); | |
32 | $test = $GLOBALS['CIVICRM_TEST_CASE'] ?? NULL; | |
33 | if ($test && $test instanceof \Civi\Test\HeadlessInterface) { | |
34 | $listenerMap = \Civi\Core\Event\EventScanner::findListeners($test); | |
35 | \Civi::dispatcher()->addListenerMap($test, $listenerMap); | |
36 | } | |
37 | } | |
38 | ||
103ae50e | 39 | /** |
40 | * @param string $name | |
41 | * @param string $value | |
42 | */ | |
43 | public function setHttpHeader($name, $value) { | |
44 | Civi::$statics[__CLASS__]['header'][] = ("$name: $value"); | |
45 | } | |
46 | ||
bb3a214a | 47 | /** |
66e42142 | 48 | * @inheritDoc |
bb3a214a | 49 | */ |
17f443df | 50 | public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { |
be2fb01f | 51 | $retVal = [1, 1, 12345]; |
6a488035 TO |
52 | return $retVal; |
53 | } | |
54 | ||
dc1e9be8 TO |
55 | /** |
56 | * Bootstrap the phony CMS. | |
dc1e9be8 | 57 | */ |
be2fb01f | 58 | public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { |
dc1e9be8 TO |
59 | return TRUE; |
60 | } | |
61 | ||
bb3a214a | 62 | /** |
66e42142 | 63 | * @inheritDoc |
bb3a214a | 64 | */ |
00be9182 | 65 | public function mapConfigToSSL() { |
6a488035 TO |
66 | global $base_url; |
67 | $base_url = str_replace('http://', 'https://', $base_url); | |
68 | } | |
69 | ||
bb3a214a | 70 | /** |
66e42142 | 71 | * @inheritDoc |
bb3a214a | 72 | */ |
00be9182 | 73 | public function postURL($action) { |
c301f76e | 74 | return NULL; |
6a488035 TO |
75 | } |
76 | ||
bb3a214a | 77 | /** |
66e42142 | 78 | * @inheritDoc |
bb3a214a | 79 | */ |
c301f76e | 80 | public function url( |
66e42142 CW |
81 | $path = NULL, |
82 | $query = NULL, | |
83 | $absolute = FALSE, | |
84 | $fragment = NULL, | |
66e42142 | 85 | $frontend = FALSE, |
8de2a34e SL |
86 | $forceBackend = FALSE, |
87 | $htmlize = TRUE | |
6a488035 TO |
88 | ) { |
89 | $config = CRM_Core_Config::singleton(); | |
90 | static $script = 'index.php'; | |
91 | ||
92 | if (isset($fragment)) { | |
93 | $fragment = '#' . $fragment; | |
94 | } | |
95 | ||
96 | if (!isset($config->useFrameworkRelativeBase)) { | |
97 | $base = parse_url($config->userFrameworkBaseURL); | |
98 | $config->useFrameworkRelativeBase = $base['path']; | |
99 | } | |
100 | $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase; | |
101 | ||
100b381f | 102 | $separator = ($htmlize && $frontend) ? '&' : '&'; |
6a488035 TO |
103 | |
104 | if (!$config->cleanURL) { | |
105 | if (isset($path)) { | |
106 | if (isset($query)) { | |
107 | return $base . $script . '?q=' . $path . $separator . $query . $fragment; | |
108 | } | |
109 | else { | |
110 | return $base . $script . '?q=' . $path . $fragment; | |
111 | } | |
112 | } | |
113 | else { | |
114 | if (isset($query)) { | |
115 | return $base . $script . '?' . $query . $fragment; | |
116 | } | |
117 | else { | |
118 | return $base . $fragment; | |
119 | } | |
120 | } | |
121 | } | |
122 | else { | |
123 | if (isset($path)) { | |
124 | if (isset($query)) { | |
125 | return $base . $path . '?' . $query . $fragment; | |
126 | } | |
127 | else { | |
128 | return $base . $path . $fragment; | |
129 | } | |
130 | } | |
131 | else { | |
132 | if (isset($query)) { | |
133 | return $base . $script . '?' . $query . $fragment; | |
134 | } | |
135 | else { | |
136 | return $base . $fragment; | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
bb3a214a EM |
142 | /** |
143 | * @param $user | |
144 | */ | |
00be9182 | 145 | public function getUserID($user) { |
6a488035 TO |
146 | //FIXME: look here a bit closer when testing UFMatch |
147 | ||
148 | // this puts the appropriate values in the session, so | |
149 | // no need to return anything | |
150 | CRM_Core_BAO_UFMatch::synchronize($user, TRUE, 'Standalone', 'Individual'); | |
151 | } | |
152 | ||
bb3a214a | 153 | /** |
66e42142 | 154 | * @inheritDoc |
bb3a214a | 155 | */ |
00be9182 | 156 | public function logout() { |
6a488035 | 157 | session_destroy(); |
d42a224c | 158 | CRM_Utils_System::setHttpHeader("Location", "index.php"); |
6a488035 TO |
159 | } |
160 | ||
bb3a214a | 161 | /** |
66e42142 | 162 | * @inheritDoc |
6a488035 TO |
163 | */ |
164 | public function getLoginURL($destination = '') { | |
165 | throw new Exception("Method not implemented: getLoginURL"); | |
166 | } | |
450f494d | 167 | |
6a488035 | 168 | } |