Author: ts
Date: Tue Oct 9 19:25:45 2007
New Revision: 6406
Log:
- Added first proof-of-concept for the plugin-system.
Added:
trunk/Webdav/src/exceptions/invalid_hook.php (with props)
trunk/Webdav/src/plugin_parameters.php (with props)
trunk/Webdav/tests/classes/custom_plugin_configuration.php (with props)
trunk/Webdav/tests/plugin_configuration_test.php (with props)
trunk/Webdav/tests/plugin_registry_test.php (with props)
Modified:
trunk/Webdav/design/class_diagram.png
trunk/Webdav/src/plugin_registry.php
trunk/Webdav/src/webdav_autoload.php
trunk/Webdav/tests/infrastructure_base_test.php
trunk/Webdav/tests/suite.php
Modified: trunk/Webdav/design/class_diagram.png
==============================================================================
Binary files - no diff available.
Added: trunk/Webdav/src/exceptions/invalid_hook.php
==============================================================================
--- trunk/Webdav/src/exceptions/invalid_hook.php (added)
+++ trunk/Webdav/src/exceptions/invalid_hook.php [iso-8859-1] Tue Oct 9
19:25:45 2007
@@ -1,0 +1,51 @@
+<?php
+/**
+ * File containing the ezcWebdavInvalidHookException class.
+ *
+ * @package Webdav
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Exception thrown if a plugin tries to register for a non-existent hook.
+ *
+ * If an instance of [EMAIL PROTECTED] ezcWebdavPluginConfiguration} returns
an invalid
+ * class or hook name on the call to [EMAIL PROTECTED]
+ * ezcWebdavPluginConfiguration::getHooks()}, [EMAIL PROTECTED]
ezcWebdavPluginRegistry}
+ * will throw this exception. This most propably means, that the plugin you try
+ * to configure is malicious or works only with a newer version of the Webdav
+ * component.
+ *
+ * @package Webdav
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcWebdavInvalidHookException extends ezcWebdavException
+{
+ /**
+ * Creates a new exception.
+ *
+ * @param string $class
+ * @param string $hook
+ * @return void
+ */
+ public function __construct( $class, $hook = null )
+ {
+ if ( $hook === null )
+ {
+ $msg = "The class {$class} does not provide any plugin hooks.";
+ }
+ else
+ {
+ $msg = "The class {$class} does not provide a plugin hook named
{$hook}.";
+ }
+ parent::__construct( $msg );
+ }
+}
+
+
+
+?>
Propchange: trunk/Webdav/src/exceptions/invalid_hook.php
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/Webdav/src/plugin_parameters.php
==============================================================================
--- trunk/Webdav/src/plugin_parameters.php (added)
+++ trunk/Webdav/src/plugin_parameters.php [iso-8859-1] Tue Oct 9 19:25:45 2007
@@ -1,0 +1,36 @@
+<?php
+/**
+ * File containing the ezcWebdavPluginParameters class.
+ *
+ * @package Webdav
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Storage class submitted to callbacks assigned to plugin hooks.
+ *
+ * Instances of this storage class are submitted to plugins by the [EMAIL
PROTECTED]
+ * ezcWebdavPluginRegistry}. The contained elements may be evaluated by plugins
+ * and, only if really necessary, be changed.
+ *
+ * @package Webdav
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcWebdavPluginParameters extends ArrayObject
+{
+ /**
+ * Create a new paramater storage.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $parameters = array();
+ parent::__construct( $parameters );
+ }
+}
+
+?>
Propchange: trunk/Webdav/src/plugin_parameters.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Webdav/src/plugin_registry.php
==============================================================================
--- trunk/Webdav/src/plugin_registry.php [iso-8859-1] (original)
+++ trunk/Webdav/src/plugin_registry.php [iso-8859-1] Tue Oct 9 19:25:45 2007
@@ -36,7 +36,7 @@
* <code>
* array(
* '<class>' => array(
- * '<method>' => <bitmask>,
+ * '<method>' => true,
* // ...
* )
* // ...
@@ -60,6 +60,30 @@
* @var array(string=>ezcWebdavPluginConfiguration)
*/
private $plugins = array();
+
+
+ /**
+ * Assigned hooks.
+ * <code>
+ * array(
+ * '<class name>' => array(
+ * '<hook name>' => array(
+ * '<namespace>' => array(
+ * <callback1>,
+ * <callback2>,
+ * // ...
+ * ),
+ * // ...
+ * ),
+ * // ...
+ * ),
+ * // ...
+ * )
+ * </code>
+ *
+ * @var array
+ */
+ private $assignedHooks = array();
/**
* Creates a new plugin registry.
@@ -144,7 +168,46 @@
*/
public final function registerPlugin( ezcWebdavPluginConfiguration $config
)
{
-
+ if ( !is_string( ( $namespace = $config->getNamespace() ) ) )
+ {
+ throw new ezcBaseValueException( 'namespace', $namespace, 'string'
);
+ }
+ if ( isset( $this->plugins[$namespace] ) )
+ {
+ throw new ezcBaseValueException( 'namespace', $namespace, 'not
registered' );
+ }
+
+ if ( !is_array( ( $hooks = $config->getHooks() ) ) )
+ {
+ throw new ezcBaseValueException( 'hooks', $hooks, 'array' );
+ }
+ // Validate hooks
+ foreach ( $hooks as $class => $hookInfos )
+ {
+ if ( !isset( $this->hooks[$class] ) )
+ {
+ throw new ezcWebdavInvalidHookException( $class );
+ }
+ foreach ( $hookInfos as $hook => $callback )
+ {
+ if ( !isset( $this->hooks[$class][$hook] ) )
+ {
+ throw new ezcWebdavInvalidHookException( $class, $hook );
+ }
+ }
+ }
+
+ // Register namespace
+ $this->plugins[$namespace] = $config;
+
+ // Register Hooks
+ foreach ( $hooks as $class => $hookInfos )
+ {
+ foreach ( $hookInfos as $hook => $callbacks )
+ {
+ $this->assignedHooks[$class][$hook][$namespace] = $callbacks;
+ }
+ }
}
/**
@@ -160,7 +223,29 @@
*/
public final function unregisterPlugin( ezcWebdavPluginConfiguration
$config )
{
-
+ if ( !is_string( ( $namespace = $config->getNamespace() ) ) )
+ {
+ throw new ezcBaseValueException( 'namespace', $namespace, 'string'
);
+ }
+ if ( !isset( $this->plugins[$namespace] ) )
+ {
+ throw new ezcBaseValueException( 'namespace', $namespace,
'registered' );
+ }
+
+ // Unregister namespace
+ unset( $this->plugins[$namespace] );
+
+ // Unregister hooks
+ foreach ( $this->assignedHooks as $class => $hookInfos )
+ {
+ foreach ( $hookInfos as $hook => $pluginInfos )
+ {
+ if ( isset( $pluginInfos[$namespace] ) )
+ {
+ unset( $this->assignedHooks[$class][$hook][$namespace] );
+ }
+ }
+ }
}
/**
@@ -175,7 +260,12 @@
*/
public final function getPluginConfig( $namespace )
{
-
+ if ( !isset( $this->plugins[$namespace] ) )
+ {
+ throw new ezcBaseValueException( 'namespace', $namespace,
'registered' );
+ }
+
+ return $this->plugins[$namespace];
}
/**
@@ -189,8 +279,7 @@
*/
public final function hasPlugin( $namespace )
{
- // @todo: Implement
- return true;
+ return isset( $this->plugins[$namespace] );
}
/**
@@ -214,7 +303,13 @@
*/
public final function announceHook( $class, $hook,
ezcWebdavPluginParameters $params )
{
-
+ foreach ( $this->assignedHooks[$class][$hook] as $namespace =>
$callbacks )
+ {
+ foreach ( $callbacks as $callback )
+ {
+ call_user_func( $callback, $params );
+ }
+ }
}
}
Modified: trunk/Webdav/src/webdav_autoload.php
==============================================================================
--- trunk/Webdav/src/webdav_autoload.php [iso-8859-1] (original)
+++ trunk/Webdav/src/webdav_autoload.php [iso-8859-1] Tue Oct 9 19:25:45 2007
@@ -14,6 +14,7 @@
'ezcWebdavBrokenRequestUriException' =>
'Webdav/exceptions/broken_request_uri.php',
'ezcWebdavHeadersNotValidatedException' =>
'Webdav/exceptions/headers_not_validated.php',
'ezcWebdavInvalidHeaderException' =>
'Webdav/exceptions/invalid_header.php',
+ 'ezcWebdavInvalidHookException' =>
'Webdav/exceptions/invalid_hook.php',
'ezcWebdavInvalidRequestBodyException' =>
'Webdav/exceptions/invalid_request_body.php',
'ezcWebdavInvalidRequestMethodException' =>
'Webdav/exceptions/invalid_request_method.php',
'ezcWebdavMissingHeaderException' =>
'Webdav/exceptions/missing_header.php',
@@ -22,6 +23,7 @@
'ezcWebdavNotTransportHandlerException' =>
'Webdav/exceptions/no_transport_handler.php',
'ezcWebdavRequestNotSupportedException' =>
'Webdav/exceptions/request_not_supported.php',
'ezcWebdavUnknownHeaderException' =>
'Webdav/exceptions/unknown_header.php',
+ 'ezcWebdavInfrastructureBase' =>
'Webdav/interfaces/xml_base.php',
'ezcWebdavProperty' =>
'Webdav/interfaces/property.php',
'ezcWebdavBackend' =>
'Webdav/interfaces/backend.php',
'ezcWebdavBackendChange' =>
'Webdav/interfaces/backend/change.php',
@@ -38,6 +40,7 @@
'ezcWebdavRequest' =>
'Webdav/interfaces/request.php',
'ezcWebdavSimpleBackend' =>
'Webdav/backends/simple.php',
'ezcWebdavSupportedLockPropertyLockentry' =>
'Webdav/properties/supportedlock_lockentry.php',
+ 'ezcWebdavTransport' =>
'Webdav/transport.php',
'ezcWebdavAutomaticPathFactory' =>
'Webdav/path_factories/automatic.php',
'ezcWebdavBasicPathFactory' =>
'Webdav/path_factories/basic.php',
'ezcWebdavCollection' =>
'Webdav/structs/collection.php',
@@ -63,7 +66,6 @@
'ezcWebdavGetResourceResponse' =>
'Webdav/responses/get_resource.php',
'ezcWebdavHeadRequest' =>
'Webdav/requests/head.php',
'ezcWebdavHeadResponse' =>
'Webdav/responses/head.php',
- 'ezcWebdavInfrastructureBase' =>
'Webdav/interfaces/xml_base.php',
'ezcWebdavLockDiscoveryProperty' =>
'Webdav/properties/lockdiscovery.php',
'ezcWebdavLockDiscoveryPropertyActiveLock' =>
'Webdav/properties/lockdiscovery_activelock.php',
'ezcWebdavLockRequest' =>
'Webdav/requests/lock.php',
@@ -71,6 +73,7 @@
'ezcWebdavMakeCollectionResponse' =>
'Webdav/responses/mkcol.php',
'ezcWebdavMemoryBackend' =>
'Webdav/backends/memory.php',
'ezcWebdavMemoryBackendOptions' =>
'Webdav/options/backend_memory_options.php',
+ 'ezcWebdavMicrosoftCompatibleTransport' =>
'Webdav/transports/microsoft.php',
'ezcWebdavMoveRequest' =>
'Webdav/requests/move.php',
'ezcWebdavMoveResponse' =>
'Webdav/responses/move.php',
'ezcWebdavMultistatusResponse' =>
'Webdav/responses/multistatus.php',
@@ -78,6 +81,7 @@
'ezcWebdavOptionsRequest' =>
'Webdav/requests/options.php',
'ezcWebdavOptionsResponse' =>
'Webdav/responses/options.php',
'ezcWebdavPluginConfiguration' =>
'Webdav/plugin_configuration.php',
+ 'ezcWebdavPluginParameters' =>
'Webdav/plugin_parameters.php',
'ezcWebdavPluginRegistry' =>
'Webdav/plugin_registry.php',
'ezcWebdavPropFindRequest' =>
'Webdav/requests/propfind.php',
'ezcWebdavPropPatchRequest' =>
'Webdav/requests/proppatch.php',
@@ -95,7 +99,6 @@
'ezcWebdavSourcePropertyLink' =>
'Webdav/properties/source_link.php',
'ezcWebdavStringDisplayInformation' =>
'Webdav/structs/display_information_string.php',
'ezcWebdavSupportedLockProperty' =>
'Webdav/properties/supportedlock.php',
- 'ezcWebdavTransport' =>
'Webdav/transport.php',
'ezcWebdavTransportConfiguration' =>
'Webdav/transport_configuration.php',
'ezcWebdavTransportDispatcher' =>
'Webdav/transport_dispatcher.php',
'ezcWebdavTransportOptions' =>
'Webdav/options/transport.php',
Added: trunk/Webdav/tests/classes/custom_plugin_configuration.php
==============================================================================
--- trunk/Webdav/tests/classes/custom_plugin_configuration.php (added)
+++ trunk/Webdav/tests/classes/custom_plugin_configuration.php [iso-8859-1] Tue
Oct 9 19:25:45 2007
@@ -1,0 +1,69 @@
+<?php
+/**
+ * File containing the fooCustomWebdavPluginConfiguration class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Mock class to remove "abstract".
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @author
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class fooCustomWebdavPluginConfiguration extends ezcWebdavPluginConfiguration
+{
+ public $foo;
+
+ public $callbackCalled = 0;
+
+ public $namespace = 'foonamespace';
+
+ public $hooks;
+
+ public $init = false;
+
+ public function getHooks()
+ {
+ return ( isset( $this->hooks ) ? $this->hooks : array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ array( 'ezcWebdavPluginRegistryTest', 'callbackBeforeTest'
),
+ array( $this, 'testCallback' ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ array( 'ezcWebdavPluginRegistryTest', 'callbackAfterTest'
),
+ array( $this, 'testCallback' )
+ ),
+ ),
+ ) );
+ }
+
+ public function testCallback()
+ {
+ ++$this->callbackCalled;
+ }
+
+
+ public function getNamespace()
+ {
+ return $this->namespace;
+ }
+
+ public function init()
+ {
+ $this->init = true;
+ }
+}
+
+
+
+?>
Propchange: trunk/Webdav/tests/classes/custom_plugin_configuration.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Webdav/tests/infrastructure_base_test.php
==============================================================================
--- trunk/Webdav/tests/infrastructure_base_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/infrastructure_base_test.php [iso-8859-1] Tue Oct 9
19:25:45 2007
@@ -26,6 +26,11 @@
require_once 'test_case.php';
/**
+ * Require mocked version of ezcWebdavPluginConfiguration.
+ */
+require_once 'classes/custom_plugin_configuration.php';
+
+/**
* Tests for ezcWebdavInfrastructureBase class.
*
* @package Webdav
@@ -33,6 +38,8 @@
*/
class ezcWebdavInfrastructureBaseTest extends ezcWebdavTestCase
{
+ protected $namespaces = array();
+
public static function suite()
{
return new PHPUnit_Framework_TestSuite( __CLASS__ );
@@ -40,9 +47,23 @@
protected function setUp()
{
- // Should register a plugin here to get a namespace
- // no need for now, since ezcWebdavPluginRegistry is not
- // ready, yet, and always returns true.
+ $srv = ezcWebdavServer::getInstance();
+
+ $this->namespaces['foonamespace'] = new
fooCustomWebdavPluginConfiguration();
+
+ $this->namespaces['namespacebar'] = new
fooCustomWebdavPluginConfiguration();
+ $this->namespaces['namespacebar']->namespace = 'namespacebar';
+
+ $srv->pluginRegistry->registerPlugin(
$this->namespaces['foonamespace'] );
+ $srv->pluginRegistry->registerPlugin(
$this->namespaces['namespacebar'] );
+ }
+
+ protected function tearDown()
+ {
+ $srv = ezcWebdavServer::getInstance();
+
+ $srv->pluginRegistry->unregisterPlugin(
$this->namespaces['foonamespace'] );
+ $srv->pluginRegistry->unregisterPlugin(
$this->namespaces['namespacebar'] );
}
public function testSetPluginDataSuccess()
@@ -182,14 +203,31 @@
$base,
'Plugin data not unset correctly.'
);
-
- $base->removePluginData( 'unkown namespace', 'unknown key' );
-
- $this->assertAttributeEquals(
- array(
- 'foonamespace' => array(
- ),
- 'namespacebar' => array(
+ }
+
+ public function testRemovePluginDataFailure()
+ {
+ $base = new fooCustomWebdavInfrastructure();
+
+ $base->setPluginData( 'foonamespace', 'barkey', array( 23, 42 ) );
+ $base->setPluginData( 'foonamespace', 'bazkey', true );
+ $base->setPluginData( 'namespacebar', 'keyfoo', new stdClass() );
+
+ try
+ {
+ $base->removePluginData( 'unkown namespace', 'unknown key' );
+ $this->fail( 'Exception not thrown on removal of data from unknown
plugin namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => array(
+ 'barkey' => array( 23, 42 ),
+ 'bazkey' => true,
+ ),
+ 'namespacebar' => array(
+ 'keyfoo' => new stdClass(),
),
),
'pluginData',
Added: trunk/Webdav/tests/plugin_configuration_test.php
==============================================================================
--- trunk/Webdav/tests/plugin_configuration_test.php (added)
+++ trunk/Webdav/tests/plugin_configuration_test.php [iso-8859-1] Tue Oct 9
19:25:45 2007
@@ -1,0 +1,71 @@
+<?php
+/**
+ * Test case for the ezcWebdavInfrastructureBase class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Reqiuire base test
+ */
+require_once 'test_case.php';
+
+/**
+ * Require mocked version of ezcWebdavPluginConfiguration.
+ */
+require_once 'classes/custom_plugin_configuration.php';
+
+/**
+ * Tests for ezcWebdavInfrastructureBase class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ */
+class ezcWebdavPluginConfigurationTest extends ezcWebdavTestCase
+{
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( __CLASS__ );
+ }
+
+ public function testGetHooks()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $this->assertEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'extractLiveProperty' => array(
+ array( 'fooBar', 'baz' ),
+ array( 'fooCustomWebdavPluginConfiguration', 'test' ),
+ ),
+ ),
+ ),
+ $cfg->getHooks()
+ );
+ }
+
+ public function testGetNamespace()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $this->assertEquals(
+ 'foobar',
+ $cfg->getNamespace()
+ );
+ }
+
+ public function testInit()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $cfg->init();
+ $this->assertEquals(
+ 'bar',
+ $cfg->foo
+ );
+ }
+}
+
+?>
Propchange: trunk/Webdav/tests/plugin_configuration_test.php
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/Webdav/tests/plugin_registry_test.php
==============================================================================
--- trunk/Webdav/tests/plugin_registry_test.php (added)
+++ trunk/Webdav/tests/plugin_registry_test.php [iso-8859-1] Tue Oct 9
19:25:45 2007
@@ -1,0 +1,649 @@
+<?php
+/**
+ * Test case for the ezcWebdavInfrastructureBase class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Reqiuire base test
+ */
+require_once 'test_case.php';
+
+/**
+ * Require mocked version of ezcWebdavPluginConfiguration.
+ */
+require_once 'classes/custom_plugin_configuration.php';
+
+/**
+ * Tests for ezcWebdavInfrastructureBase class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ */
+class ezcWebdavPluginRegistryTest extends ezcWebdavTestCase
+{
+ private static $beforeParams;
+
+ private static $afterParams;
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( __CLASS__ );
+ }
+
+ protected function setUp()
+ {
+ self::$beforeParams = null;
+ self::$afterParams = null;
+ }
+
+ public static function callbackBeforeTest( ezcWebdavPluginParameters
$params )
+ {
+ self::$beforeParams = $params;
+ }
+
+ public static function callbackAfterTest( ezcWebdavPluginParameters
$params )
+ {
+ self::$afterParams = $params;
+ }
+
+ public function testCtor()
+ {
+ $reg = new ezcWebdavPluginRegistry();
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(),
+ 'plugins',
+ $reg,
+ 'Attribute $plugins not initialized correctly.'
+ );
+
+ }
+
+ public function testRegisterPluginSuccess()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackBeforeTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackAfterTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+ }
+
+ public function testRegisterPluginFailureDoubleRegister()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg
+ ),
+ 'plugins',
+ $reg
+ );
+
+ try
+ {
+ $reg->registerPlugin( $cfg );
+ $this->fail( 'Exception not thrown on double registered
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ }
+
+ public function testRegisterPluginFailureInvalidNamespace()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+ $reg->namespace = true;
+
+ $reg->registerPlugin( $cfg );
+
+ try
+ {
+ $reg->registerPlugin( $cfg );
+ $this->fail( 'Exception not thrown on double registered
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ }
+
+ public function testRegisterPluginFailureInvalidHooks()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $cfg->hooks = true;
+
+ $reg = new ezcWebdavPluginRegistry();
+
+ try
+ {
+ $reg->registerPlugin( $cfg );
+ $this->fail( 'Exception not thrown on double registered
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ }
+
+ public function testRegisterPluginFailureInvalidHookClass()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $cfg->hooks = array(
+ 'fooMyClass' => array(),
+ );
+
+ $reg = new ezcWebdavPluginRegistry();
+
+ try
+ {
+ $reg->registerPlugin( $cfg );
+ $this->fail( 'Exception not thrown on double registered
namespace.' );
+ }
+ catch ( ezcWebdavInvalidHookException $e ) {}
+ }
+
+ public function testRegisterPluginFailureInvalidHook()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $cfg->hooks = array(
+ 'ezcWebdavTransport' => array(
+ 'beforeMyCustomHook' => array(),
+ ),
+ );
+
+ $reg = new ezcWebdavPluginRegistry();
+
+ try
+ {
+ $reg->registerPlugin( $cfg );
+ $this->fail( 'Exception not thrown on double registered
namespace.' );
+ }
+ catch ( ezcWebdavInvalidHookException $e ) {}
+ }
+
+ public function testUnregisterPluginSuccess()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackBeforeTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackAfterTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ $reg->unregisterPlugin( $cfg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ ),
+ 'afterExtractLiveProperty' => array(
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+ }
+
+ public function testUnregisterPluginFailureUnknown()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ try
+ {
+ $reg->unregisterPlugin( $cfg );
+ $this->fail( 'Exception not thrown on unregistering unknown
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ }
+
+ public function testUnregisterPluginFailureInvalidNamespace()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $cfg->namespace = true;
+ $reg = new ezcWebdavPluginRegistry();
+
+ try
+ {
+ $reg->unregisterPlugin( $cfg );
+ $this->fail( 'Exception not thrown on unregistering invalid
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+ }
+
+ public function testGetPluginConfigSuccess()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg,
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackBeforeTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackAfterTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ $this->assertEquals(
+ $cfg,
+ $reg->getPluginConfig( 'foonamespace' )
+ );
+ }
+
+ public function testGetPluginConfigFailure()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ try
+ {
+ $reg->getPluginConfig( 'foonamespace' );
+ $this->fail( 'Exception not thrown on get of unknown plugin
namespace.' );
+ }
+ catch ( ezcBaseValueException $e ) {}
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+ }
+
+ public function testHasPluginConfigSuccess()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg,
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackBeforeTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackAfterTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ $this->assertTrue(
+ $reg->hasPlugin( 'foonamespace' )
+ );
+ }
+
+ public function testHasPluginConfigFailure()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ $this->assertFalse(
+ $reg->hasPlugin( 'foonamespace' )
+ );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+ }
+
+ public function testAnnounceHookSuccess()
+ {
+ $cfg = new fooCustomWebdavPluginConfiguration();
+ $reg = new ezcWebdavPluginRegistry();
+
+ $reg->registerPlugin( $cfg );
+
+ $this->assertHooksCorrect( $reg );
+
+ $this->assertAttributeEquals(
+ array(
+ 'foonamespace' => $cfg,
+ ),
+ 'plugins',
+ $reg
+ );
+
+ $this->assertAttributeEquals(
+ array(
+ 'ezcWebdavTransport' => array(
+ 'beforeExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackBeforeTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ 'afterExtractLiveProperty' => array(
+ 'foonamespace' => array(
+ array( 'ezcWebdavPluginRegistryTest',
'callbackAfterTest' ),
+ array( $cfg, 'testCallback' ),
+ ),
+ ),
+ ),
+ ),
+ 'assignedHooks',
+ $reg,
+ 'Property $assignedHooks not set correctly after registration.'
+ );
+
+ $reg->announceHook( 'ezcWebdavTransport', 'beforeExtractLiveProperty',
( $beforeParams = new ezcWebdavPluginParameters() ) );
+
+ $this->assertSame(
+ $beforeParams,
+ self::$beforeParams,
+ 'Params of before callback invalid'
+ );
+
+ $this->assertNull(
+ self::$afterParams,
+ 'Params of after callback invalid'
+ );
+
+ $this->assertEquals(
+ 1,
+ $cfg->callbackCalled,
+ 'Number of called callbackes invalid.'
+ );
+
+ $reg->announceHook( 'ezcWebdavTransport', 'afterExtractLiveProperty',
( $afterParams = new ezcWebdavPluginParameters() ) );
+
+ $this->assertSame(
+ $beforeParams,
+ self::$beforeParams,
+ 'Params of before callback invalid'
+ );
+
+ $this->assertEquals(
+ new ezcWebdavPluginParameters(),
+ self::$beforeParams,
+ 'Params of before callback invalid'
+ );
+
+ $this->assertSame(
+ $afterParams,
+ self::$afterParams,
+ 'Params of after callback invalid'
+ );
+
+ $this->assertEquals(
+ 2,
+ $cfg->callbackCalled,
+ 'Number of called callbackes invalid.'
+ );
+ }
+
+
+ protected function assertHooksCorrect( ezcWebdavPluginRegistry $reg )
+ {
+ $this->assertAttributeEquals(
+ array (
+ 'ezcWebdavTransport' => array (
+ 'beforeParseCopyRequest' => true,
+ 'afterParseCopyRequest' => true,
+ 'beforeParseDeleteRequest' => true,
+ 'afterParseDeleteRequest' => true,
+ 'beforeParseGetRequest' => true,
+ 'afterParseGetRequest' => true,
+ 'beforeParseHeadRequest' => true,
+ 'afterParseHeadRequest' => true,
+ 'beforeParseLockRequest' => true,
+ 'afterParseLockRequest' => true,
+ 'beforeParseMakeCollectionRequest' => true,
+ 'afterParseMakeCollectionRequest' => true,
+ 'beforeParseMoveRequest' => true,
+ 'afterParseMoveRequest' => true,
+ 'beforeParseOptionsRequest' => true,
+ 'afterParseOptionsRequest' => true,
+ 'beforeParsePropFindRequest' => true,
+ 'afterParsePropFindRequest' => true,
+ 'beforeParsePropPatchRequest' => true,
+ 'afterParsePropPatchRequest' => true,
+ 'beforeParsePutRequest' => true,
+ 'afterParsePutRequest' => true,
+ 'beforeParseUnlockRequest' => true,
+ 'afterParseUnlockRequest' => true,
+ 'beforeProcessCopyResponse' => true,
+ 'afterProcessCopyResponse' => true,
+ 'beforeProcessDeleteResponse' => true,
+ 'afterProcessDeleteResponse' => true,
+ 'beforeProcessErrorResponse' => true,
+ 'afterProcessErrorResponse' => true,
+ 'beforeProcessGetCollectionResponse' => true,
+ 'afterProcessGetCollectionResponse' => true,
+ 'beforeProcessGetResourceResponse' => true,
+ 'afterProcessGetResourceResponse' => true,
+ 'beforeProcessHeadResponse' => true,
+ 'afterProcessHeadResponse' => true,
+ 'beforeProcessMakeCollectionResponse' => true,
+ 'afterProcessMakeCollectionResponse' => true,
+ 'beforeProcessMoveResponse' => true,
+ 'afterProcessMoveResponse' => true,
+ 'beforeProcessMultiStatusResponse' => true,
+ 'afterProcessMultiStatusResponse' => true,
+ 'beforeProcessOptionsResponse' => true,
+ 'afterProcessOptionsResponse' => true,
+ 'beforeProcessPropFindResponse' => true,
+ 'afterProcessPropFindResponse' => true,
+ 'beforeProcessPropPatchResponse' => true,
+ 'afterProcessPropPatchResponse' => true,
+ 'beforeProcessPutResponse' => true,
+ 'afterProcessPutResponse' => true,
+ 'processUnknownRequest' => true,
+ 'handleUnknownResponse' => true,
+ 'beforeExtractLiveProperty' => true,
+ 'afterExtractLiveProperty' => true,
+ 'beforeExtractDeadProperty' => true,
+ 'afterExtractDeadProperty' => true,
+ 'beforeSerializeLiveProperty' => true,
+ 'afterSerializeLiveProperty' => true,
+ 'beforeSerializeDeadProperty' => true,
+ 'afterSerializeDeadProperty' => true,
+ 'extractUnknownLiveProperty' => true,
+ 'serializeUnknownLiveProperty' => true,
+ 'extractUnknownDeadProperty' => true,
+ 'serializeUnknownDeadProperty' => true,
+ ),
+ 'ezcWebdavServer' => array (
+ 'receivedRequest' => true,
+ 'generatedResponse' => true,
+ ),
+ ),
+ 'hooks',
+ $reg,
+ 'Attribute $hooks is invalid.'
+ );
+ }
+}
+
+?>
Propchange: trunk/Webdav/tests/plugin_registry_test.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Webdav/tests/suite.php
==============================================================================
--- trunk/Webdav/tests/suite.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/suite.php [iso-8859-1] Tue Oct 9 19:25:45 2007
@@ -66,6 +66,9 @@
require_once 'transport_configuration_test.php';
require_once 'transport_dispatcher_test.php';
+require_once 'plugin_configuration_test.php';
+require_once 'plugin_registry_test.php';
+
require_once 'client_test_rfc.php';
require_once 'client_test_litmus.php';
require_once 'client_test_cadaver.php';
@@ -88,6 +91,10 @@
$this->setName( 'Webdav' );
$this->addTest( ezcWebdavBasicServerTest::suite() );
+
+ $this->addTest( ezcWebdavPluginConfigurationTest::suite() );
+ $this->addTest( ezcWebdavPluginRegistryTest::suite() );
+
$this->addTest( ezcWebdavTransportConfigurationTest::suite() );
$this->addTest( ezcWebdavTransportDispatcherTest::suite() );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components