Author: ts
Date: Thu Oct 11 17:39:05 2007
New Revision: 6432

Log:
- Started refactoring of client test suite.
# Attention work in progress.

Modified:
    trunk/Webdav/src/server.php
    trunk/Webdav/tests/client_test.php
    trunk/Webdav/tests/client_test_backend_continuous.php
    trunk/Webdav/tests/client_test_cadaver.php
    trunk/Webdav/tests/client_test_cadaver_backend.php
    trunk/Webdav/tests/client_test_litmus.php
    trunk/Webdav/tests/client_test_nautilus.php
    trunk/Webdav/tests/client_test_rfc.php
    trunk/Webdav/tests/client_test_rfc_backend.php

Modified: trunk/Webdav/src/server.php
==============================================================================
--- trunk/Webdav/src/server.php [iso-8859-1] (original)
+++ trunk/Webdav/src/server.php [iso-8859-1] Thu Oct 11 17:39:05 2007
@@ -116,14 +116,14 @@
         $this->backend = $backend;
         if ( !isset( $_SERVER['HTTP_USER_AGENT'] ) )
         {
-            throw new ezcWedavMissingHeaderException( 'User-Agent' );
+            throw new ezcWebdavMissingHeaderException( 'User-Agent' );
         }
         $this->properties['transport'] = $this->transports->createTransport( 
$_SERVER['HTTP_USER_AGENT'] );
 
         // Parse request into request object
         try
         {
-            $request = $this->transport->parseRequest();
+            $request = $this->transport->parseRequest( 'http://' . 
$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] );
         }
         catch ( Exception $e )
         {

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] Thu Oct 11 17:39:05 2007
@@ -18,7 +18,7 @@
 
     public $dataDir;
     
-    public $transport;
+    public $server;
 
     public $backend;
 
@@ -85,34 +85,54 @@
         );
 
         // Request test
-        if ( file_exists( ( $requestDir = "{$testSetName}/request" ) ) === 
true )
+        if ( file_exists( ( $requestDir = "{$testSetName}/request" ) ) === 
false )
         {
-            // Settings
-            $request = array();
-            $request['result'] = $this->getFileContent( $requestDir, 'result' 
);
-            $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 );
+            throw new PHPUnit_Framework_ExpectationFailedException( "No test 
data found for '$requestDir'." );
         }
+        // Settings
+        $request = array();
+        $request['result'] = $this->getFileContent( $requestDir, 'result' );
+        $request['server'] = array_merge( $serverBase, $this->getFileContent( 
$requestDir, 'server' ) );
+        $request['body']   = $this->getFileContent( $requestDir, 'body' );
+        $request['uri']    = $this->getFileContent( $requestDir, 'uri' );
 
         // Response test
         if ( file_exists( ( $responseDir = "{$testSetName}/response" ) ) === 
true && $requestObject instanceof ezcWebdavRequest && $this->setupClass !== 
null )
         {
-            $requestObject->validateHeaders();
+            throw new PHPUnit_Framework_ExpectationFailedException( "No test 
data found for '$requestDir'." );
+        }
+        // Settings
+        $response = array();
+        $response['result']  = $this->getFileContent( $responseDir, 'result' );
+        $response['headers'] = $this->getFileContent( $responseDir, 'headers' 
);
+        $response['body']    = $this->getFileContent( $responseDir, 'body' );
+        $response['code']    = $this->getFileContent( $responseDir, 'code' );
+        $response['name']    = $this->getFileContent( $responseDir, 'name' );
+        $response['backend'] = $this->getFileContent( $responseDir, 'backend' 
);
+        
+        // Optionally set a body.
+        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = ( $request['body'] !== 
false ? $request['body'] : '' );
 
-            // Settings
-            $response = array();
-            $response['result']  = $this->getFileContent( $responseDir, 
'result' );
-            $response['headers'] = $this->getFileContent( $responseDir, 
'headers' );
-            $response['body']    = $this->getFileContent( $responseDir, 'body' 
);
-            $response['code']    = $this->getFileContent( $responseDir, 'code' 
);
-            $response['name']    = $this->getFileContent( $responseDir, 'name' 
);
-            $response['backend'] = $this->getFileContent( $responseDir, 
'backend' );
-            
-            $responseObject = $this->runResponseTest( $response, 
$requestObject );
-        }
+        // Optionally overwrite $_SERVER
+        $_SERVER = $request['server'];
+
+        $this->server->handle( $this->backend );
+
+        $responseBody    = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY'];
+        $responseHeaders = 
$GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'];
+        $responseStatus  = 
$GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS'];
+
+        $this->assertEquals(
+            $responseHeaders,
+            $response['headers'],
+            'Headers incorrect.'
+        );
+
+        $this->assertEquals(
+            $responseBody,
+            $response['body'],
+            'Body incorrect.'
+        );
     }
 
     protected function getFileContent( $dir, $file )
