Author: ts
Date: Wed Sep 19 15:25:05 2007
New Revision: 6199
Log:
- Added test for LOCK request.
- Added script used for converting RFC tests.
- Refactored test suite for human readability.
Added:
trunk/Webdav/tests/clients/rfc/convert.php (with props)
trunk/Webdav/tests/request_lock_test.php (with props)
Modified:
trunk/Webdav/design/class_diagram.png
trunk/Webdav/src/properties/lockdiscovery_activelock.php
trunk/Webdav/src/properties/supportedlock_lockentry.php
trunk/Webdav/tests/suite.php
Modified: trunk/Webdav/design/class_diagram.png
==============================================================================
Binary files - no diff available.
Modified: trunk/Webdav/src/properties/lockdiscovery_activelock.php
==============================================================================
--- trunk/Webdav/src/properties/lockdiscovery_activelock.php [iso-8859-1]
(original)
+++ trunk/Webdav/src/properties/lockdiscovery_activelock.php [iso-8859-1] Wed
Sep 19 15:25:05 2007
@@ -30,16 +30,16 @@
/**
* Creates a new ezcWebdavSupportedLockPropertyLockentry.
*
- * @param int $lockType Lock type (constant
ezcWebdavLockRequest::TYPE__*).
- * @param int $lockScope Lock scope (constant
ezcWebdavLockRequest::SCOPE__*).
+ * @param int $lockType Lock type (constant
ezcWebdavLockRequest::TYPE_*).
+ * @param int $lockScope Lock scope (constant
ezcWebdavLockRequest::SCOPE_*).
* @param int $depth Lock depth (constant
ezcWebdavRequest::DEPTH_*).
* @param string $owner
* @param DateTime $timeout
* @param array(string) $tokens
* @return void
*/
- public function __construct( $lockType =
ezcWebdavLockRequest::TYPE__READ,
- $lockScope =
ezcWebdavLockRequest::SCOPE__SHARED,
+ public function __construct( $lockType =
ezcWebdavLockRequest::TYPE_READ,
+ $lockScope =
ezcWebdavLockRequest::SCOPE_SHARED,
$depth =
ezcWebdavRequest::DEPTH_INFINITY,
$owner = null,
DateTime $timeout = null,
@@ -133,8 +133,8 @@
{
parent::clear();
- $this->properties['lockType'] = ezcWebdavLockRequest::TYPE__READ;
- $this->properties['lockScope'] = ezcWebdavLockRequest::SCOPE__SHARED;
+ $this->properties['lockType'] = ezcWebdavLockRequest::TYPE_READ;
+ $this->properties['lockScope'] = ezcWebdavLockRequest::SCOPE_SHARED;
$this->properties['depth'] = ezcWebdavRequest::DEPTH_INFINITY;
$this->properties['tokens'] = array();
}
Modified: trunk/Webdav/src/properties/supportedlock_lockentry.php
==============================================================================
--- trunk/Webdav/src/properties/supportedlock_lockentry.php [iso-8859-1]
(original)
+++ trunk/Webdav/src/properties/supportedlock_lockentry.php [iso-8859-1] Wed
Sep 19 15:25:05 2007
@@ -27,7 +27,7 @@
* @param int $lockScope Lock scope (constant SCOPE_*).
* @return void
*/
- public function __construct( $lockType = ezcWebdavLockRequest::TYPE__READ,
$lockScope = ezcWebdavLockRequest::SCOPE__SHARED )
+ public function __construct( $lockType = ezcWebdavLockRequest::TYPE_READ,
$lockScope = ezcWebdavLockRequest::SCOPE_SHARED )
{
parent::__construct( 'lockentry' );
@@ -55,7 +55,7 @@
switch ( $propertyName )
{
case 'lockType':
- if ( $propertyValue !== ezcWebdavLockRequest::TYPE__READ &&
$propertyValue !== ezcWebdavLockRequest::TYPE__WRITE )
+ if ( $propertyValue !== ezcWebdavLockRequest::TYPE_READ &&
$propertyValue !== ezcWebdavLockRequest::TYPE_WRITE )
{
throw new ezcBaseValueException( $propertyName,
$propertyValue, 'ezcWebdavLockRequest::TYPE_*' );
}
@@ -64,7 +64,7 @@
break;
case 'lockScope':
- if ( $propertyValue !== ezcWebdavLockRequest::SCOPE__SHARED &&
$propertyValue !== ezcWebdavLockRequest::SCOPE__EXCLUSIVE )
+ if ( $propertyValue !== ezcWebdavLockRequest::SCOPE_SHARED &&
$propertyValue !== ezcWebdavLockRequest::SCOPE_EXCLUSIVE )
{
throw new ezcBaseValueException( $propertyName,
$propertyValue, 'ezcWebdavLockRequest::SCOPE_*' );
}
@@ -101,8 +101,8 @@
{
parent::clear();
- $this->properties['lockType'] = ezcWebdavLockRequest::TYPE__READ;
- $this->properties['lockScope'] = ezcWebdavLockRequest::SCOPE__SHARED;
+ $this->properties['lockType'] = ezcWebdavLockRequest::TYPE_READ;
+ $this->properties['lockScope'] = ezcWebdavLockRequest::SCOPE_SHARED;
}
}
Added: trunk/Webdav/tests/clients/rfc/convert.php
==============================================================================
--- trunk/Webdav/tests/clients/rfc/convert.php (added)
+++ trunk/Webdav/tests/clients/rfc/convert.php [iso-8859-1] Wed Sep 19 15:25:05
2007
@@ -1,0 +1,224 @@
+<?php
+
+$files = glob( './*.txt' );
+
+foreach ( $files as $testDataFile )
+{
+ $content = array_map( 'rtrim', file( $testDataFile ) );
+
+ $request = array(
+ 'server' => array(),
+ 'body' => '',
+ 'uri' => '',
+ );
+
+ $response = array(
+ 'headers' => array(),
+ 'body' => '',
+ 'code' => null,
+ 'name' => '',
+ );
+
+ $mode = 'start';
+ $lastHeader = '';
+ foreach ( $content as $no => $line )
+ {
+ switch ( $mode )
+ {
+ case 'start':
+ if ( $line == '' )
+ {
+ $mode = 'read_request_head';
+ }
+ break;
+ case 'read_request_head':
+ if ( preg_match( '(^(\w+)\s+(\S+)\s+(\S+)$)', $line, $matches
) < 1 )
+ {
+ throw new RuntimeException( "Could not match '$mode' on
line $no '$line' of file $testDataFile." );
+ }
+ $request['server']['REQUEST_METHOD'] = $matches[1];
+ $request['server']['REQUEST_URI'] = $matches[2];
+ $request['server']['SERVER_PROTOCOL'] = $matches[3];
+ $mode = 'read_blank_before_request_headers';
+ break;
+ case 'read_blank_before_request_headers':
+ $mode = 'read_request_headers';
+ // break;
+ case 'read_request_headers':
+ if ( preg_match( '(^(\S+):\s+(.+)$)', $line, $matches ) > 0 )
+ {
+ switch( strtolower( $matches[1] ) )
+ {
+ case 'host':
+ $request['server']['HTTP_HOST'] = $matches[2];
+ $lastHeader = 'HTTP_HOST';
+ break;
+ case 'content-type':
+ $request['server']['CONTENT_TYPE'] = $matches[2];
+ $lastHeader = 'CONTENT_TYPE';
+ break;
+ case 'content-length':
+ // Workaround for RFC dummy
+ $request['server']['HTTP_CONTENT_LENGTH'] = (
$matches[2] === 'xxxx' ? "1234" : $matches[2] );
+ $lastHeader = 'HTTP_CONTENT_LENGTH';
+ break;
+ case 'depth':
+ $request['server']['HTTP_DEPTH'] = $matches[2];
+ $lastHeader = 'HTTP_DEPTH';
+ break;
+ // @TODO Guessed from here, need validation!
+ case 'destination':
+ $request['server']['HTTP_DESTINATION'] =
$matches[2];
+ $lastHeader = 'HTTP_DESTINATION';
+ break;
+ case 'overwrite':
+ $request['server']['HTTP_OVERWRITE'] = $matches[2];
+ $lastHeader = 'HTTP_OVERWRITE';
+ break;
+ case 'timeout':
+ $request['server']['HTTP_TIMEOUT'] = $matches[2];
+ $lastHeader = 'HTTP_TIMEOUT';
+ break;
+ case 'authorization':
+ $request['server']['HTTP_AUTH'] = $matches[2];
+ $lastHeader = 'HTTP_AUTH';
+ break;
+ case 'if':
+ $request['server']['HTTP_IF'] = $matches[2];
+ $lastHeader = 'HTTP_IF';
+ break;
+ case 'if':
+ $request['server']['HTTP_IF'] = $matches[2];
+ $lastHeader = 'HTTP_IF';
+ break;
+ case 'lock-token':
+ $request['server']['HTTP_LOCK_TOKEN'] =
$matches[2];
+ $lastHeader = 'HTTP_LOCK_TOKEN';
+ break;
+
+ default:
+ echo "Unknown Header: '$matches[1]' =
'$matches[2]'\n";
+ $lastHeader = $matches[1];
+ }
+ }
+ else if ( preg_match( '(^ (.*)$)', $line, $matches ) > 0 )
+ {
+ $request['server'][$lastHeader] .= ' ' . $matches[1];
+ }
+ else
+ {
+ $mode = 'read_request_body';
+ }
+ break;
+ case 'read_request_body':
+ if ( $line !== '' && $line !== '>>Response' )
+ {
+ $request['body'] .= $line . "\n";
+ }
+ else
+ {
+ $mode = 'start_response';
+ }
+ break;
+ case 'start_response':
+ if ( $line === '' )
+ {
+ $mode = 'read_response_head';
+ }
+ break;
+ case 'read_blank_before_response':
+ $mode = 'read_response_head';
+ break;
+ case 'read_response_head':
+ if ( preg_match( '(^(\S+)\s+([0-9]+)\s+(.*)$)', $line,
$matches ) < 1 )
+ {
+ var_dump( $request );
+ throw new RuntimeException( "Could not match '$mode' on
$no '$line' of file '$testDataFile'." );
+ }
+ $response['code'] = $matches[2];
+ $response['name'] = $matches[3];
+ $mode = 'read_blank_before_response_headers';
+ case 'read_blank_before_response_headers':
+ $mode = 'read_response_headers';
+ break;
+ case 'read_response_headers':
+ if ( preg_match( '(^(\S+):\s+(.+)$)', $line, $matches ) > 0 )
+ {
+ $response['headers'][$matches[1]] = ( $matches[2] ===
'xxxx' ? 1234 : $matches[2] );
+ }
+ else
+ {
+ $mode = 'read_response_body';
+ }
+ break;
+ case 'read_response_body':
+ $response['body'] .= $line . "\n";
+ }
+ }
+
+ $fileInfo = pathinfo( $testDataFile );
+
+ if ( file_exists( ( $testSetBase =
"{$fileInfo['dirname']}/{$fileInfo['filename']}" ) ) === false )
+ {
+ mkdir( $testSetBase );
+ }
+ if ( file_exists( ( $requestBase = "{$testSetBase}/request" ) ) === false
)
+ {
+ mkdir( $requestBase );
+ }
+ if ( file_exists( ( $responseBase = "{$testSetBase}/response" ) ) ===
false )
+ {
+ mkdir( $responseBase );
+ }
+
+ $templates = array();
+ $templates['php'] = <<<EOT
+<?php
+
+return %s;
+
+?>
+EOT;
+
+ file_put_contents(
+ "{$requestBase}/server.php",
+ sprintf( $templates['php'], var_export( $request['server'], true ) )
+ );
+ file_put_contents(
+ "{$requestBase}/body.xml",
+ $request['body']
+ );
+ file_put_contents(
+ "{$requestBase}/uri.txt",
+ ( $request['uri'] === ''
+ ? ( 'http://' . ( isset( $request['server']['HTTP_HOST'] ) ?
$request['server']['HTTP_HOST'] : 'localhost' ) . ( isset(
$request['server']['REQUEST_URI'] ) ? $request['server']['REQUEST_URI'] : '/' )
)
+ : $request['uri'] )
+ );
+
+ file_put_contents(
+ "{$responseBase}/headers.php",
+ sprintf( $templates['php'], var_export( $response['headers'], true ) )
+ );
+ file_put_contents(
+ "{$responseBase}/body.xml",
+ $response['body']
+ );
+ file_put_contents(
+ "{$responseBase}/code.txt",
+ $response['code']
+ );
+ file_put_contents(
+ "{$responseBase}/name.txt",
+ $response['name']
+ );
+
+ $response = array(
+ 'headers' => array(),
+ 'body' => '',
+ 'code' => null,
+ 'name' => '',
+ );
+
+}
+
+?>
Propchange: trunk/Webdav/tests/clients/rfc/convert.php
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/Webdav/tests/request_lock_test.php
==============================================================================
--- trunk/Webdav/tests/request_lock_test.php (added)
+++ trunk/Webdav/tests/request_lock_test.php [iso-8859-1] Wed Sep 19 15:25:05
2007
@@ -1,0 +1,105 @@
+<?php
+/**
+ * File containing the ezcWebdavLockRequestTest class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogentag//
+ * @copyright Lockright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Reqiuire base test
+ */
+require_once 'request_test.php';
+
+/**
+ * Test case for the ezcWebdavLockRequest class.
+ *
+ * @package Webdav
+ * @subpackage Tests
+ * @version //autogentag//
+ * @copyright Lockright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcWebdavLockRequestTest extends ezcWebdavRequestTestCase
+{
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( __CLASS__ );
+ }
+
+ protected function setUp()
+ {
+ $this->className = 'ezcWebdavLockRequest';
+ $this->constructorArguments = array(
+ '/foo', '/bar'
+ );
+ $this->defaultValues = array(
+ 'lockInfo' => null,
+ );
+ $this->workingValues = array(
+ 'lockInfo' => array(
+ new ezcWebdavRequestLockInfoContent(
ezcWebdavLockRequest::SCOPE_EXCLUSIVE, ezcWebdavLockRequest::TYPE_WRITE ),
+ new ezcWebdavRequestLockInfoContent(
ezcWebdavLockRequest::SCOPE_SHARED, ezcWebdavLockRequest::TYPE_WRITE, 'Foo Bar'
),
+ new ezcWebdavRequestLockInfoContent(
ezcWebdavLockRequest::SCOPE_SHARED, ezcWebdavLockRequest::TYPE_WRITE,
'http://example.com/foo/bar' ),
+ null,
+ ),
+ );
+ $this->failingValues = array(
+ 'lockInfo' => array(
+ 23,
+ 23.34,
+ 'foo bar',
+ array( 23, 42 ),
+ new stdClass(),
+ true,
+ false,
+ ),
+ );
+ }
+
+ public function testValidateHeadersSuccess()
+ {
+ $req = new ezcWebdavLockRequest( '/foo', '/bar' );
+ $req->validateHeaders();
+
+ $req->setHeader( 'Depth', ezcWebdavRequest::DEPTH_ZERO );
+ $req->validateHeaders();
+
+ $req->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
+ $req->validateHeaders();
+ }
+
+ public function testValidateHeadersFailure()
+ {
+ $req = new ezcWebdavLockRequest( '/foo', '/bar' );
+
+ $req->setHeader( 'Depth', null );
+ try
+ {
+ $req->validateHeaders();
+ $this->fail( 'Exception not thrown on missing Depth header.' );
+ }
+ catch ( ezcWebdavMissingHeaderException $e ) {}
+
+ $req->setHeader( 'Depth', 'A' );
+ try
+ {
+ $req->validateHeaders();
+ $this->fail( 'Exception not thrown on invalid Depth header.' );
+ }
+ catch ( ezcWebdavInvalidHeaderException $e ) {}
+
+ $req->setHeader( 'Depth', ezcWebdavRequest::DEPTH_ONE );
+ try
+ {
+ $req->validateHeaders();
+ $this->fail( 'Exception not thrown on invalid Depth header.' );
+ }
+ catch ( ezcWebdavInvalidHeaderException $e ) {}
+ }
+}
+
+?>
Propchange: trunk/Webdav/tests/request_lock_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] Wed Sep 19 15:25:05 2007
@@ -46,6 +46,7 @@
require_once 'request_move_test.php';
require_once 'request_propfind_test.php';
require_once 'request_proppatch_test.php';
+require_once 'request_lock_test.php';
require_once 'request_content_property_behaviour_test.php';
@@ -77,14 +78,14 @@
$this->setName( 'Webdav' );
$this->addTest( ezcWebdavBasicServerTest::suite() );
+ $this->addTest( ezcWebdavServerOptionsTest::suite() );
+
+ $this->addTest( ezcWebdavFlaggedPropertyStorageTest::suite() );
$this->addTest( ezcWebdavPropertyStorageTest::suite() );
- $this->addTest( ezcWebdavFlaggedPropertyStorageTest::suite() );
+
$this->addTest( ezcWebdavCreationDatePropertyTest::suite() );
+ $this->addTest( ezcWebdavDeadPropertyTest::suite() );
$this->addTest( ezcWebdavDisplayNamePropertyTest::suite() );
- $this->addTest( ezcWebdavErrorResonseTest::suite() );
- $this->addTest( ezcWebdavGetResponseTest::suite() );
- $this->addTest( ezcWebdavOptionsResponseTest::suite() );
- $this->addTest( ezcWebdavDeadPropertyTest::suite() );
$this->addTest( ezcWebdavGetContentLanguagePropertyTest::suite() );
$this->addTest( ezcWebdavGetContentLengthPropertyTest::suite() );
$this->addTest( ezcWebdavGetContentTypePropertyTest::suite() );
@@ -92,20 +93,28 @@
$this->addTest( ezcWebdavGetLastModifiedPropertyTest::suite() );
$this->addTest( ezcWebdavLockDiscoveryPropertyActiveLockTest::suite()
);
$this->addTest( ezcWebdavLockDiscoveryPropertyTest::suite() );
- $this->addTest( ezcWebdavMemoryBackendTest::suite() );
- $this->addTest( ezcWebdavPathFactoryTest::suite() );
$this->addTest( ezcWebdavResourceTypePropertyTest::suite() );
- $this->addTest( ezcWebdavServerOptionsTest::suite() );
$this->addTest( ezcWebdavSourcePropertyLinkTest::suite() );
$this->addTest( ezcWebdavSourcePropertyTest::suite() );
$this->addTest( ezcWebdavSupportedLockPropertyLockentryTest::suite() );
$this->addTest( ezcWebdavSupportedLockPropertyTest::suite() );
+
$this->addTest( ezcWebdavCopyRequestTest::suite() );
- $this->addTest( ezcWebdavResponseTest::suite() );
+ $this->addTest( ezcWebdavLockRequestTest::suite() );
$this->addTest( ezcWebdavMoveRequestTest::suite() );
$this->addTest( ezcWebdavPropFindRequestTest::suite() );
$this->addTest( ezcWebdavPropPatchRequestTest::suite() );
$this->addTest( ezcWebdavRequestPropertyBehaviourContentTest::suite()
);
+
+ $this->addTest( ezcWebdavErrorResonseTest::suite() );
+ $this->addTest( ezcWebdavGetResponseTest::suite() );
+ $this->addTest( ezcWebdavOptionsResponseTest::suite() );
+ $this->addTest( ezcWebdavResponseTest::suite() );
+
+ $this->addTest( ezcWebdavMemoryBackendTest::suite() );
+
+ $this->addTest( ezcWebdavPathFactoryTest::suite() );
+
$this->addTest( ezcWebdavClientRfcTest::suite() );
$this->addTest( ezcWebdavClientCadaverTest::suite() );
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components