Modified: trunk/Webdav/tests/server_test.php
==============================================================================
--- trunk/Webdav/tests/server_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/server_test.php [iso-8859-1] Wed Oct  3 08:26:57 2007
@@ -27,6 +27,187 @@
                return new PHPUnit_Framework_TestSuite( 
'ezcWebdavBasicServerTest' );
        }
 
+    public function testSingleton()
+    {
+        $srv = ezcWebdavServer::getInstance();
+        $srv2 = ezcWebdavServer::getInstance();
+
+        $this->assertSame( $srv, $srv2 );
+    }
+
+    public function testCtor()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        $this->assertAttributeEquals(
+            array(
+                'transport'      => null,
+                'backend'        => null,
+                'transports'     => new ezcWebdavTransportDispatcher(),
+                'pluginRegistry' => new ezcWebdavPluginRegistry(),
+            ),
+            'properties',
+            $srv
+        );
+    }
+
+    public function testGetPropertiesDefaultSuccess()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        $defaults = array(
+            'transport'      => null,
+            'backend'        => null,
+            'transports'     => new ezcWebdavTransportDispatcher(),
+            'pluginRegistry' => new ezcWebdavPluginRegistry(),
+        );
+
+        foreach ( $defaults as $property => $value )
+        {
+            $this->assertEquals(
+                $value,
+                $srv->$property,
+                "Property $property has incorrect default."
+            );
+        }
+    }
+
+    public function testGetPropertiesFailure()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        try
+        {
+            echo $srv->foo;
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( 'Property not thrown on get access of non-existent 
property.' );
+    }
+
+    public function testSetPropertiesGetPropertiesSuccess()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        $setValues = array(
+            'transports'     => new ezcWebdavTransportDispatcher(),
+            'backend'        => new ezcWebdavMemoryBackend(),
+        );
+        $checkValues = array(
+            'transport'      => null,
+            'backend'        => new ezcWebdavMemoryBackend(),
+            'transports'     => new ezcWebdavTransportDispatcher(),
+            'pluginRegistry' => new ezcWebdavPluginRegistry(),
+        );
+
+        foreach( $setValues as $property => $value )
+        {
+            $srv->$property = $value;
+        }
+
+        $this->assertAttributeEquals(
+            $checkValues,
+            'properties',
+            $srv
+        );
+
+        foreach ( $checkValues as $property => $value )
+        {
+            $this->assertEquals(
+                $value,
+                $srv->$property,
+                "Property $property has incorrect value after ctor setting."
+            );
+        }
+    }
+
+    public function testSetAccessFailure()
+    {
+        $typicalFails = array(
+            '',
+            23,
+            23.42,
+            true,
+            false,
+            array(),
+            new stdClass(),
+        );
+
+        $invalidValues = array(
+            'transports' => $typicalFails, 
+            'backend'    => $typicalFails, 
+        );
+
+        foreach ( $invalidValues as $propertyName => $propertyValues )
+        {
+            $this->assertSetPropertyFailure( $propertyName, $propertyValues, 
'ezcBaseValueException' );
+        }
+
+        try
+        {
+            $srv = ezcWebdavServer::getInstance();
+            $srv->pluginRegistry = 23;
+            $this->fail( 'Exception not thrown on set access to read-only 
property.' );
+        }
+        catch ( ezcBasePropertyPermissionException $e ){}
+
+        try
+        {
+            $srv = ezcWebdavServer::getInstance();
+            $srv->transport = 23;
+            $this->fail( 'Exception not thrown on set access to read-only 
property.' );
+        }
+        catch ( ezcBasePropertyPermissionException $e ){}
+
+        try
+        {
+            $srv = ezcWebdavServer::getInstance();
+            $srv->fooBar = 23;
+            $this->fail( 'Exception not thrown on set access to non-existent 
property.' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e ){}
+    }
+
+    public function testPropertiesIssetAccessDefaultCtorSuccess()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        $properties =array(
+            'transports', 
+            'backend', 
+            'pluginRegistry', 
+            'transport', 
+        );
+
+        foreach( $properties as $propertyName )
+        {
+            $this->assertTrue(
+                isset( $srv->$propertyName ),
+                "Property not set after default construction: '$propertyName'."
+            );
+        }
+    }
+
+    public function testPropertyIssetAccessFailure()
+    {
+        $srv = ezcWebdavServer::getInstance();
+
+        $this->assertFalse(
+            isset( $srv->foo ),
+            'Non-existent property $foo seems to be set.'
+        );
+        $this->assertFalse(
+            isset( $srv->properties ),
+            'Non-existent property $properties seems to be set.'
+        );
+    }
+
+    /*
+     * Old tests.
+     * Need updated environment now.
+
     public function testDefaultHandlerWithUnknowClient()
     {
         $_SERVER['HTTP_USER_AGENT'] = 'ezcUnknownClient';
@@ -121,5 +302,27 @@
 
         $this->fail( 'Expected ezcWebdavNotTransportHandlerException.' );
     }
+
+    */
+
+    protected function assertSetPropertyFailure( $propertyName, array 
$propertyValues, $exceptionClass )
+    {
+        foreach ( $propertyValues as $value )
+        {
+            try
+            {
+                $srv = ezcWebdavServer::getInstance();
+                $srv->$propertyName = $value;
+                $this->fail( "Exception not thrown on invalid ___set() value 
for property '$propertyName'." );
+            }
+            catch( Exception $e )
+            {
+                $this->assertTrue(
+                    ( $e instanceof $exceptionClass ),
+                    "Exception thrown on invalid value set for property 
'$propertyName'. '" . get_class( $e ) . "' instead of '$exceptionClass'."
+                );
+            }
+        }
+    }
 }
 ?>

Modified: trunk/Webdav/tests/suite.php
==============================================================================
--- trunk/Webdav/tests/suite.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/suite.php [iso-8859-1] Wed Oct  3 08:26:57 2007
@@ -60,8 +60,9 @@
 require_once 'response_options_test.php';
 require_once 'response_test.php';
 
-require_once 'transport_options_test.php';
 require_once 'server_test.php';
+require_once 'transport_configuration_test.php';
+require_once 'transport_dispatcher_test.php';
 
 require_once 'client_test_rfc.php';
 require_once 'client_test_litmus.php';
@@ -85,7 +86,8 @@
         $this->setName( 'Webdav' );
 
         $this->addTest( ezcWebdavBasicServerTest::suite() );
-        $this->addTest( ezcWebdavTransportOptionsTest::suite() );
+        $this->addTest( ezcWebdavTransportConfigurationTest::suite() );
+        $this->addTest( ezcWebdavTransportDispatcherTest::suite() );
 
         $this->addTest( ezcWebdavFlaggedPropertyStorageTest::suite() );
         $this->addTest( ezcWebdavPropertyStorageTest::suite() );

Added: trunk/Webdav/tests/transport_configuration_test.php
==============================================================================
--- trunk/Webdav/tests/transport_configuration_test.php (added)
+++ trunk/Webdav/tests/transport_configuration_test.php [iso-8859-1] Wed Oct  3 
08:26:57 2007
@@ -1,0 +1,461 @@
+<?php
+/**
+ * Basic test cases for the memory backend.
+ *
+ * @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';
+
+/**
+ * Custom classes to test inheritence. 
+ */
+require_once 'classes/foo_custom_classes.php';
+
+/**
+ * Tests for ezcWebdavTransportConfiguration class.
+ * 
+ * @package Webdav
+ * @subpackage Tests
+ */
+class ezcWebdavTransportConfigurationTest extends ezcWebdavTestCase
+{
+       public static function suite()
+       {
+               return new PHPUnit_Framework_TestSuite( __CLASS__ );
+       }
+
+    public function testCtorSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*)',
+                'transport'       => 'ezcWebdavTransport',
+                'xmlTool'         => 'ezcWebdavXmlTool',
+                'propertyHandler' => 'ezcWebdavPropertyHandler',
+                'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)'
+        );
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*Nautilus.*)',
+                'transport'       => 'ezcWebdavTransport',
+                'xmlTool'         => 'ezcWebdavXmlTool',
+                'propertyHandler' => 'ezcWebdavPropertyHandler',
+                'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'ezcWebdavCustomTransport'
+        );
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*Nautilus.*)',
+                'transport'       => 'ezcWebdavCustomTransport',
+                'xmlTool'         => 'ezcWebdavXmlTool',
+                'propertyHandler' => 'ezcWebdavPropertyHandler',
+                'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool'
+        );
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*Nautilus.*)',
+                'transport'       => 'fooCustomTransport',
+                'xmlTool'         => 'fooCustomXmlTool',
+                'propertyHandler' => 'ezcWebdavPropertyHandler',
+                'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool',
+            'fooCustomPropertyHandler'
+        );
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*Nautilus.*)',
+                'transport'       => 'fooCustomTransport',
+                'xmlTool'         => 'fooCustomXmlTool',
+                'propertyHandler' => 'fooCustomPropertyHandler',
+                'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool',
+            'fooCustomPropertyHandler',
+            new ezcWebdavBasicPathFactory()
+        );
+
+        $this->assertAttributeEquals(
+            array(
+                'userAgentRegex'  => '(.*Nautilus.*)',
+                'transport'       => 'fooCustomTransport',
+                'xmlTool'         => 'fooCustomXmlTool',
+                'propertyHandler' => 'fooCustomPropertyHandler',
+                'pathFactory'     => new ezcWebdavBasicPathFactory(),
+            ),
+            'properties',
+            $cfg,
+            'Default properties not created correctly on empty ctor.'
+        );
+    }
+
+    public function testCtorFailure()
+    {
+        $typicalFails = array(
+            '',
+            23,
+            23.42,
+            true,
+            false,
+            array(),
+            new stdClass(),
+        );
+        $typicalValid = 'fooSomeClass';
+
+        $validCtorParams = array(
+            $typicalValid, // userAgentRegex
+            $typicalValid, // transport
+            $typicalValid, // xmlTool
+            $typicalValid, // propertyHandler
+            new ezcWebdavAutomaticPathFactory(), // pathFactory
+        );
+
+        $invalidCtorParams = array(
+            $typicalFails, // userAgentRegex
+            $typicalFails, // transport
+            $typicalFails, // xmlTool
+            $typicalFails, // propertyHandler
+            array_merge( $typicalFails, array( 'foo' ) ), // pathFactory
+        );
+
+        foreach ( $invalidCtorParams as $id => $paramSet )
+        {
+            $params = array();
+            for ( $i = 0; $i < $id; ++$i )
+            {
+                $params[$i] = $validCtorParams[$i];
+            }
+            foreach ( $paramSet as $param )
+            {
+                $params[$id] = $param;
+                $this->assertCtorFailure( $params, ( $i !== 4 ? 
'ezcBaseValueException' : 'PHPUnit_Framework_Error' ) );
+            }
+        }
+    }
+
+    public function testGetPropertiesDefaultSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $defaults = array(
+            'userAgentRegex'  => '(.*)',
+            'transport'       => 'ezcWebdavTransport',
+            'xmlTool'         => 'ezcWebdavXmlTool',
+            'propertyHandler' => 'ezcWebdavPropertyHandler',
+            'pathFactory'     => new ezcWebdavAutomaticPathFactory(),
+        );
+
+        foreach ( $defaults as $property => $value )
+        {
+            $this->assertEquals(
+                $value,
+                $cfg->$property,
+                "Property $property has incorrect default."
+            );
+        }
+    }
+
+    public function testGetPropertiesFromCtorSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool',
+            'fooCustomPropertyHandler',
+            new ezcWebdavBasicPathFactory()
+        );
+
+        $values = array(
+            'userAgentRegex'  => '(.*Nautilus.*)',
+            'transport'       => 'fooCustomTransport',
+            'xmlTool'         => 'fooCustomXmlTool',
+            'propertyHandler' => 'fooCustomPropertyHandler',
+            'pathFactory'     => new ezcWebdavBasicPathFactory(),
+        );
+
+        foreach ( $values as $property => $value )
+        {
+            $this->assertEquals(
+                $value,
+                $cfg->$property,
+                "Property $property has incorrect value after ctor setting."
+            );
+        }
+    }
+
+    public function testGetPropertiesFailure()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        try
+        {
+            echo $cfg->foo;
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            return;
+        }
+        $this->fail( 'Property not thrown on get access of non-existent 
property.' );
+    }
+
+    public function testSetPropertiesGetPropertiesSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $values = array(
+            'userAgentRegex'  => '(.*Nautilus.*)',
+            'transport'       => 'fooCustomTransport',
+            'xmlTool'         => 'fooCustomXmlTool',
+            'propertyHandler' => 'fooCustomPropertyHandler',
+            'pathFactory'     => new ezcWebdavBasicPathFactory(),
+        );
+
+        foreach( $values as $property => $value )
+        {
+            $cfg->$property = $value;
+        }
+
+        $this->assertAttributeEquals(
+            $values,
+            'properties',
+            $cfg
+        );
+        foreach ( $values as $property => $value )
+        {
+            $this->assertEquals(
+                $value,
+                $cfg->$property,
+                "Property $property has incorrect value after ctor setting."
+            );
+        }
+    }
+
+    public function testSetAccessFailure()
+    {
+        $typicalFails = array(
+            '',
+            23,
+            23.42,
+            true,
+            false,
+            array(),
+            new stdClass(),
+        );
+
+        $invalidValues = array(
+            'userAgentRegex'  => $typicalFails, 
+            'transport'       => $typicalFails, 
+            'xmlTool'         => $typicalFails, 
+            'propertyHandler' => $typicalFails, 
+            'pathFactory'     => array_merge( $typicalFails, array( 'foo' ) ), 
+        );
+
+        foreach ( $invalidValues as $propertyName => $propertyValues )
+        {
+            $this->assertSetPropertyFailure( $propertyName, $propertyValues, 
'ezcBaseValueException' );
+        }
+
+        try
+        {
+            $cfg = new ezcWebdavTransportConfiguration();
+            $cfg->fooBar = 23;
+            $this->fail( 'Exception not thrown on set access to non-existent 
property.' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e ){}
+    }
+
+    public function testPropertiesIssetAccessDefaultCtorSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $properties =array(
+            'userAgentRegex', 
+            'transport', 
+            'xmlTool', 
+            'propertyHandler', 
+            'pathFactory', 
+        );
+
+        foreach( $properties as $propertyName )
+        {
+            $this->assertTrue(
+                isset( $cfg->$propertyName ),
+                "Property not set after default construction: '$propertyName'."
+            );
+        }
+    }
+
+    public function testPropertiesIssetAccessNonDefaultCtorSuccess()
+    {
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool',
+            'fooCustomPropertyHandler',
+            new ezcWebdavBasicPathFactory()
+        );
+
+        $properties =array(
+            'userAgentRegex', 
+            'transport', 
+            'xmlTool', 
+            'propertyHandler', 
+            'pathFactory', 
+        );
+
+        foreach( $properties as $propertyName )
+        {
+            $this->assertTrue(
+                isset( $cfg->$propertyName ),
+                "Property not set after default construction: '$propertyName'."
+            );
+        }
+    }
+
+    public function testPropertyIssetAccessFailure()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $this->assertFalse(
+            isset( $cfg->foo ),
+            'Non-existent property $foo seems to be set.'
+        );
+        $this->assertFalse(
+            isset( $cfg->properties ),
+            'Non-existent property $properties seems to be set.'
+        );
+    }
+
+    public function testGetTransportInstanceSuccessDefaultCtor()
+    {
+        $cfg = new ezcWebdavTransportConfiguration();
+
+        $expected = new ezcWebdavTransport();
+
+        $this->assertEquals(
+            $expected,
+            $cfg->getTransportInstance()
+        );
+    }
+
+    public function testGetTransportInstanceSuccessNonDefaultCtor()
+    {
+        $cfg = new ezcWebdavTransportConfiguration(
+            '(.*Nautilus.*)',
+            'fooCustomTransport',
+            'fooCustomXmlTool',
+            'fooCustomPropertyHandler',
+            new ezcWebdavBasicPathFactory( 'http://foo.example.com/webdav/' )
+        );
+        
+        $xmlTool = new fooCustomXmlTool();
+        $expected = new fooCustomTransport(
+            $xmlTool,
+            new fooCustomPropertyHandler( $xmlTool ),
+            new ezcWebdavBasicPathFactory( 'http://foo.example.com/webdav/' )
+        );
+
+        $this->assertEquals(
+            $expected,
+            $cfg->getTransportInstance()
+        );
+
+    }
+
+    protected function assertCtorFailure( array $args, $exceptionClass )
+    {
+        try
+        {
+            $cfgClass = new ReflectionClass( 'ezcWebdavTransportConfiguration' 
);
+            $cfg = $cfgClass->newInstanceArgs( $args );
+        }
+        catch( Exception $e )
+        {
+            ( !( $e instanceof $exceptionClass ) ? var_dump( $e ) : null );
+            $this->assertTrue(
+                ( $e instanceof $exceptionClass ),
+                "Exception thrown on invalid value set of wrong exception 
class. '" . get_class( $e ) . "' instead of '$exceptionClass'."
+            );
+            return;
+        }
+        $this->fail( "Exception not thrown on invalid argument set." );
+    }
+
+    protected function assertSetPropertyFailure( $propertyName, array 
$propertyValues, $exceptionClass )
+    {
+        foreach ( $propertyValues as $value )
+        {
+            try
+            {
+                $cfg = new ezcWebdavTransportConfiguration();
+                $cfg->$propertyName = $value;
+                $this->fail( "Exception not thrown on invalid ___set() value 
for property '$propertyName'." );
+            }
+            catch( Exception $e )
+            {
+                $this->assertTrue(
+                    ( $e instanceof $exceptionClass ),
+                    "Exception thrown on invalid value set for property 
'$propertyName'. '" . get_class( $e ) . "' instead of '$exceptionClass'."
+                );
+            }
+        }
+    }
+}
+
+?>

