Author: ts
Date: Wed Sep 26 23:53:15 2007
New Revision: 6293

Log:
- Added scripts used to generate litmus tests.
# Just to have them somewhere in SVN.
- Moved scripts used for testing stuff to a common directory.

Added:
    trunk/Webdav/tests/scripts/
    trunk/Webdav/tests/scripts/extract_litmus.php   (with props)
    trunk/Webdav/tests/scripts/extract_litmus_transport_mock.php   (with props)
    trunk/Webdav/tests/scripts/visualize_results.php
      - copied unchanged from r6287, trunk/Webdav/tests/visualize_results.php
Removed:
    trunk/Webdav/tests/visualize_results.php

Added: trunk/Webdav/tests/scripts/extract_litmus.php
==============================================================================
--- trunk/Webdav/tests/scripts/extract_litmus.php (added)
+++ trunk/Webdav/tests/scripts/extract_litmus.php [iso-8859-1] Wed Sep 26 
23:53:15 2007
@@ -1,0 +1,164 @@
+<?php
+/**
+ * index.php in web envirionment. Renam accordingly.
+ * This file is meant as the index.php in your web environement. You need to
+ * adjust the include path accordingly to have eZ Components included. Copy
+ * [EMAIL PROTECTED] extract_litmus_transport_mock.php} to the same directory 
as index.php
+ * and name it transport_mock.php. The directory must be writeable and contain
+ * a sub-directory named log/ where the extracted test cases are created.
+ *
+ * @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
+ */
+
+require_once '/home/dotxp/dev/ez/ezcomponents/trunk/Base/src/base.php';
+
+function __autoload( $className )
+{
+    ezcBase::autoload( $className );
+}
+
+require_once dirname( __FILE__ ) . '/transport_mock.php';
+
+$trans = new tsWebdavTransportMock();
+$trans->options->pathFactory = new ezcWebdavPathFactory( 'http://' . 
$_SERVER['HTTP_HOST'] );
+try
+{
+    $req = $trans->parseRequest( ( $_SERVER['REQUEST_URI'] === '' ? '/' : 
$_SERVER['REQUEST_URI'] ) );
+    $req->validateHeaders();
+}
+catch( Exception $e )
+{
+    file_put_contents( './webdav.transport.error.log' . microtime(), 
var_export( $e, true ) );
+    die( $e->getMessage() );
+}
+
+if ( file_exists( ( $backendFile = dirname( __FILE__ ) . '/backend.ser' ) ) )
+{
+    $backend = unserialize( file_get_contents( $backendFile ) );
+}
+else
+{
+    $backend = new ezcWebdavMemoryBackend();
+    $backend->options->fakeLiveProperties = true;
+    $backend->addContents(
+        array(
+            'test_collection' => array(
+                'foo.txt'  => 'Test foo content',
+                'bar'      => 'Test bar content',
+                'baz_coll' => array(
+                    'baz_1.html' => '<html></html>',
+                    'baz_2.html' => '<html><body><h1>Test</h1></body></html>',
+                ),
+            ),
+        )
+    );
+
+    // Properties requested by Cadaver on first request
+
+    $backend->setProperty(
+        '/test_collection',
+        new ezcWebdavGetLastModifiedProperty(
+            new ezcWebdavDateTime()
+        )
+    );
+
+    // Make GET requests work
+
+    $backend->setProperty(
+        '/test_collection/foo.txt',
+        new ezcWebdavGetContentTypeProperty(
+            'text/plain', 'utf-8'
+        )
+    );
+    $backend->setProperty(
+        '/test_collection/bar',
+        new ezcWebdavGetContentTypeProperty(
+            'text/plain', 'utf-8'
+        )
+    );
+    $backend->setProperty(
+        '/test_collection/baz_coll/baz_1.html',
+        new ezcWebdavGetContentTypeProperty(
+            'text/html', 'utf-8'
+        )
+    );
+    $backend->setProperty(
+        '/test_collection/baz_coll/baz_2.html',
+        new ezcWebdavGetContentTypeProperty(
+            'text/xhtml', 'utf-8'
+        )
+    );
+}
+
+$log['request']['backend'] = serialize( $backend );
+    
+try
+{
+    $res = $backend->performRequest( $req );
+}
+catch ( Exception $e )
+{
+    file_put_contents( './webdav.backend.error.log' . microtime(), var_export( 
$e, true ) );
+    die( $e->getMessage() );
+}
+
+try
+{
+    $trans->handleResponse( $res );
+}
+catch ( Exception $e )
+{
+    file_put_contents( './webdav.transport.error.log' . microtime(), 
var_export( $e, true ) );
+    die( $e->getMessage() );
+}
+
+$testName = strtr(
+    $_SERVER['HTTP_X_LITMUS'],
+    array(
+        ' ' => '_',
+        ':' => '_',
+        '(' => '',
+        ')' => '',
+    )
+);
+
+$log['request']['server'] =  "<?php\n\nreturn " . var_export( $_SERVER, true ) 
. ";\n\n?>";
+$log['request']['body'] = $GLOBALS['TS_REQUEST_BODY'];
+$log['request']['uri'] = 'http://' . $_SERVER['SERVER_NAME'] . 
$_SERVER['REQUEST_URI'];
+
+$log['response']['headers'] = "<?php\n\nreturn " . var_export( 
$GLOBALS['TS_RESPONSE_HEADERS'], true ) . ";\n\n?>";
+$log['response']['body'] = $GLOBALS['TS_RESPONSE_BODY'];
+$log['response']['code'] = $GLOBALS['TS_RESPONSE_INFO']->response->status;
+$log['response']['name'] = 
ezcWebdavResponse::$errorNames[$GLOBALS['TS_RESPONSE_INFO']->response->status];
+
+if ( !file_exists( ( $logDir = dirname( __FILE__ ) . '/log' ) ) )
+{
+    mkdir( $logDir );
+}
+
+$testNo  = ( file_exists( ( $testNoFile = dirname( __FILE__ ) . '/test.no.txt' 
) ) ? (int)  file_get_contents( $testNoFile ) : 1 );
+$testDir = $logDir . sprintf( "/%'03s_%s", $testNo, $testName );
+
+file_put_contents( $testNoFile, ++$testNo );
+
+mkdir( $testDir );
+
+mkdir( ( $requestDir  = $testDir . '/request' ) );
+mkdir( ( $responseDir = $testDir . '/response' ) );
+
+file_put_contents( $requestDir . '/server.php', $log['request']['server'] );
+file_put_contents( $requestDir . '/body.xml', $log['request']['body'] );
+file_put_contents( $requestDir . '/uri.txt', $log['request']['uri'] );
+
+file_put_contents( $responseDir . '/headers.php', $log['response']['headers'] 
);
+file_put_contents( $responseDir . '/body.xml', $log['response']['body'] );
+file_put_contents( $responseDir . '/code.txt', $log['response']['code'] );
+file_put_contents( $responseDir . '/name.txt', $log['response']['name'] );
+
+file_put_contents( $backendFile, serialize( $backend ) );
+
+?>

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

