Merge pull request #15144 from JKingsnorth/copying-events-contribution-pages
[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 * @param string $name
50 * @param string $value
51 */
52 public function setHttpHeader($name, $value) {
53 Civi::$statics[__CLASS__]['header'][] = ("$name: $value");
54 }
55
56 /**
57 * @inheritDoc
58 */
59 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
60 $retVal = [1, 1, 12345];
61 return $retVal;
62 }
63
64 /**
65 * Bootstrap the phony CMS.
66 */
67 public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
68 return TRUE;
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public function mapConfigToSSL() {
75 global $base_url;
76 $base_url = str_replace('http://', 'https://', $base_url);
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function postURL($action) {
83 return NULL;
84 }
85
86 /**
87 * @inheritDoc
88 */
89 public function url(
90 $path = NULL,
91 $query = NULL,
92 $absolute = FALSE,
93 $fragment = NULL,
94 $htmlize = TRUE,
95 $frontend = FALSE,
96 $forceBackend = FALSE
97 ) {
98 $config = CRM_Core_Config::singleton();
99 static $script = 'index.php';
100
101 if (isset($fragment)) {
102 $fragment = '#' . $fragment;
103 }
104
105 if (!isset($config->useFrameworkRelativeBase)) {
106 $base = parse_url($config->userFrameworkBaseURL);
107 $config->useFrameworkRelativeBase = $base['path'];
108 }
109 $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase;
110
111 $separator = $htmlize ? '&amp;' : '&';
112
113 if (!$config->cleanURL) {
114 if (isset($path)) {
115 if (isset($query)) {
116 return $base . $script . '?q=' . $path . $separator . $query . $fragment;
117 }
118 else {
119 return $base . $script . '?q=' . $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 else {
132 if (isset($path)) {
133 if (isset($query)) {
134 return $base . $path . '?' . $query . $fragment;
135 }
136 else {
137 return $base . $path . $fragment;
138 }
139 }
140 else {
141 if (isset($query)) {
142 return $base . $script . '?' . $query . $fragment;
143 }
144 else {
145 return $base . $fragment;
146 }
147 }
148 }
149 }
150
151 /**
152 * @param $user
153 */
154 public function getUserID($user) {
155 //FIXME: look here a bit closer when testing UFMatch
156
157 // this puts the appropriate values in the session, so
158 // no need to return anything
159 CRM_Core_BAO_UFMatch::synchronize($user, TRUE, 'Standalone', 'Individual');
160 }
161
162 /**
163 * @inheritDoc
164 */
165 public function logout() {
166 session_destroy();
167 CRM_Utils_System::setHttpHeader("Location", "index.php");
168 }
169
170 /**
171 * @inheritDoc
172 */
173 public function getLoginURL($destination = '') {
174 throw new Exception("Method not implemented: getLoginURL");
175 }
176
177 }