Author: ts
Date: Tue Sep 25 07:07:53 2007
New Revision: 6259
Log:
- Fixed path factory.
- Added path factory tests.
Added:
trunk/Webdav/tests/path_factory_test.php (with props)
Modified:
trunk/Webdav/src/path_factory.php
trunk/Webdav/tests/suite.php
Modified: trunk/Webdav/src/path_factory.php
==============================================================================
--- trunk/Webdav/src/path_factory.php [iso-8859-1] (original)
+++ trunk/Webdav/src/path_factory.php [iso-8859-1] Tue Sep 25 07:07:53 2007
@@ -32,6 +32,19 @@
* @var array(string=>string)
*/
protected $baseUriParts;
+
+
+ /**
+ * Caches pathes that are a collection.
+ *
+ * Those will get a '/' appended on reserialization. Works only if they had
+ * been unserialized before.
+ *
+ * @todo This is a temporary hack to satisfy memory backend and RFC.
+ *
+ * @var array(string=>bool)
+ */
+ protected $collectionPathes = array();
/**
* Creates a new path factory.
@@ -62,7 +75,9 @@
$requestPath = parse_url( trim( $uri ), PHP_URL_PATH );
if ( substr( $requestPath, -1, 1 ) === '/' )
{
+ // @todo This is a cleanup for the memory backend
$requestPath = substr( $requestPath, 0, -1 );
+ $this->collectionPathes[substr( $requestPath, ( isset(
$this->baseUriParts['path'] ) ? strlen( $this->baseUriParts['path'] ) : 0 ) )]
= true;
}
return substr( $requestPath, ( isset( $this->baseUriParts['path'] ) ?
strlen( $this->baseUriParts['path'] ) : 0 ) );
}
@@ -86,7 +101,7 @@
. ( isset( $this->baseUriParts['user'] ) || isset(
$this->baseUriParts['pass'] ) ? '@' : '' )
. $this->baseUriParts['host']
. ( isset( $this->baseUriParts['path'] ) ?
$this->baseUriParts['path'] : '' )
- . trim( $path )
+ . trim( $path ) . ( isset( $this->collectionPathes[$path] ) ? '/'
: '' )
. ( isset( $this->baseUriParts['query'] ) ? '?' .
$this->baseUriParts['query'] : '' )
. ( isset( $this->baseUriParts['fragment'] ) ? '#' .
$this->baseUriParts['fragment'] : '' );
}
Added: trunk/Webdav/tests/path_factory_test.php
==============================================================================
--- trunk/Webdav/tests/path_factory_test.php (added)
+++ trunk/Webdav/tests/path_factory_test.php [iso-8859-1] Tue Sep 25 07:07:53
2007
@@ -1,0 +1,179 @@
+<?php
+/**
+ * Basic test cases for the path factory 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';
+
+/**
+ * Custom path factpory
+ */
+require_once 'classes/custom_path_factory.php';
+
+/**
+ * Tests for ezcWebdavPathFactory class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ */
+class ezcWebdavPathFactoryTest extends ezcWebdavTestCase
+{
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite(
'ezcWebdavPathFactoryTest' );
+ }
+
+ public function testPathDispatchingWithoutBasePath()
+ {
+ $uri = '/collection/ressource';
+ $fakePath = $uri;
+
+ $factory = new ezcWebdavPathFactory( 'http://example.com' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testPathDispatchingWithBasePath()
+ {
+ $uri = '/my/webdav/base/collection/ressource';
+ $fakePath = '/collection/ressource';
+
+ $factory = new ezcWebdavPathFactory(
'http://example.com/my/webdav/base' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testPathDispatchingCollectionWithoutBasePath()
+ {
+ $uri = '/collection/another_coll/';
+ $fakePath = '/collection/another_coll';
+
+ $factory = new ezcWebdavPathFactory( 'http://example.com' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testPathDispatchingCollectionWithBasePath()
+ {
+ $uri = '/my/webdav/base/collection/another_coll';
+ $fakePath = '/collection/another_coll';
+
+ $factory = new ezcWebdavPathFactory(
'http://example.com/my/webdav/base' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testUriDispatchingWithoutBasePath()
+ {
+ $uri = 'http://example.com/collection/ressource';
+ $fakePath = '/collection/ressource';
+
+ $factory = new ezcWebdavPathFactory( 'http://example.com' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testUriDispatchingWithBasePath()
+ {
+ $uri = 'http://example.com/my/webdav/base/collection/ressource';
+ $fakePath = '/collection/ressource';
+
+ $factory = new ezcWebdavPathFactory(
'http://example.com/my/webdav/base' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testUriDispatchingCollectionWithoutBasePath()
+ {
+ $uri = 'http://example.com/collection/another_coll/';
+ $fakePath = '/collection/another_coll';
+
+ $factory = new ezcWebdavPathFactory( 'http://example.com' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testUriDispatchingCollectionWithBasePath()
+ {
+ $uri = 'http://example.com/my/webdav/base/collection/another_coll';
+ $fakePath = '/collection/another_coll';
+
+ $factory = new ezcWebdavPathFactory(
'http://example.com/my/webdav/base' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri )
+ );
+ }
+
+ public function testUriDispatchingCollectionWithoutBasePathRestore()
+ {
+ $uri = 'http://example.com/collection/another_coll/';
+ $fakePath = '/collection/another_coll';
+ $fakeUri = $uri;
+
+ $factory = new ezcWebdavPathFactory( 'http://example.com' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri ),
+ 'Parsing of URI failed.'
+ );
+ $this->assertEquals(
+ $fakeUri,
+ $factory->generateUriFromPath( $fakePath ),
+ 'Restoring of URI failed'
+ );
+ }
+
+ public function testUriDispatchingCollectionWithBaseUriRestore()
+ {
+ $uri =
'http://example.com/my/webdav/base/collection/another_coll/';
+ $fakePath = '/collection/another_coll';
+ $fakeUri = $uri;
+
+ $factory = new ezcWebdavPathFactory(
'http://example.com/my/webdav/base' );
+
+ $this->assertEquals(
+ $fakePath,
+ $factory->parseUriToPath( $uri ),
+ 'Parsing of URI failed.'
+ );
+ $this->assertEquals(
+ $fakeUri,
+ $factory->generateUriFromPath( $fakePath ),
+ 'Restoring of URI failed'
+ );
+ }
+}
+?>
Propchange: trunk/Webdav/tests/path_factory_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 Sep 25 07:07:53 2007
@@ -24,6 +24,7 @@
require_once 'backend_file_test.php';
require_once 'backend_file_options_test.php';
+require_once 'path_factory_test.php';
require_once 'path_factory_automatic_test.php';
require_once 'property_storage_test.php';
@@ -120,6 +121,7 @@
// $this->addTest( ezcWebdavFileBackendTest::suite() );
// $this->addTest( ezcWebdavFileBackendOptionsTestCase::suite() );
+ $this->addTest( ezcWebdavPathFactoryTest::suite() );
$this->addTest( ezcWebdavAutomaticPathFactoryTest::suite() );
$this->addTest( ezcWebdavClientRfcTest::suite() );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components