Merge pull request #17361 from jaapjansma/dev-1767
[civicrm-core.git] / CRM / Utils / System / UnitTests.php
CommitLineData
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 21class 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
103ae50e 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
bb3a214a 38 /**
66e42142 39 * @inheritDoc
bb3a214a 40 */
17f443df 41 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
be2fb01f 42 $retVal = [1, 1, 12345];
6a488035
TO
43 return $retVal;
44 }
45
dc1e9be8
TO
46 /**
47 * Bootstrap the phony CMS.
dc1e9be8 48 */
be2fb01f 49 public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
dc1e9be8
TO
50 return TRUE;
51 }
52
bb3a214a 53 /**
66e42142 54 * @inheritDoc
bb3a214a 55 */
00be9182 56 public function mapConfigToSSL() {
6a488035
TO
57 global $base_url;
58 $base_url = str_replace('http://', 'https://', $base_url);
59 }
60
bb3a214a 61 /**
66e42142 62 * @inheritDoc
bb3a214a 63 */
00be9182 64 public function postURL($action) {
c301f76e 65 return NULL;
6a488035
TO
66 }
67
bb3a214a 68 /**
66e42142 69 * @inheritDoc
bb3a214a 70 */
c301f76e 71 public function url(
66e42142
CW
72 $path = NULL,
73 $query = NULL,
74 $absolute = FALSE,
75 $fragment = NULL,
66e42142 76 $frontend = FALSE,
8de2a34e
SL
77 $forceBackend = FALSE,
78 $htmlize = TRUE
6a488035
TO
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
100b381f 93 $separator = ($htmlize && $frontend) ? '&amp;' : '&';
6a488035
TO
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
bb3a214a
EM
133 /**
134 * @param $user
135 */
00be9182 136 public function getUserID($user) {
6a488035
TO
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
bb3a214a 144 /**
66e42142 145 * @inheritDoc
bb3a214a 146 */
00be9182 147 public function logout() {
6a488035 148 session_destroy();
d42a224c 149 CRM_Utils_System::setHttpHeader("Location", "index.php");
6a488035
TO
150 }
151
bb3a214a 152 /**
66e42142 153 * @inheritDoc
6a488035
TO
154 */
155 public function getLoginURL($destination = '') {
156 throw new Exception("Method not implemented: getLoginURL");
157 }
450f494d 158
6a488035 159}