Author: kn
Date: Tue Oct  2 14:39:54 2007
New Revision: 6332

Log:
- Implemented handling of mime types in file backend

Modified:
    trunk/Webdav/src/backends/file.php
    trunk/Webdav/src/options/backend_file_options.php
    trunk/Webdav/tests/backend_file_options_test.php
    trunk/Webdav/tests/backend_file_test.php

Modified: trunk/Webdav/src/backends/file.php
==============================================================================
--- trunk/Webdav/src/backends/file.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backends/file.php [iso-8859-1] Tue Oct  2 14:39:54 2007
@@ -52,8 +52,8 @@
         'getlastmodified', 
         'creationdate', 
         'displayname', 
+        'getetag', 
         'getcontenttype', 
-        'getetag', 
         'resourcetype'
     );
 
@@ -208,7 +208,7 @@
     protected function getMimeType( $resource )
     {
         // Check if extension pecl/fileinfo is usable.
-        if ( function_exists( 'finfo_file' ) )
+        if ( $this->options->useMimeExts && function_exists( 'finfo_file' ) )
         {
             $fInfo = new fInfo( FILEINFO_MIME );
             $mimeType = $fInfo->file( $this->root . $resource );
@@ -218,15 +218,21 @@
         }
 
         // Check if extension ext/mime-magic is usable.
-        if ( function_exists( 'mime_content_type' ) )
+        if ( $this->options->useMimeExts && function_exists( 
'mime_content_type' ) )
         {
             return mime_content_type( $this->root . $resource );
         }
 
         // Check if some browser submitted mime type is available.
-        if ( false )
-        {
-            // @TODO: Implement
+        $storage = $this->getPropertyStoragePath(
+            $resource, 
+            new ezcWebdavDeadProperty( 'DAV:', 'getcontenttype' ) 
+        );
+
+        if ( is_file( $storage ) )
+        {
+            $property = unserialize( file_get_contents( $storage ) );
+            return $property->mime;
         }
 
         return 'application/octet-stream';
@@ -354,7 +360,9 @@
 
         // Check if property is a self handled live property and return an
         // error in this case.
-        if ( in_array( $property->name, $this->handledLiveProperties, true ) )
+        if ( ( $property->namespace === 'DAV:' ) &&
+             in_array( $property->name, $this->handledLiveProperties, true ) &&
+             ( $property->name !== 'getcontenttype' ) )
         {
             return false;
         }

Modified: trunk/Webdav/src/options/backend_file_options.php
==============================================================================
--- trunk/Webdav/src/options/backend_file_options.php [iso-8859-1] (original)
+++ trunk/Webdav/src/options/backend_file_options.php [iso-8859-1] Tue Oct  2 
14:39:54 2007
@@ -25,6 +25,10 @@
  *           Mode directories are created with.
  * @property int $fileMode
  *           Mode files are created with.
+ * @property bool $useMimeExts
+ *           Indicates wheather to use PHPs extensions to receive the correct
+ *           mime time for a file instead of just returning the mime type
+ *           originally set by the client.
  *
  * @package Webdav
  * @version //autogen//
@@ -49,6 +53,7 @@
         $this->properties['propertyStoragePath']    = '.ezc';
         $this->properties['directoryMode']          = 0755;
         $this->properties['fileMode']               = 0644;
+        $this->properties['useMimeExts']            = true;
 
         parent::__construct( $options );
     }
@@ -69,6 +74,7 @@
         switch ( $name )
         {
             case 'noLock':
+            case 'useMimeExts':
                 if ( !is_bool( $value ) )
                 {
                     throw new ezcBaseValueException( $name, $value, 'bool' );

Modified: trunk/Webdav/tests/backend_file_options_test.php
==============================================================================
--- trunk/Webdav/tests/backend_file_options_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_file_options_test.php [iso-8859-1] Tue Oct  2 
14:39:54 2007
@@ -37,6 +37,7 @@
             'propertyStoragePath'   => '.ezc',
             'directoryMode'         => 0755,
             'fileMode'              => 0644,
+            'useMimeExts'           => true,
         );
         $this->workingValues = array(
             'noLock'                => array(
@@ -62,6 +63,10 @@
             'fileMode'              => array(
                 0,
                 100
+            ),
+            'useMimeExts'           => array(
+                true,
+                false
             ),
         );
         $this->failingValues = array(
@@ -107,6 +112,13 @@
                 false,
                 new stdClass(),
             ),
+            'useMimeExts'           => array(
+                23,
+                23.34,
+                'foo',
+                array(),
+                new stdClass(),
+            ),
         );
     }
 

Modified: trunk/Webdav/tests/backend_file_test.php
==============================================================================
--- trunk/Webdav/tests/backend_file_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_file_test.php [iso-8859-1] Tue Oct  2 14:39:54 
2007
@@ -1209,6 +1209,105 @@
         $response = $backend->propfind( $request );
 
         $this->compareResponse( __FUNCTION__, $response );
+    }
+
+    public function testPropMimeTypeOnResource()
+    {
+        $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
+
+        $newProperties = new ezcWebdavFlaggedPropertyStorage();
+        $newProperties->attach( 
+            new ezcWebdavGetContentTypeProperty( 'text/xml' ),
+            ezcWebdavPropPatchRequest::SET
+        );
+
+        $request = new ezcWebdavPropPatchRequest( '/resource' );
+        $request->updates = $newProperties;
+        $request->validateHeaders();
+        $response = $backend->proppatch( $request );
+
+        $requestedProperties = new ezcWebdavBasicPropertyStorage();
+        $requestedProperties->attach(
+            new ezcWebdavGetContentTypeProperty()
+        );
+
+        $request = new ezcWebdavPropFindRequest( '/resource' );
+        $request->prop = $requestedProperties;
+        $request->validateHeaders();
+        $response = $backend->propfind( $request );
+
+        $responseProperty = new ezcWebdavBasicPropertyStorage();
+        $responseProperty->attach(
+            new ezcWebdavGetContentTypeProperty( 'text/plain' )
+        );
+
+        $responseProperty->rewind();
+        $expectedResponse = new ezcWebdavMultistatusResponse(
+            new ezcWebdavPropFindResponse(
+                new ezcWebdavResource( '/resource' ),
+                new ezcWebdavPropStatResponse(
+                    $responseProperty
+                )
+            )
+        );
+
+        $this->assertEquals(
+            $expectedResponse,
+            $response,
+            'Expected response does not match real response.',
+            0,
+            20
+        );
+    }
+
+    public function testPropMimeTypeOnResourceWithoutGuessingPriorSet()
+    {
+        $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
+        $backend->options->useMimeExts = false;
+
+        $newProperties = new ezcWebdavFlaggedPropertyStorage();
+        $newProperties->attach( 
+            new ezcWebdavGetContentTypeProperty( 'text/xml' ),
+            ezcWebdavPropPatchRequest::SET
+        );
+
+        $request = new ezcWebdavPropPatchRequest( '/resource' );
+        $request->updates = $newProperties;
+        $request->validateHeaders();
+        $response = $backend->proppatch( $request );
+
+        $requestedProperties = new ezcWebdavBasicPropertyStorage();
+        $requestedProperties->attach(
+            new ezcWebdavGetContentTypeProperty()
+        );
+
+        $request = new ezcWebdavPropFindRequest( '/resource' );
+        $request->prop = $requestedProperties;
+        $request->validateHeaders();
+        $response = $backend->propfind( $request );
+
+        $responseProperty = new ezcWebdavBasicPropertyStorage();
+        $responseProperty->attach(
+            new ezcWebdavGetContentTypeProperty( 'text/xml' )
+        );
+
+        $responseProperty->rewind();
+        $expectedResponse = new ezcWebdavMultistatusResponse(
+            new ezcWebdavPropFindResponse(
+                new ezcWebdavResource( '/resource' ),
+                new ezcWebdavPropStatResponse(
+                    $responseProperty
+                )
+            )
+        );
+
+        $this->assertEquals(
+            $expectedResponse,
+            $response,
+            'Expected response does not match real response.',
+            0,
+            20
+        );
     }
 
     public function testPropFindOnCollection()


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

Reply via email to