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