Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Test fixes #433

Merged
merged 4 commits into from

2 participants

@eddieajau

Fixes invalid file name in JAccess tests, and check style errors in JError.

@LouisLandry LouisLandry merged commit 1325de6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 16, 2011
  1. @LouisLandry
Commits on Oct 17, 2011
  1. @LouisLandry

    Normalizing the dataset stub for JAccess and making it possible to clear

    LouisLandry authored
    class static caches for testing purposes.
Commits on Oct 18, 2011
  1. @eddieajau
  2. @eddieajau
This page is out of date. Refresh to see the latest.
View
68 libraries/joomla/access/access.php
@@ -38,6 +38,46 @@ class JAccess
protected static $assetRules = array();
/**
+ * Array of user groups.
+ *
+ * @var array
+ * @since 11.1
+ */
+ protected static $userGroups = array();
+
+ /**
+ * Array of user group paths.
+ *
+ * @var array
+ * @since 11.1
+ */
+ protected static $userGroupPaths = array();
+
+ /**
+ * Array of cached groups by user.
+ *
+ * @var array
+ * @since 11.1
+ */
+ protected static $groupsByUser = array();
+
+ /**
+ * Method for clearing static caches.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public static function clearStatics()
+ {
+ self::$viewLevels = array();
+ self::$assetRules = array();
+ self::$userGroups = array();
+ self::$userGroupPaths = array();
+ self::$groupsByUser = array();
+ }
+
+ /**
* Method to check if a user is authorised to perform an action, optionally on an asset.
*
* @param integer $userId Id of the user for which to check authorisation.
@@ -123,10 +163,8 @@ public static function checkGroup($groupId, $action, $asset = null)
*/
protected static function getGroupPath($groupId)
{
- static $groups, $paths;
-
// Preload all groups
- if (empty($groups))
+ if (empty(self::$userGroups))
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
@@ -134,30 +172,30 @@ protected static function getGroupPath($groupId)
->from('#__usergroups AS parent')
->order('parent.lft');
$db->setQuery($query);
- $groups = $db->loadObjectList('id');
+ self::$userGroups = $db->loadObjectList('id');
}
// Make sure groupId is valid
- if (!array_key_exists($groupId, $groups))
+ if (!array_key_exists($groupId, self::$userGroups))
{
return array();
}
// Get parent groups and leaf group
- if (!isset($paths[$groupId]))
+ if (!isset(self::$userGroupPaths[$groupId]))
{
- $paths[$groupId] = array();
+ self::$userGroupPaths[$groupId] = array();
- foreach ($groups as $group)
+ foreach (self::$userGroups as $group)
{
- if ($group->lft <= $groups[$groupId]->lft && $group->rgt >= $groups[$groupId]->rgt)
+ if ($group->lft <= self::$userGroups[$groupId]->lft && $group->rgt >= self::$userGroups[$groupId]->rgt)
{
- $paths[$groupId][] = $group->id;
+ self::$userGroupPaths[$groupId][] = $group->id;
}
}
}
- return $paths[$groupId];
+ return self::$userGroupPaths[$groupId];
}
/**
@@ -235,12 +273,10 @@ public static function getAssetRules($asset, $recursive = false)
*/
public static function getGroupsByUser($userId, $recursive = true)
{
- static $results = array();
-
// Creates a simple unique string for each parameter combination:
$storeId = $userId . ':' . (int) $recursive;
- if (!isset($results[$storeId]))
+ if (!isset(self::$groupsByUser[$storeId]))
{
// Guest user
if (empty($userId))
@@ -282,10 +318,10 @@ public static function getGroupsByUser($userId, $recursive = true)
}
}
- $results[$storeId] = $result;
+ self::$groupsByUser[$storeId] = $result;
}
- return $results[$storeId];
+ return self::$groupsByUser[$storeId];
}
/**
View
2  libraries/joomla/database/table/extension.php
@@ -9,6 +9,8 @@
defined('JPATH_PLATFORM') or die();
+jimport('joomla.database.table');
+
/**
* Extension table
* Replaces plugins table
View
2  libraries/joomla/error/error.php
@@ -549,7 +549,7 @@ public static function handleEcho(&$error, $options)
{
$backtrace = $error->getTrace();
$trace = '';
- for( $i = count( $backtrace )-1; $i >= 0 ; $i-- )
+ for ($i = count($backtrace) - 1; $i >= 0 ; $i--)
{
if (isset($backtrace[$i]['class']))
{
View
10 tests/bootstrap.php
@@ -44,23 +44,23 @@
}
if (!defined('JPATH_CACHE'))
{
- define('JPATH_CACHE', realpath(JPATH_BASE . '/cache'));
+ define('JPATH_CACHE', JPATH_BASE . '/cache');
}
if (!defined('JPATH_CONFIGURATION'))
{
- define('JPATH_CONFIGURATION', realpath(JPATH_BASE));
+ define('JPATH_CONFIGURATION', JPATH_BASE);
}
if (!defined('JPATH_MANIFESTS'))
{
- define('JPATH_MANIFESTS', realpath(JPATH_BASE . '/manifests'));
+ define('JPATH_MANIFESTS', JPATH_BASE . '/manifests');
}
if (!defined('JPATH_PLUGINS'))
{
- define('JPATH_PLUGINS', realpath(JPATH_BASE . '/plugins'));
+ define('JPATH_PLUGINS', JPATH_BASE . '/plugins');
}
if (!defined('JPATH_THEMES'))
{
- define('JPATH_THEMES', realpath(JPATH_BASE . '/themes'));
+ define('JPATH_THEMES', JPATH_BASE . '/themes');
}
// Load a configuration file for the tests.
View
5 tests/suite/joomla/access/JAccessTest.php
@@ -31,6 +31,9 @@ protected function setUp()
{
parent::setUp();
+ // Clear the static caches.
+ JAccess::clearStatics();
+
$this->object = new JAccess;
}
@@ -43,7 +46,7 @@ protected function setUp()
*/
protected function getDataSet()
{
- return $this->createXMLDataSet(__DIR__.'/JAccessTest.xml');
+ return $this->createXMLDataSet(__DIR__.'/stubs/S01.xml');
}
/**
View
0  tests/suite/joomla/access/JAccessTest.xml → tests/suite/joomla/access/stubs/S01.xml
File renamed without changes
Something went wrong with that request. Please try again.