Added: trunk/Webdav/tests/scripts/extract_litmus_transport_mock.php
==============================================================================
--- trunk/Webdav/tests/scripts/extract_litmus_transport_mock.php (added)
+++ trunk/Webdav/tests/scripts/extract_litmus_transport_mock.php [iso-8859-1] 
Wed Sep 26 23:53:15 2007
@@ -1,0 +1,41 @@
+<?php
+/**
+ * transport_mock.php in web envirionment. Renam accordingly.
+ * 
+ * @see extract_litmus.php
+ * @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
+ */
+
+class tsWebdavTransportMock extends ezcWebdavTransport
+{
+
+    protected function retreiveBody()
+    {
+        $body = parent::retreiveBody();
+        $GLOBALS['TS_REQUEST_BODY'] = $body;
+        return $body;
+    }
+
+    protected function parseHeaders( array $headerNames )
+    {
+        $headers = parent::parseHeaders( $headerNames );
+        $GLOBALS['TS_REQUEST_HEADERS'] = $headers;
+        return $headers;
+    }
+
+    protected function sendResponse( ezcWebdavDisplayInformation $info )
+    {
+        $GLOBALS['TS_RESPONSE_INFO'] = $info;
+        ob_start();
+        parent::sendResponse( $info );
+        $GLOBALS['TS_RESPONSE_BODY'] = ob_get_contents();
+        ob_flush();
+        $GLOBALS['TS_RESPONSE_HEADERS'] = $info->response->getHeaders();
+    }
+}
+
+?>

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


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

Reply via email to