Propchange: trunk/Webdav/tests/transport_configuration_test.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Webdav/tests/transport_dispatcher_test.php
==============================================================================
--- trunk/Webdav/tests/transport_dispatcher_test.php (added)
+++ trunk/Webdav/tests/transport_dispatcher_test.php [iso-8859-1] Wed Oct  3 
08:26:57 2007
@@ -1,0 +1,866 @@
+<?php
+/**
+ * Basic test cases for the memory backend.
+ *
+ * @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';
+
+/**
+ * Custom classes to test inheritence. 
+ */
+require_once 'classes/foo_custom_classes.php';
+
+/**
+ * Tests for ezcWebdavTransportDispatcher class.
+ * 
+ * @package Webdav
+ * @subpackage Tests
+ */
+class ezcWebdavTransportDispatcherTest extends ezcWebdavTestCase
+{
+       public static function suite()
+       {
+               return new PHPUnit_Framework_TestSuite( __CLASS__ );
+       }
+
+    public function testCtor()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $this->assertAttributeEquals(
+            array(
+                0  => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+    }
+    
+    public function testInsertBeforeSuccess()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $firstCfg = new ezcWebdavTransportConfiguration();
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $secondCfg = new ezcWebdavTransportConfiguration(
+            'fooregex'
+        );
+
+        $dp->insertBefore( $secondCfg );
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $secondCfg,
+                1  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+
+        $thirdCfg = new ezcWebdavTransportConfiguration(
+            'barregex'
+        );
+
+        $dp->insertBefore( $thirdCfg, 1 );
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $secondCfg,
+                1  => $thirdCfg,
+                2  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+
+        $dp->insertBefore( $thirdCfg );
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $thirdCfg,
+                1  => $secondCfg,
+                2  => $thirdCfg,
+                3  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+    }
+    
+    public function testInsertBeforeFailure()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $firstCfg = new ezcWebdavTransportConfiguration();
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+        
+        $secondCfg = new ezcWebdavTransportConfiguration(
+            'fooregex'
+        );
+
+        try
+        {
+            $dp->insertBefore( $secondCfg, 'foo' );
+            $this->fail( 'ezcBaseValueException not thrown on string $offset.' 
);
+        }
+        catch ( ezcBaseValueException $e ) {}
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+
+        try
+        {
+            $dp->insertBefore( $secondCfg, -23 );
+            $this->fail( 'ezcBaseValueException not thrown on negative int 
$offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+
+        try
+        {
+            $dp->insertBefore( $secondCfg, 42 );
+            $this->fail( 'ezcBaseValueException not thrown on wide to large 
int $offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+
+        try
+        {
+            $dp->insertBefore( $secondCfg, 1 );
+            $this->fail( 'ezcBaseValueException not thrown on to large int 
$offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+
+        $this->assertAttributeEquals(
+            array(
+                0  => $firstCfg,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Default properties not created correctly on empty ctor.'
+        );
+    }
+
+    public function testCreateTransportDefaultCtorSuccess()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( '' )
+        );
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( 'Foo' )
+        );
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( 'Nautilus' )
+        );
+    }
+
+    public function testCreateTransportMultipleConfigsSuccess()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $ms = new ezcWebdavTransportConfiguration( '(^.*micro\\$oft.*$)i' );
+        $gn = new ezcWebdavTransportConfiguration( '(^.*nautilus.*$)i', 
'fooCustomTransport' );
+        $kd = new ezcWebdavTransportConfiguration( '(^.*konqueror.*$)i' );
+        $ca = new ezcWebdavTransportConfiguration( '(^.*cadaver.*$)i' );
+        
+        $dp->insertBefore( $ms, 0 );
+        $dp->insertBefore( $gn, 0 );
+        $dp->insertBefore( $kd, 0 );
+        $dp->insertBefore( $ca, 0 );
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( '' ),
+            'Default transport not created on none-matching User-Agent.'
+        );
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( 'Mirco$soft Internet Explorer 66.6beta1' ),
+            'Transport not correctly selected, $ms'
+        );
+
+        $this->assertEquals(
+            new fooCustomTransport(),
+            $dp->createTransport( 'Gentoo-2.6.22-r8, Gnome 2.18.2-rc2, 
Nautilus' ),
+            'Transport not correctly selected, $gn'
+        );
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( 'Gentoo-2.6.22-r8, KDE Foo Bar, 
Konqueror-X.Y.Z, libneon-a.b.c-alpha23' ),
+            'Transport not correctly selected, $kd'
+        );
+    }
+
+    public function testCreateTransportFailure()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+        unset( $dp[0] );
+
+        try
+        {
+            $dp->createTransport( 'Fooo Bar' );
+            $this->fail( 'Creating transport does not fail without any 
configs.' );
+        }
+        catch ( ezcWebdavMissingTransportConfigurationException $e ) {}
+
+        $unmatching = new ezcWebdavTransportConfiguration( 
'(^.*micro\$oft.*)i' );
+
+        $dp[] = $unmatching;
+
+        try
+        {
+            $dp->createTransport( 'Fooo Bar' );
+            $this->fail( 'Creating transport does not fail without any 
configs.' );
+        }
+        catch ( ezcWebdavMissingTransportConfigurationException $e ) {}
+
+        $this->assertEquals(
+            new ezcWebdavTransport(),
+            $dp->createTransport( 'some MiCrO$OfT client' ),
+            'Transport not created correctly with match.'
+        );
+    }
+
+    public function testOffsetSetSuccess()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new ezcWebdavTransportConfiguration( '(b)' );
+
+        $dp      = new ezcWebdavTransportDispatcher();
+        $dp[1]   = $first;
+        $dp[]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        $dp[0]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => $second,
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+    }
+
+    public function testOffsetSetFailure()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new stdClass();
+
+        $dp      = new ezcWebdavTransportDispatcher();
+
+        try
+        {
+            $dp[2]   = $first;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
too large offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            $dp[-2]   = $first;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
too small offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            $dp['foo']   = $first;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
invalid offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+        
+        try
+        {
+            $dp[]    = $second;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
invalid value and null offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+        
+        try
+        {
+            $dp[]    = $second;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
invalid value and null offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+        
+        try
+        {
+            $dp[0]    = $second;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
invalid value and 0 offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+        
+        try
+        {
+            $dp[1]    = $second;
+            $this->fail( 'ezcBaseValueException not thrown on set access with 
invalid value and 1 offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+    }
+
+    public function testOffsetGetSuccess()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new ezcWebdavTransportConfiguration( '(b)' );
+
+        $dp      = new ezcWebdavTransportDispatcher();
+        $dp[1]   = $first;
+        $dp[]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        $this->assertEquals(
+            new ezcWebdavTransportConfiguration(),
+            $dp[0],
+            'Index 2 not got correctly.'
+        );
+
+        $this->assertSame(
+            $first,
+            $dp[1],
+            'Index 2 not got correctly.'
+        );
+
+        $this->assertSame(
+            $second,
+            $dp[2],
+            'Index 2 not got correctly.'
+        );
+    }
+
+    public function testOffsetGetFailure()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new stdClass();
+
+        $dp      = new ezcWebdavTransportDispatcher();
+
+        try
+        {
+            echo $dp[2];
+            $this->fail( 'ezcBaseValueException not thrown on get access with 
too large offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            echo $dp[-2];
+            $this->fail( 'ezcBaseValueException not thrown on get access with 
too small offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            echo $dp['foo'];
+            $this->fail( 'ezcBaseValueException not thrown on get access with 
invalid offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+    }
+
+    public function testOffsetUnsetSuccess()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new ezcWebdavTransportConfiguration( '(b)' );
+
+        $dp      = new ezcWebdavTransportDispatcher();
+        $dp[1]   = $first;
+        $dp[]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        unset( $dp[1] );
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        unset( $dp[1] );
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        unset( $dp[0] );
+        
+        $this->assertAttributeEquals(
+            array(
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+    }
+
+    public function testOffsetUnsetFailure()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new stdClass();
+
+        $dp      = new ezcWebdavTransportDispatcher();
+
+        try
+        {
+            unset( $dp[2] );
+            $this->fail( 'ezcBaseValueException not thrown on unset access 
with too large offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            unset( $dp[-2] );
+            $this->fail( 'ezcBaseValueException not thrown on unset access 
with too small offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        try
+        {
+            unset( $dp['foo'] );
+            $this->fail( 'ezcBaseValueException not thrown on unset access 
with invalid offset.' );
+        }
+        catch ( ezcBaseValueException $e ) {}
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+    }
+
+    public function testOffsetExistsSuccess()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new ezcWebdavTransportConfiguration( '(b)' );
+
+        $dp      = new ezcWebdavTransportDispatcher();
+        $dp[1]   = $first;
+        $dp[]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        $this->assertTrue(
+            isset( $dp[0] ),
+            'Offset 0 does not seem to be set.'
+        );
+        $this->assertTrue(
+            isset( $dp[1] ),
+            'Offset 1 does not seem to be set.'
+        );
+        $this->assertTrue(
+            isset( $dp[2] ),
+            'Offset 2 does not seem to be set.'
+        );
+    }
+
+    public function testOffsetExistsFailure()
+    {
+        $first   = new ezcWebdavTransportConfiguration( '(a)' );
+        $second  = new ezcWebdavTransportConfiguration( '(b)' );
+
+        $dp      = new ezcWebdavTransportDispatcher();
+        $dp[1]   = $first;
+        $dp[]    = $second;
+        
+        $this->assertAttributeEquals(
+            array(
+                0 => new ezcWebdavTransportConfiguration(),
+                1 => $first,
+                2 => $second,
+            ),
+            'transportConfigurations',
+            $dp,
+            'Configurations not added correctly through offsetSet().'
+        );
+
+        $this->assertFalse(
+            isset( $dp[-1] ),
+            'Offset -1 does seem to be set.'
+        );
+        $this->assertFalse(
+            isset( $dp[3] ),
+            'Offset 3 does seem to be set.'
+        );
+        $this->assertFalse(
+            isset( $dp['foo'] ),
+            'Offset "foo" does seem to be set.'
+        );
+    }
+
+    public function testIteratorDefaultCtor()
+    {
+        $dp = new ezcWebdavTransportDispatcher();
+
+        $fake = array(
+            0 => new ezcWebdavTransportConfiguration(),
+        );
+        
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+
+        // Try if rewind works
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+    }
+
+    public function testIteratorMultipleElements()
+    {
+        $dp   = new ezcWebdavTransportDispatcher();
+        $dp[] = new ezcWebdavTransportConfiguration( '(.*nautilus.*)i' );
+        $dp[] = new ezcWebdavTransportConfiguration( '(.*konqueror.*)i' );
+
+        $fake = array(
+            0 => new ezcWebdavTransportConfiguration(),
+            1 => new ezcWebdavTransportConfiguration( '(.*nautilus.*)i' ),
+            2 => new ezcWebdavTransportConfiguration( '(.*konqueror.*)i' ),
+        );
+        
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+
+        // Try if rewind works
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+    }
+
+    public function testIteratorEmpty()
+    {
+        $dp   = new ezcWebdavTransportDispatcher();
+        unset( $dp[0] );
+
+        $fake = array();
+        
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+
+        // Try if rewind works
+        $i = 0;
+        foreach( $dp as $key => $val )
+        {
+            $this->assertEquals(
+                $i,
+                $key,
+                "ID missmatch during iteration"
+            );
+            $this->assertTrue(
+                isset( $fake[$key] ),
+                "Fake key '$key' not set"
+            );
+            $this->assertEquals(
+                $fake[$key],
+                $val,
+                'Value missmatch'
+            );
+            ++$i;
+        }
+    }
+}
+
+?>

Propchange: trunk/Webdav/tests/transport_dispatcher_test.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to