@@ -142,139 +162,6 @@
         return $fileContent;
     }
 
-    protected function runRequestTest( array $request )
-    {
-        // Optionally set a body.
-        $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_BODY'] = ( $request['body'] !== 
false ? $request['body'] : '' );
-
-        // Optionally overwrite $_SERVER
-        $_SERVER = ( $request['server'] !== false ? $request['server'] : 
$_SERVER );
-
-        // Optionally set an URI different from 'http://localhost/webdav.php'
-        $uri = ( $request['uri'] !== false ? $request['uri'] : '/webdav.php' );
-
-        // Begin request test
-        $result = $this->transport->parseRequest( $uri );
-
-        if ( file_exists( ( $testResultFile = 
"{$this->currentTestSet}/request/result.ser" ) ) === false && 
self::REGENERATE_REQUEST === true )
-        {
-            echo "\nRegenerating {$testResultFile}\n";
-            file_put_contents(
-                $testResultFile,
-                serialize( $result )
-            );
-        }
-
-        $this->assertEquals(
-            $request['result'],
-            $result,
-            "Result not parsed correctly for test set 
'{$this->currentTestSet}'."
-        );
-
-        return $result;
-    }
-
-    protected function runResponseTest( array $response, ezcWebdavRequest 
$requestObject )
-    {
-        $responseObject = $this->backend->performRequest( $requestObject );
-        
-        $this->transport->handleResponse( $responseObject );
-        
-        $responseBody    = $GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_BODY'];
-        $responseHeaders = 
$GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_HEADERS'];
-        $responseStatus  = 
$GLOBALS['EZC_WEBDAV_TRANSPORT_TEST_RESPONSE_STATUS'];
-
-        if ( $response['result'] === false )
-        {
-            if ( file_exists( ( $testResultFile = 
"{$this->currentTestSet}/response/result.ser" ) ) === false && 
self::REGENERATE_RESPONSE )
-            {
-                echo "\nRegenerating {$testResultFile}\n";
-                file_put_contents(
-                    $testResultFile,
-                    serialize( array( "headers" => $responseHeaders, "body" => 
$responseBody ) )
-                );
-            }
-            if ( isset( $response['body'] ) === false || trim( 
$response['body'] ) === '' || $responseBody === '' )
-            {
-                $this->assertEquals(
-                    $response['body'],
-                    $responseBody,
-                    'Response body not generated correctly.'
-                );
-            }
-            else
-            {
-                $this->assertXmlStringEqualsXmlString(
-                    $response['body'],
-                    $responseBody,
-                    'Response body not generated correctly.'
-                );
-            }
-            if ( isset( $response['backend'] ) && $response['backend'] !== 
false )
-            {
-                $this->assertEquals(
-                    $response['backend'],
-                    $this->backend,
-                    'Backend state missmatched.'
-                );
-            }
-        } 
-        else
-        {
-            // FIXME
-            $responseHeaders[0] = $responseStatus;
-            if ( !empty( $responseBody ) && !isset( 
$response['result']['headers']['Content-Type'] ) )
-            {
-                $response['result']['headers']['Content-Type'] = 'text/xml; 
charset="utf-8"';
-            }
-            // END FIXME
-
-            $this->assertEquals(
-                $response['result']['headers'],
-                $responseHeaders,
-                'Generated headers missmatch.'
-            );
-            if ( trim( $response['result']['body'] ) === '' || $responseBody 
=== '' )
-            {
-                $this->assertEquals(
-                    $response['result']['body'],
-                    $responseBody,
-                    'Generated body missmatch.'
-                );
-            }
-            else
-            {
-                $this->assertXmlStringEqualsXmlString(
-                    $response['result']['body'],
-                    $responseBody,
-                    'Generated body missmatch.'
-                );
-            }
-        }
-        if ( file_exists( ( $testBackendFile = 
"{$this->currentTestSet}/response/backend.ser" ) ) === false && 
self::REGENERATE_RESPONSE )
-        {
-            echo "\nRegenerating {$testBackendFile}\n";
-            file_put_contents(
-                $testBackendFile,
-                serialize( $this->backend )
-            );
-        }
-
-        $this->assertEquals(
-            $response['code'],
-            $responseObject->status,
-            'Response code missmatch'
-        );
-
-        $this->assertEquals(
-            $response['name'],
-            ezcWebdavResponse::$errorNames[$responseObject->status],
-            'Response name missmatch'
-        );
-
-        return $responseObject;
-    }
-
 }
 
 ?>

