* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Stub_Registry
{
/**
* A flag that is set once the basic horde application has been
* minimally configured.
*
* @var boolean
*/
public $hordeInit = false;
/**
* The currrent user.
*
* @var string
*/
private $_user;
/**
* The current application.
*
* @var string
*/
private $_app;
/**
* Constructor.
*
* @param string $user The current user.
* @param string $app The current application.
*/
public function __construct($user, $app)
{
$this->_user = $user;
$this->_app = $app;
}
/**
* Returns the currently logged in user, if there is one.
*
* @param string $format The return format, defaults to the unique Horde
* ID. Alternative formats:
*
* bare - Horde ID without any domain information.
* EXAMPLE: foo@example.com would be returned as 'foo'.
* domain: Domain of the Horde ID.
* EXAMPLE: foo@example.com would be returned as 'example.com'.
* original: The username used to originally login to Horde.
*
*
* @return mixed The user ID or false if no user is logged in.
*/
public function getAuth($format = null)
{
return $this->_user;
}
/**
* Is a user an administrator?
*
* @param array $options Options:
*
* 'permission' - (string) Allow users with this permission admin access
* in the current context.
* 'permlevel' - (integer) The level of permissions to check for.
* Defaults to Horde_Perms::EDIT.
* 'user' - (string) The user to check.
* Defaults to self::getAuth().
*
*
* @return boolean Whether or not this is an admin user.
*/
public function isAdmin(array $options = array())
{
return false;
}
/**
* Return the requested configuration parameter for the specified
* application. If no application is specified, the value of
* the current application is used. However, if the parameter is not
* present for that application, the Horde-wide value is used instead.
* If that is not present, we return null.
*
* @param string $parameter The configuration value to retrieve.
* @param string $app The application to get the value for.
*
* @return string The requested parameter, or null if it is not set.
*/
public function get($parameter, $app = null)
{
return '';
}
/**
* Return the current application - the app at the top of the application
* stack.
*
* @return string The current application.
*/
public function getApp()
{
return $this->_app;
}
/**
* Determine if an interface is implemented by an active application.
*
* @param string $interface The interface to check for.
*
* @return mixed The application implementing $interface if we have it,
* false if the interface is not implemented.
*/
public function hasInterface($interface)
{
return false;
}
/**
* Returns all available registry APIs.
*
* @return array The API list.
*/
public function listAPIs()
{
return array();
}
}
Horde_Test-2.2.6/lib/Horde/Test/AllTests.php 0000664 0001750 0001750 00000011700 12250351701 016652 0 ustar jan jan
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
require_once 'PHPUnit/Autoload.php';
/**
* Horde base test suite
*
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Jan Schneider
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_AllTests
{
private $_dir;
private $_package;
/**
* Create a Horde_Test_AllTests object.
*
* @param string $file Filename of the AllTests.php script.
*
* @return Horde_Test_AllTests Test object.
*/
static public function init($file)
{
$file = dirname($file);
$parts = array();
foreach (array_reverse(explode(DIRECTORY_SEPARATOR, $file)) as $val) {
if ($val == 'test' ||
$val == implode('_', array_reverse($parts))) {
break;
}
$parts[] = $val;
}
return new self(
implode('_', array_reverse($parts)),
$file
);
}
/**
* Constructor.
*
* @param string $package The name of the package tested by this suite.
* @param string $dir The path of the AllTests class.
*/
public function __construct($package, $dir)
{
$this->_package = $package;
$this->_dir = $dir;
}
/**
* Main entry point for running the suite.
*
* @return boolean
*/
public function run()
{
$old_dir = getcwd();
chdir($this->_dir);
$old_error = error_reporting();
$result = PHPUnit_TextUI_TestRunner::run($this->suite());
error_reporting($old_error);
chdir($old_dir);
return $result;
}
/**
* Collect the unit tests of this directory into a new suite.
*
* @return PHPUnit_Framework_TestSuite The test suite.
*/
public function suite()
{
$this->setup();
$suite = new PHPUnit_Framework_TestSuite('Horde Framework - ' . $this->_package);
$baseregexp = preg_quote($this->_dir . DIRECTORY_SEPARATOR, '/');
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->_dir)) as $file) {
if ($file->isFile()) {
$pathname = $file->getPathname();
if ((preg_match('/Test.php$/', $file->getFilename())) &&
(include $pathname)) {
$class = str_replace(
DIRECTORY_SEPARATOR, '_',
preg_replace("/^$baseregexp(.*)\.php/", '\\1', $pathname));
try {
$suite->addTestSuite($this->_package . '_' . $class);
} catch (InvalidArgumentException $e) {
throw new Horde_Test_Exception(
sprintf(
'Failed adding test suite "%s" from file "%s": %s',
$this->_package . '_' . $class,
$pathname,
$e->getMessage()
)
);
}
}
}
}
return $suite;
}
/**
* Basic test suite setup. This includes error checking and autoloading.
*
* In the default situation this will set the error reporting to E_ALL |
* E_STRICT and pull in Horde/Test/Autoload.php as autoloading
* definition. If there is an Autoload.php in $_dir, then only this file
* will be used.
*
* In addition the setup() call will attempt to detect the "lib" directory
* of the component currently under test and add it to the
* include_path. This ensures that the component code from the checkout is
* preferred over whatever else might be available in the default
* include_path.
*/
public function setup()
{
// Detect component root and add "lib" and "test" to the include path.
$base = $this->_dir;
while ($base != '/' && basename($base) != 'test') {
$base = dirname($base);
}
if ($base) {
set_include_path(
$base . PATH_SEPARATOR . $base . '/../lib' . PATH_SEPARATOR . get_include_path()
);
}
require_once 'Horde/Test/Bootstrap.php';
Horde_Test_Bootstrap::bootstrap($this->_dir);
if (file_exists($this->_dir . '/Autoload.php')) {
require_once $this->_dir . '/Autoload.php';
}
}
}
Horde_Test-2.2.6/lib/Horde/Test/Autoload.php 0000664 0001750 0001750 00000004351 12250351701 016673 0 ustar jan jan
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Autoload
{
/**
* Prefix mappings.
*
* @var array
*/
private static $_mappings = array();
/**
* Only run init code once.
*
* @var boolean
*/
private static $_runonce = false;
/**
* Base autoloader code for Horde PEAR packages.
*/
public static function init()
{
if (self::$_runonce) {
return;
}
spl_autoload_register(
function($class) {
$filename = Horde_Test_Autoload::resolve($class);
$err_mask = error_reporting() & ~E_WARNING;
$old_err = error_reporting($err_mask);
include "$filename.php";
error_reporting($old_err);
}
);
self::$_runonce = true;
}
/**
* Add a prefix to the autoloader.
*
* @param string $prefix Prefix to add.
* @param string $path Path to the prefix.
*/
public static function addPrefix($prefix, $path)
{
self::$_mappings[$prefix] = $path;
}
/**
* Resolve classname to a filename.
*
* @param string $class Class name.
*
* @return string Resolved filename.
*/
public static function resolve($class)
{
$filename = str_replace(array('::', '_', '\\'), '/', $class);
foreach (self::$_mappings as $prefix => $path) {
if ((strpos($filename, "/") === false) && ($filename == $prefix)) {
$filename = $path . '/' . $filename;
}
if (substr($filename, 0, strlen($prefix)) == $prefix) {
$filename = $path . substr($filename, strlen($prefix));
}
}
return $filename;
}
}
Horde_Test-2.2.6/lib/Horde/Test/Bootstrap.php 0000664 0001750 0001750 00000003343 12250351701 017100 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
* @package Test
*/
class Horde_Test_Bootstrap
{
/**
* Only run bootstrap code once.
*
* @var boolean
*/
private static $_runonce = false;
/**
* Bootstrap code for Horde PEAR packages.
*
* @param string $dir Base directory of tests.
* @param boolean $no_autoload Don't run default Horde_Test autoload
* tasks.
*/
static public function bootstrap($dir, $no_autoload = false)
{
if (self::$_runonce) {
return;
}
if (!$no_autoload) {
// Catch strict standards
error_reporting(E_ALL | E_STRICT);
// Set up autoload
$base = $dir;
while ($base != '/' && basename($base) != 'Horde') {
$base = dirname($base);
}
$base = dirname($base);
if ($base) {
set_include_path(
$base . PATH_SEPARATOR . $base . '/../lib' . PATH_SEPARATOR . get_include_path()
);
}
require_once 'Horde/Test/Autoload.php';
Horde_Test_Autoload::init();
}
if (file_exists($dir . '/Autoload.php')) {
require_once $dir . '/Autoload.php';
}
self::$_runonce = true;
}
}
Horde_Test-2.2.6/lib/Horde/Test/Case.php 0000664 0001750 0001750 00000005272 12250351701 016001 0 ustar jan jan
* @author Jan Schneider
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
/**
* Basic Horde test case helper.
*
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Chuck Hagenbuch
* @author Jan Schneider
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Case extends PHPUnit_Framework_TestCase
{
/**
* Useful shorthand if you are mocking a class with a private constructor
*/
public function getMockSkipConstructor($className, array $methods = array(), array $arguments = array(), $mockClassName = '')
{
return $this->getMock($className, $methods, $arguments, $mockClassName, /* $callOriginalConstructor */ false);
}
/**
* Helper method for loading test configuration from a file.
*
* The configuration can be specified by an environment variable. If the
* variable content is a file name, the configuration is loaded from the
* file. Otherwise it's assumed to be a json encoded configuration hash. If
* the environment variable is not set, the method tries to load a conf.php
* file from the same directory as the test case.
*
* @param string $env An environment variable name.
* @param string $path The path to use.
* @param array $default Some default values that are merged into the
* configuration if specified as a json hash.
*
* @return mixed The value of the configuration file's $conf variable, or
* null.
*/
static public function getConfig($env, $path = null, $default = array())
{
$config = getenv($env);
if ($config) {
$json = json_decode($config, true);
if ($json) {
return array_replace_recursive($default, $json);
}
} else {
if (!$path) {
$backtrace = new Horde_Support_Backtrace();
$caller = $backtrace->getCurrentContext();
$path = dirname($caller['file']);
}
$config = $path . '/conf.php';
}
if (file_exists($config)) {
require $config;
return $conf;
}
return null;
}
}
Horde_Test-2.2.6/lib/Horde/Test/Exception.php 0000664 0001750 0001750 00000001431 12250351701 017055 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
/**
* The exception specific to this package.
*
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Exception extends Horde_Exception_Wrapped
{
}
Horde_Test-2.2.6/lib/Horde/Test/Functional.php 0000664 0001750 0001750 00000003210 12250351701 017216 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
/**
* Horde test case helper.
*
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Functional extends Horde_Test_Case
{
/**
* Test two XML strings for equivalency (e.g., identical up to reordering of
* attributes).
*/
public function assertDomEquals($expected, $actual, $message = null)
{
$expectedDom = new DOMDocument();
$expectedDom->loadXML($expected);
$actualDom = new DOMDocument();
$actualDom->loadXML($actual);
$this->assertEquals($expectedDom->saveXML(), $actualDom->saveXML(), $message);
}
/**
* Test two HTML strings for equivalency (e.g., identical up to reordering
* of attributes).
*/
public function assertHtmlDomEquals($expected, $actual, $message = null)
{
$expectedDom = new DOMDocument();
$expectedDom->loadHTML($expected);
$actualDom = new DOMDocument();
$actualDom->loadHTML($actual);
$this->assertEquals($expectedDom->saveHTML(), $actualDom->saveHTML(), $message);
}
}
Horde_Test-2.2.6/lib/Horde/Test/Log.php 0000664 0001750 0001750 00000007106 12250351701 015645 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
/**
* Provides utilities to test for log output.
*
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Log extends Horde_Test_Case
{
/**
* The log handler.
*
* @var Horde_Log_Handler_Base
*/
private $_logHandler;
/**
* Returns a log handler.
*
* @return Horde_Log_Logger
*/
public function getLogger()
{
if (!class_exists('Horde_Log_Logger')) {
$this->markTestSkipped('The "Horde_Log" package is missing!');
}
$this->_logHandler = new Horde_Log_Handler_Mock();
return new Horde_Log_Logger($this->_logHandler);
}
/**
* Asserts that the log contains the given number of messages.
*
* You *MUST* fetch the logger via $this->getLogger() before using this
* method. This will store a reference to an internal mock log handler that
* will later be used to analyze the log events.
*
* @param int $count The expected number of messages.
*
* @return Horde_Log_Logger
*/
public function assertLogCount($count)
{
$this->assertEquals(count($this->_logHandler->events), $count);
}
/**
* Asserts that the log contains at least one message matching the provided string.
*
* You *MUST* fetch the logger via $this->getLogger() before using this
* method. This will store a reference to an internal mock log handler that
* will later be used to analyze the log events.
*
* @param string $message The expected log message.
*
* @return Horde_Log_Logger
*/
public function assertLogContains($message)
{
$messages = array();
$found = false;
foreach ($this->_logHandler->events as $event) {
if (strstr($event['message'], $message) !== false) {
$found = true;
break;
}
$messages[] = $event['message'];
}
$this->assertTrue($found, sprintf("Did not find \"%s\" in [\n%s\n]", $message, join("\n", $messages)));
}
/**
* Asserts that the log contains at least one message matching the provided regular_expression.
*
* You *MUST* fetch the logger via $this->getLogger() before using this
* method. This will store a reference to an internal mock log handler that
* will later be used to analyze the log events.
*
* @param string $regular_expression The expected regular expression.
*
* @return Horde_Log_Logger
*/
public function assertLogRegExp($regular_expression)
{
$messages = array();
$found = false;
foreach ($this->_logHandler->events as $event) {
if (preg_match($regular_expression, $event['message'], $matches) !== false) {
$found = true;
break;
}
$messages[] = $event['message'];
}
$this->assertTrue($found, sprintf("Did not find \"%s\" in [\n%s\n]", $message, join("\n", $messages)));
}
}
Horde_Test-2.2.6/lib/Horde/Test/Setup.php 0000664 0001750 0001750 00000013501 12250351701 016220 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
/**
* A test helper for generating complex test setups.
*
* Copyright 2011-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Test
* @author Gunnar Wrobel
* @license http://www.horde.org/licenses/lgpl21 LGPL
* @link http://www.horde.org/components/Horde_Test
*/
class Horde_Test_Setup
{
/**
* The Horde_Injector instance which serves as our service container.
*
* @var Horde_Injector
*/
private $_injector;
/**
* In case the setup turns out to be unfullfillable this should contain an
* appropriate message indicating the problem.
*
* @var string
*/
private $_error;
/**
* Global parameters that apply to several factories.
*
* @var string
*/
private $_params = array();
/**
* Constructor.
*/
public function __construct()
{
if (class_exists('Horde_Injector')) {
$this->_injector = new Horde_Injector(new Horde_Injector_TopLevel());
$this->_injector->setInstance('Horde_Injector', $this->_injector);
} else {
$this->_error = 'The Horde_Injector class is unavailable!';
}
}
/**
* Add a new set of elements to the service container.
*
* @param array $params All parameters necessary for creating the services.
* The keys of the array elements define the name that
* will be used for registering the test service with
* the injector. The element values are a
* configuration array with the following elements:
*
* 'factory' - (string) Name of the factory. Can be a full class name or an
* abbreviated name that will get prepended with
* 'Horde_Test_Factory_'
* 'method' - (string) Method name that will be invoked on the above factory
* to generate the test service.
* 'params' - (array) Any parameters the factory method might require for
* generating the test service. See the various factories/methods
* for details.
*
*
* @return NULL
*/
public function setup($params)
{
if (isset($params['_PARAMS'])) {
$this->_params = $params['_PARAMS'];
unset($params['_PARAMS']);
}
foreach ($params as $interface => $setup) {
if (is_array($setup)) {
$factory = $setup['factory'];
$method = isset($setup['method']) ? $setup['method'] : 'create';
$params = isset($setup['params']) ? $setup['params'] : array();
} else {
$factory = $setup;
$method = 'create';
$params = array();
}
if (!empty($this->_error)) {
break;
}
$this->add($interface, $factory, $method, $params);
}
}
/**
* Add a new element to the service container.
*
* @oaram string $interface The interface name to register the service with.
* @param string $factory The (abbreviated) name of the factory.
* @param string $method The factory method that will generate the
* service.
* @param array $params All parameters necessary for creating the
* service.
*
* @return NULL
*/
public function add($interface, $factory, $method, $params)
{
if (!empty($this->_error)) {
return;
}
if (!class_exists('Horde_Test_Factory_' . $factory) &&
!class_exists($factory)) {
$this->_error = "Neither the class \"Horde_Test_Factory_$factory\" nor \"$factory\" exist. \"$interface\" cannot be created!";
return;
}
if (class_exists('Horde_Test_Factory_' . $factory)) {
$f = $this->_injector->getInstance('Horde_Test_Factory_' . $factory);
} else {
$f = $this->_injector->getInstance($factory);
}
if (!method_exists($f, $method) &&
!method_exists($f, 'create' . $method)) {
$this->_error = "The factory lacks the specified method \"$method\"!";
return;
}
if (method_exists($f, 'create' . $method)) {
$method = 'create' . $method;
}
$params = array_merge($this->_params, $params);
try {
$this->_injector->setInstance($interface, $f->{$method}($params));
} catch (Horde_Test_Exception $e) {
$this->_error = $e->getMessage() . "\n\n" . $e->getFile() . ':' . $e->getLine();
}
}
/**
* Export elements from the injector into global scope.
*
* @param array $elements The elements to export.
*
* @return NULL
*/
public function makeGlobal($elements)
{
if (!empty($this->_error)) {
return;
}
foreach ($elements as $key => $interface) {
$GLOBALS[$key] = $this->_injector->getInstance($interface);
}
}
/**
* Return any potential setup error.
*
* @return string The error.
*/
public function getError()
{
return $this->_error;
}
/**
* Return the service container.
*
* @return Horde_Injector The injector.
*/
public function getInjector()
{
return $this->_injector;
}
}