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