Modified: trunk/Webdav/tests/client_test_backend_continuous.php
==============================================================================
--- trunk/Webdav/tests/client_test_backend_continuous.php [iso-8859-1] 
(original)
+++ trunk/Webdav/tests/client_test_backend_continuous.php [iso-8859-1] Thu Oct 
11 17:39:05 2007
@@ -1,8 +1,10 @@
 <?php
 
-class ezcWebdavClientTestBackendContinuous
+require_once 'client_test_setup.php';
+
+class ezcWebdavClientTestContinuousSetup extends ezcWebdavClientTestSetup
 {
-    protected static $transport;
+    protected static $pathFactory;
 
     protected static $backend;
 
@@ -12,13 +14,13 @@
     {
         if ( basename( dirname( $testSetName ) ) !== self::$lastTestSuite )
         {
-            self::$lastTestSuite          = basename( dirname( $testSetName ) 
);
-            self::$transport              = new ezcWebdavTransportTestMock();
-            self::$transport->pathFactory = new ezcWebdavBasicPathFactory( 
'http://webdav' );
-            self::$backend                = self::setupBackend();
+            self::$lastTestSuite = basename( dirname( $testSetName ) );
+            self::$pathFactory   = new ezcWebdavBasicPathFactory( 
'http://webdav' );
+            self::$backend       = self::setupBackend();
         }
-        $test->transport = self::$transport;
-        $test->backend   = self::$backend;
+
+        $test->server  = self::getServer( self::$pathFactory );
+        $test->backend = self::$backend;
     }
 
     protected static function setupBackend()

Modified: trunk/Webdav/tests/client_test_cadaver.php
==============================================================================
--- trunk/Webdav/tests/client_test_cadaver.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_cadaver.php [iso-8859-1] Thu Oct 11 17:39:05 
2007
@@ -10,7 +10,7 @@
 {
     protected function setupTestEnvironment()
     {
-        $this->setupClass = 'ezcWebdavClientTestBackendContinuous';
+        $this->setupClass = 'ezcWebdavClientTestContinuousSetup';
         $this->dataDir    = dirname( __FILE__ ) . '/clients/cadaver';
     }
 

Modified: trunk/Webdav/tests/client_test_cadaver_backend.php
==============================================================================
--- trunk/Webdav/tests/client_test_cadaver_backend.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_cadaver_backend.php [iso-8859-1] Thu Oct 11 
17:39:05 2007
@@ -1,19 +1,17 @@
 <?php
 
-class ezcWebdavClientCadaverTestBackend
+require_once 'client_test_setup.php';
+
+class ezcWebdavClientTestCadaverSetup extends ezcWebdavClientTestSetup
 {
     public static function performSetup( ezcWebdavClientTest $test, 
$testSetName )
     {
-        $test->transport = new ezcWebdavTransportTestMock();
-        $test->transport->pathFactory = new ezcWebdavBasicPathFactory(
+        $pathFactory = new ezcWebdavBasicPathFactory(
             'http://foo.bar'
         );
         
-        return self::getFooBarSetup1( $test );
-    }
-
-    protected static function getFooBarSetup1( ezcWebdavClientTest $test )
-    {
+        $test->server = self::getServer( $pathFactory );
+        
         $test->backend                             = new 
ezcWebdavMemoryBackend();
         $test->backend->options->failForRegexp     = '(container/resource3)';
         $test->backend->options->failingOperations = 
ezcWebdavMemoryBackendOptions::REQUEST_DELETE;
@@ -156,8 +154,6 @@
                 )
             )
         );
-
-        return $test->backend;
     }
 }
 

