From 66e421424421075eb4e96676cd5414a3c2bb4a8e Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 2 Feb 2015 15:39:15 -0500 Subject: [PATCH] CRM-15903 - Modify CRM_Utils_System_UnitTests to not extend Drupal ---------------------------------------- * CRM-15903: Restructure UF classes so that CRM_Utils_System_UnitTests does not extend Drupal https://issues.civicrm.org/jira/browse/CRM-15903 --- CRM/Core/Module.php | 4 +- CRM/Utils/System/Base.php | 10 ++ CRM/Utils/System/Drupal.php | 15 --- CRM/Utils/System/Drupal6.php | 5 +- CRM/Utils/System/DrupalBase.php | 5 +- CRM/Utils/System/UnitTests.php | 206 +++----------------------------- 6 files changed, 27 insertions(+), 218 deletions(-) diff --git a/CRM/Core/Module.php b/CRM/Core/Module.php index ca379d1751..7ec8c94a5c 100644 --- a/CRM/Core/Module.php +++ b/CRM/Core/Module.php @@ -66,9 +66,7 @@ class CRM_Core_Module { $result[] = new CRM_Core_Module('civicrm', TRUE); // pseudo-module for core $config = CRM_Core_Config::singleton(); - if (is_callable(array($config->userSystem, 'getModules'))) { - $result = array_merge($result, $config->userSystem->getModules()); - } + $result = array_merge($result, $config->userSystem->getModules()); } return $result; } diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 6c32fcfac7..475841d39b 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -647,6 +647,16 @@ abstract class CRM_Utils_System_Base { return $this->getLoggedInUniqueIdentifier(); } + /** + * List modules installed in the CMS, including enabled and disabled ones. + * + * @return array + * [CRM_Core_Module] + */ + public function getModules() { + return array(); + } + /** * Get Url to view user record * @param int $contactID diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 896ec65c7d..5b7c1842be 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -712,21 +712,6 @@ AND u.status = 1 } } - /** - * Get a list of all installed modules, including enabled and disabled ones - * - * @return array - * CRM_Core_Module - */ - public function getModules() { - $result = array(); - $q = db_query('SELECT name, status FROM {system} WHERE type = \'module\' AND schema_version <> -1'); - foreach ($q as $row) { - $result[] = new CRM_Core_Module('drupal.' . $row->name, ($row->status == 1) ? TRUE : FALSE); - } - return $result; - } - /** * Wrapper for og_membership creation * diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 0d172847df..00ca7055f7 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -675,10 +675,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { } /** - * Get a list of all installed modules, including enabled and disabled ones - * - * @return array - * CRM_Core_Module + * @inheritDoc */ public function getModules() { $result = array(); diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index bdf5e512d2..624866bd92 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -295,10 +295,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { } /** - * Get a list of all installed modules, including enabled and disabled ones - * - * @return array - * CRM_Core_Module + * @inheritDoc */ public function getModules() { $result = array(); diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index a2e6a593e9..4805af7ded 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -36,7 +36,7 @@ /** * Helper authentication class for unit tests */ -class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { +class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { /** */ public function __construct() { @@ -45,44 +45,7 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { } /** - * Sets the title of the page - * - * @param string $title - * @param null $pageTitle - * - * @paqram string $pageTitle - * - * @return void - */ - /** - * @param string $title - * @param null $pageTitle - */ - public function setTitle($title, $pageTitle = NULL) { - return NULL; - } - - /** - * Authenticate the user against the drupal db - * - * @param string $name - * The user name. - * @param string $password - * The password for the above user name. - * @param bool $loadCMSBootstrap - * Load cms bootstrap?. - * @param NULL|string $realPath filename of script - * - * @return array|bool - * [contactID, ufID, uniqueString] if success else false if no auth - */ - /** - * @param string $name - * @param string $password - * @param bool $loadCMSBootstrap - * @param null|string $realPath - * - * @return mixed + * @inheritDoc */ public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) { $retVal = array(1, 1, 12345); @@ -90,102 +53,31 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { } /** - * Append an additional breadcrumb tag to the existing breadcrumb - * - * @param $breadCrumbs - * - * @internal param string $title - * @internal param string $url - * - * @return void - */ - /** - * @param $breadCrumbs - */ - public function appendBreadCrumb($breadCrumbs) { - return NULL; - } - - public function resetBreadCrumb() { - return NULL; - } - - /** - * Append a string to the head of the html file - * - * @param string $header - * The new string to be appended. - * - * @return void + * @inheritDoc */ - /** - * @param string $head - */ - public function addHTMLHead($head) { - return NULL; - } - public function mapConfigToSSL() { global $base_url; $base_url = str_replace('http://', 'https://', $base_url); } /** - * Figure out the post url for the form - * - * @param mix $action - * The default action if one is pre-specified. - * - * @return string - * the url to post the form - */ - /** - * @param mix $action - * - * @return void + * @inheritDoc */ public function postURL($action) { return NULL; } /** - * Generate an internal CiviCRM URL (copied from DRUPAL/includes/common.inc#url) - * - * @param string $path - * The path being linked to, such as "civicrm/add". - * @param string $query - * A query string to append to the link. - * @param bool $absolute - * Whether to force the output to be an absolute link (beginning with http:). - * Useful for links that will be displayed outside the site, such as in an - * RSS feed. - * @param string $fragment - * A fragment identifier (named anchor) to append to the link. - * @param bool $htmlize - * whether to convert to html eqivalant. - * @param bool $frontend - * a gross joomla hack. - * @param bool $forceBackend - * a gross joomla hack. - * - * @return string - * an HTML string containing a link to the given path. - */ - /** - * @param null|string $path - * @param null|string $query - * @param bool $absolute - * @param null|string $fragment - * @param bool $htmlize - * @param bool $frontend - * @param bool $forceBackend - * - * @return string + * @inheritDoc */ public function url( - $path = NULL, $query = NULL, $absolute = FALSE, - $fragment = NULL, $htmlize = TRUE, - $frontend = FALSE, $forceBackend = FALSE + $path = NULL, + $query = NULL, + $absolute = FALSE, + $fragment = NULL, + $htmlize = TRUE, + $frontend = FALSE, + $forceBackend = FALSE ) { $config = CRM_Core_Config::singleton(); static $script = 'index.php'; @@ -252,88 +144,18 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Drupal { } /** - * @param $user - * - * @return bool + * @inheritDoc */ - public function getAllowedToLogin($user) { - return TRUE; - } - - /** - * Set a message in the UF to display to a user - * - * @param string $message - * The message to set. - */ - /** - * @param string $message - */ - public function setMessage($message) { - return NULL; - } - - public function permissionDenied() { - CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); - } - public function logout() { session_destroy(); header("Location:index.php"); } /** - * Get the locale set in the hosting CMS - * - * @return string - * with the locale or null for none - */ - /** - * @return void - */ - public function getUFLocale() { - return NULL; - } - - /** - * Get a list of all installed modules, including enabled and disabled ones - * - * @return array - * CRM_Core_Module - */ - /** - * @return array - */ - public function getModules() { - return array(); - } - - /** - * Get user login URL for hosting CMS (method declared in each CMS system class) - * - * @param string $destination - * If present, add destination to querystring (works for Drupal only). - * - * @Throws Exception - * loginURL for the current CMS + * @inheritDoc */ public function getLoginURL($destination = '') { throw new Exception("Method not implemented: getLoginURL"); } - /** - * Over-ridable function to get timezone as a string eg. - * @return string - * Timezone e.g. 'America/Los_Angeles' - */ - public function getTimeZoneString() { - // This class extends Drupal, but we don't want Drupal's behavior; reproduce CRM_Utils_System_Base::getTimeZoneString - return date_default_timezone_get(); - } - - public function clearResourceCache() { - // UGH. Obscure Drupal-specific implementation. Why does UnitTests extend Drupal? - // You should delete this function if the base-classes are properly rearranged. - } - } -- 2.25.1