Author: ts
Date: Wed Sep 19 19:27:35 2007
New Revision: 6208
Log:
- Started response generation testing.
- Added factory class for different RFC backend setups.
- Added custom path factory to combine RFC input with memory backend.
Added:
trunk/Webdav/tests/classes/rfc_path_factory.php (with props)
trunk/Webdav/tests/client_test_rfc_backend.php (with props)
Modified:
trunk/Webdav/src/interfaces/response.php
trunk/Webdav/tests/client_test.php
trunk/Webdav/tests/client_test_rfc.php
trunk/Webdav/tests/clients/cadaver/propfind/request/result.ser
trunk/Webdav/tests/clients/cadaver/propfind_extended/request/result.ser
trunk/Webdav/tests/clients/rfc/copy/request/result.ser
trunk/Webdav/tests/clients/rfc/copy_collection/request/result.ser
trunk/Webdav/tests/clients/rfc/copy_overwrite/request/result.ser
trunk/Webdav/tests/clients/rfc/copy_success/request/result.ser
trunk/Webdav/tests/clients/rfc/delete/request/result.ser
trunk/Webdav/tests/clients/rfc/lock_1/request/result.ser
trunk/Webdav/tests/clients/rfc/lock_2/request/result.ser
trunk/Webdav/tests/clients/rfc/lock_3/request/result.ser
trunk/Webdav/tests/clients/rfc/lockdiscovery/request/result.ser
trunk/Webdav/tests/clients/rfc/mkcol/request/result.ser
trunk/Webdav/tests/clients/rfc/move_collection/request/result.ser
trunk/Webdav/tests/clients/rfc/move_resource/request/result.ser
trunk/Webdav/tests/clients/rfc/propfind_allprop/request/result.ser
trunk/Webdav/tests/clients/rfc/propfind_prop/request/result.ser
trunk/Webdav/tests/clients/rfc/propfind_propname/request/result.ser
trunk/Webdav/tests/clients/rfc/proppatch/request/result.ser
trunk/Webdav/tests/clients/rfc/supportedlock/request/result.ser
trunk/Webdav/tests/clients/rfc/unlock/request/result.ser
Modified: trunk/Webdav/src/interfaces/response.php
==============================================================================
--- trunk/Webdav/src/interfaces/response.php [iso-8859-1] (original)
+++ trunk/Webdav/src/interfaces/response.php [iso-8859-1] Wed Sep 19 19:27:35
2007
@@ -204,6 +204,11 @@
return isset( $this->headers[$headerName] ) ?
$this->headers[$headerName] : null;
}
+ public final function getHeaders()
+ {
+ return $this->headers;
+ }
+
/**
* Sets a property.
* This method is called when an property is to be set.
Added: trunk/Webdav/tests/classes/rfc_path_factory.php
==============================================================================
--- trunk/Webdav/tests/classes/rfc_path_factory.php (added)
+++ trunk/Webdav/tests/classes/rfc_path_factory.php [iso-8859-1] Wed Sep 19
19:27:35 2007
@@ -1,0 +1,16 @@
+<?php
+
+class ezcWebdavRfcPathFactory
+{
+ public static function parsePath( $requestPath, $base = null )
+ {
+ $path = parse_url( $requestPath, PHP_URL_PATH );
+ if ( substr( $path, -1, 1 ) === '/' )
+ {
+ $path = substr( $path, 0, -1 );
+ }
+ return $path;
+ }
+}
+
+?>
Propchange: trunk/Webdav/tests/classes/rfc_path_factory.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Webdav/tests/client_test.php
==============================================================================
--- trunk/Webdav/tests/client_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test.php [iso-8859-1] Wed Sep 19 19:27:35 2007
@@ -6,6 +6,10 @@
protected $dataDir;
protected $transportClass;
+
+ protected $setupClass;
+
+ protected $pathFactory = 'ezcWebdavPathFactory';
private $testSets = array();
@@ -41,6 +45,7 @@
public function setTestSet( $testSet )
{
$this->currentTestSet = $testSet;
+ $this->setName( basename( $testSet ) );
}
public function runTest()
@@ -56,6 +61,11 @@
protected function runTestSet( $testSetName )
{
$requestObject = null;
+
+ $serverBase = array(
+ 'DOCUMENT_ROOT' => '/var/www/localhost/htdocs',
+ 'SCRIPT_FILENAME' => '/var/www/localhost/htdocs',
+ );
// Request test
if ( file_exists( ( $requestDir = "{$testSetName}/request" ) ) ===
true )
@@ -63,21 +73,27 @@
// Settings
$request = array();
$request['result'] = $this->getFileContent( $requestDir, 'result'
);
- $request['server'] = $this->getFileContent( $requestDir, 'server'
);
+ $request['server'] = array_merge( $serverBase,
$this->getFileContent( $requestDir, 'server' ) );
$request['body'] = $this->getFileContent( $requestDir, 'body' );
$request['uri'] = $this->getFileContent( $requestDir, 'uri' );
$requestObject = $this->runRequestTest( $request );
+
}
// Response test
- if ( file_exists( ( $responseDir = "{$this->dataDir}/response" ) ) ===
true && $requestObject !== null )
- {
+ if ( file_exists( ( $responseDir = "{$testSetName}/response" ) ) ===
true && $requestObject instanceof ezcWebdavRequest && $this->setupClass !==
null )
+ {
+ $requestObject->validateHeaders();
+
// Settings
$response = array();
- $response['result'] = $this->getFileContent( $responseDir,
'result' );
+ $response['result'] = $this->getFileContent( $responseDir,
'result' );
$response['headers'] = $this->getFileContent( $responseDir,
'headers' );
- $response['body'] = $this->getFileContent( $responseDir, 'body'
);
+ $response['body'] = $this->getFileContent( $responseDir, 'body'
);
+ $response['code'] = $this->getFileContent( $responseDir, 'code'
);
+ $response['name'] = $this->getFileContent( $responseDir, 'name'
);
+ $response['backend'] = call_user_func( array( $this->setupClass,
'getSetup' ), basename( $testSetName ) );
$responseObject = $this->runResponseTest( $response,
$requestObject );
}
@@ -119,7 +135,10 @@
$_SERVER = ( $request['server'] !== false ? $request['server'] :
$_SERVER );
// Optionally set an URI different from 'http://localhost/webdav.php'
- $uri = ( $request['uri'] !== false ? $request['uri'] :
'http://localhost/webdav.php' );
+ $uri = ( $request['uri'] !== false
+ ? call_user_func( array( $this->pathFactory, 'parsePath' ),
$request['uri'] )
+ : '/webdav.php'
+ );
// Setup test environment
$transportClass = $this->transportClass;
@@ -142,11 +161,99 @@
$result,
"Result not parsed correctly for test set
'{$this->currentTestSet}'."
);
+
+ return $result;
}
protected function runResponseTest( array $response, ezcWebdavRequest
$requestObject )
{
- // To be implemented...
+ switch( get_class( $requestObject ) )
+ {
+ case 'ezcWebdavGetRequest':
+ $responseObject = $response['backend']->get( $requestObject );
+ break;
+ case 'ezcWebdavHeadRequest':
+ $responseObject = $response['backend']->head( $requestObject );
+ break;
+ case 'ezcWebdavPropFindRequest':
+ $responseObject = $response['backend']->propFind(
$requestObject );
+ break;
+ case 'ezcWebdavPropPatchRequest':
+ $responseObject = $response['backend']->propPatch(
$requestObject );
+ break;
+ case 'ezcWebdavDeleteRequest':
+ if ( $requestObject instanceof ezcWebdavBackendChange )
+ {
+ $responseObject = $response['backend']->delete(
$requestObject );
+ }
+ else
+ {
+ $this->fail( 'Backend does not support testing DELETE
request.' );
+ }
+ break;
+ case 'ezcWebdavCopyRequest':
+ if ( $requestObject instanceof ezcWebdavBackendChange )
+ {
+ $responseObject = $response['backend']->copy(
$requestObject );
+ }
+ else
+ {
+ $this->fail( 'Backend does not support testing COPY
request.' );
+ }
+ break;
+ case 'ezcWebdavMoveRequest':
+ if ( $requestObject instanceof ezcWebdavBackendChange )
+ {
+ $responseObject = $response['backend']->move(
$requestObject );
+ }
+ else
+ {
+ $this->fail( 'Backend does not support testing MOVE
request.' );
+ }
+ break;
+ case 'ezcWebdavMakeCollectionRequest':
+ if ( $requestObject instanceof ezcWebdavBackendMakeCollection )
+ {
+ $responseObject = $response['backend']->makeCollection(
$requestObject );
+ }
+ else
+ {
+ $this->fail( 'Backend does not support testing MKCOL
request.' );
+ }
+ break;
+ case 'ezcWebdavPutRequest':
+ if ( $requestObject instanceof ezcWebdavBackendPut )
+ {
+ $responseObject = $response['backend']->put(
$requestObject );
+ }
+ else
+ {
+ $this->fail( 'Backend does not support testing PUT
request.' );
+ }
+ break;
+ default:
+ throw new PHPUnit_Framework_ExpectationFailedException(
"Unable to dispatch request of class " . get_class( $requestObject ) );
+ }
+
+ $this->assertEquals(
+ $response['code'],
+ $responseObject->status,
+ "Request returned status code '{$responseObject->status}' instead
of '{$response['code']}' '{$requestObject->requestUri}'."
+ );
+
+ foreach ( $response['headers'] as $headerName => $headerValue )
+ {
+ if ( $headerName !== 'Content-Type' && $headerName !==
'Content-Length' )
+ {
+ $this->assertEquals(
+ $headerValue,
+ $responseObject->getHeader( $headerName ),
+ "Header '$headerName' not set to value '$headerValue'."
+ );
+ }
+ }
+
+ return $responseObject;
}
}
Modified: trunk/Webdav/tests/client_test_rfc.php
==============================================================================
--- trunk/Webdav/tests/client_test_rfc.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_rfc.php [iso-8859-1] Wed Sep 19 19:27:35 2007
@@ -1,6 +1,8 @@
<?php
require_once 'classes/transport_test_mock.php';
+require_once 'classes/rfc_path_factory.php';
+require_once 'client_test_rfc_backend.php';
require_once 'client_test_suite.php';
require_once 'client_test.php';
@@ -11,6 +13,8 @@
{
$this->transportClass = 'ezcWebdavTransportTestMock';
$this->dataDir = dirname( __FILE__ ) . '/clients/rfc';
+ $this->setupClass = 'ezcWebdavClientRfcTestBackend';
+ $this->pathFactory = 'ezcWebdavRfcPathFactory';
}
public static function suite()
Added: trunk/Webdav/tests/client_test_rfc_backend.php
==============================================================================
--- trunk/Webdav/tests/client_test_rfc_backend.php (added)
+++ trunk/Webdav/tests/client_test_rfc_backend.php [iso-8859-1] Wed Sep 19
19:27:35 2007
@@ -1,0 +1,165 @@
+<?php
+
+class ezcWebdavClientRfcTestBackend
+{
+ public static function getSetup( $testSetName )
+ {
+ switch( $testSetName )
+ {
+ case 'propfind_propname':
+ case 'lockdiscovery':
+ case 'supportedlock':
+ case 'propfind_allprop':
+ case 'move_collection':
+ case 'copy_collection':
+ return self::getFooBarSetup();
+ default:
+ throw new RuntimeException( "Could not find setup for test set
'$testSetName'." );
+ }
+ }
+
+ protected static function getFooBarSetup()
+ {
+ $backend = new ezcWebdavMemoryBackend();
+ $backend->addContents(
+ array(
+ 'container' => array(
+ 'front.html' => '',
+ ),
+ )
+ );
+
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavDeadProperty(
+ 'http://www.foo.bar/boxschema/',
+ 'bigbox',
+ <<<EOT
+<?xml version="1.0" encoding="utf-8" ?>
+<R:bigbox xmlns:R="http://www.foo.bar/boxschema/">
+<R:BoxType>Box type A</R:BoxType>
+</R:bigbox>
+EOT
+ )
+ );
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavDeadProperty(
+ 'http://www.foo.bar/boxschema/',
+ 'author',
+ <<<EOT
+<?xml version="1.0" encoding="utf-8" ?>
+<R:author xmlns:R="http://www.foo.bar/boxschema/">
+<R:Name>Hadrian</R:Name>
+</R:author>
+EOT
+ )
+ );
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavCreationDateProperty(
+ new DateTime( '1997-12-01T17:42:21-08:00' )
+ )
+ );
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavDisplayNameProperty(
+ 'Example collection'
+ )
+ );
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavResourceTypeProperty(
+ 'collection'
+ )
+ );
+ $backend->setProperty(
+ '/container',
+ new ezcWebdavSupportedLockProperty(
+ array(
+ new ezcWebdavSupportedLockPropertyLockentry(
+ ezcWebdavLockRequest::TYPE_WRITE,
+ ezcWebdavLockRequest::SCOPE_EXCLUSIVE
+ ),
+ new ezcWebdavSupportedLockPropertyLockentry(
+ ezcWebdavLockRequest::TYPE_WRITE,
+ ezcWebdavLockRequest::SCOPE_SHARED
+ ),
+ )
+ )
+ );
+
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavDeadProperty(
+ 'http://www.foo.bar/boxschema/',
+ 'bigbox',
+ <<<EOT
+<?xml version="1.0" encoding="utf-8" ?>
+<R:bigbox xmlns:R="http://www.foo.bar/boxschema/">
+<R:BoxType>Box type B</R:BoxType>
+</R:bigbox>
+EOT
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavCreationDateProperty(
+ new DateTime( '1997-12-01T18:27:21-08:00' )
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavDisplayNameProperty(
+ 'Example HTML resource'
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavGetContentLengthProperty(
+ '4525'
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavGetContentTypeProperty(
+ 'text/html'
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavGetEtagProperty(
+ 'zzyzx'
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavGetLastModifiedProperty(
+ new DateTime( 'Monday, 12-Jan-98 09:25:56 GMT' )
+ )
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavResourceTypeProperty()
+ );
+ $backend->setProperty(
+ '/container/front.html',
+ new ezcWebdavSupportedLockProperty(
+ array(
+ new ezcWebdavSupportedLockPropertyLockentry(
+ ezcWebdavLockRequest::TYPE_WRITE,
+ ezcWebdavLockRequest::SCOPE_EXCLUSIVE
+ ),
+ new ezcWebdavSupportedLockPropertyLockentry(
+ ezcWebdavLockRequest::TYPE_WRITE,
+ ezcWebdavLockRequest::SCOPE_SHARED
+ ),
+ )
+ )
+ );
+
+ return $backend;
+ }
+}
+
+?>
Propchange: trunk/Webdav/tests/client_test_rfc_backend.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Webdav/tests/clients/cadaver/propfind/request/result.ser
==============================================================================
Binary files - no diff available.
Modified:
trunk/Webdav/tests/clients/cadaver/propfind_extended/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/copy/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/copy_collection/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/copy_overwrite/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/copy_success/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/delete/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/lock_1/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/lock_2/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/lock_3/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/lockdiscovery/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/mkcol/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/move_collection/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/move_resource/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/propfind_allprop/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/propfind_prop/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/propfind_propname/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/proppatch/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/supportedlock/request/result.ser
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/tests/clients/rfc/unlock/request/result.ser
==============================================================================
Binary files - no diff available.
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components