Modified: trunk/Webdav/tests/client_test_litmus.php
==============================================================================
--- trunk/Webdav/tests/client_test_litmus.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_litmus.php [iso-8859-1] Thu Oct 11 17:39:05 
2007
@@ -11,7 +11,7 @@
 {
     protected function setupTestEnvironment()
     {
-        $this->setupClass = 'ezcWebdavClientTestBackendContinuous';
+        $this->setupClass = 'ezcWebdavClientTestContinuousSetup';
         $this->dataDir    = dirname( __FILE__ ) . '/clients/litmus';
     }
 

Modified: trunk/Webdav/tests/client_test_nautilus.php
==============================================================================
--- trunk/Webdav/tests/client_test_nautilus.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_nautilus.php [iso-8859-1] Thu Oct 11 
17:39:05 2007
@@ -10,7 +10,7 @@
 {
     protected function setupTestEnvironment()
     {
-        $this->setupClass = 'ezcWebdavClientTestBackendContinuous';
+        $this->setupClass = 'ezcWebdavClientTestContinuousSetup';
         $this->dataDir    = dirname( __FILE__ ) . '/clients/nautilus';
     }
 

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] Thu Oct 11 17:39:05 2007
@@ -11,7 +11,7 @@
 {
     protected function setupTestEnvironment()
     {
-        $this->setupClass = 'ezcWebdavClientRfcTestBackend';
+        $this->setupClass = 'ezcWebdavClientTestRfcSetup';
         $this->dataDir    = dirname( __FILE__ ) . '/clients/rfc';
     }
 

Modified: trunk/Webdav/tests/client_test_rfc_backend.php
==============================================================================
--- trunk/Webdav/tests/client_test_rfc_backend.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/client_test_rfc_backend.php [iso-8859-1] Thu Oct 11 
17:39:05 2007
@@ -1,15 +1,15 @@
 <?php
 
-class ezcWebdavClientRfcTestBackend
+require_once 'client_test_setup.php';
+
+class ezcWebdavClientTestRfcSetup extends ezcWebdavClientTestSetup
 {
     public static function performSetup( ezcWebdavClientTest $test, 
$testSetName )
     {
-        // Compat
+        $pathFactory  = new ezcWebdavBasicPathFactory( 'http://www.foo.bar' );
+        $test->server = self::getServer( $pathFactory );
+
         $testSetName = basename( $testSetName );
-
-        $test->transport  = new ezcWebdavTransportTestMock();
-        $test->transport->pathFactory = new ezcWebdavBasicPathFactory( 
'http://www.foo.bar' );
-
         switch( $testSetName )
         {
             case 'propfind_propname':
@@ -43,11 +43,6 @@
         }
     }
 
-    public static function reset()
-    {
-
-    }
-
     protected static function getFooBarSetup1( ezcWebdavClientTest $test )
     {
 


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

Reply via email to