Author: kn
Date: Thu Sep 20 11:44:57 2007
New Revision: 6212

Log:
- Generate correct responses for validation errors in backend.

Modified:
    trunk/Webdav/src/backend/simple.php
    trunk/Webdav/tests/backend_memory_test.php

Modified: trunk/Webdav/src/backend/simple.php
==============================================================================
--- trunk/Webdav/src/backend/simple.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backend/simple.php [iso-8859-1] Thu Sep 20 11:44:57 2007
@@ -548,6 +548,7 @@
 
         $errors = array(
             ezcWebdavResponse::STATUS_403 => new ezcWebdavPropertyStorage(),
+            ezcWebdavResponse::STATUS_409 => new ezcWebdavPropertyStorage(),
             ezcWebdavResponse::STATUS_424 => new ezcWebdavPropertyStorage(),
         );
         $errnous = false;
@@ -560,6 +561,14 @@
             if ( $errnous )
             {
                 $errors[ezcWebdavResponse::STATUS_424]->attach( $property );
+                continue;
+            }
+
+            // Check for property validation errors and add a 409 for this.
+            if ( $property->hasError )
+            {
+                $errors[ezcWebdavResponse::STATUS_409]->attach( $property );
+                $errnous = true;
                 continue;
             }
 
@@ -617,6 +626,10 @@
                     ezcWebdavResponse::STATUS_403
                 ),
                 new ezcWebdavPropStatResponse(
+                    $errors[ezcWebdavResponse::STATUS_409],
+                    ezcWebdavResponse::STATUS_409
+                ),
+                new ezcWebdavPropStatResponse(
                     $errors[ezcWebdavResponse::STATUS_424],
                     ezcWebdavResponse::STATUS_424
                 )

Modified: trunk/Webdav/tests/backend_memory_test.php
==============================================================================
--- trunk/Webdav/tests/backend_memory_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_memory_test.php [iso-8859-1] Thu Sep 20 11:44:57 
2007
@@ -2441,6 +2441,10 @@
                     ezcWebdavResponse::STATUS_403
                 ),
                 new ezcWebdavPropStatResponse(
+                    new ezcWebdavPropertyStorage,
+                    ezcWebdavResponse::STATUS_409
+                ),
+                new ezcWebdavPropStatResponse(
                     $depError,
                     ezcWebdavResponse::STATUS_424
                 )
@@ -2639,6 +2643,10 @@
                     ezcWebdavResponse::STATUS_403
                 ),
                 new ezcWebdavPropStatResponse(
+                    new ezcWebdavPropertyStorage,
+                    ezcWebdavResponse::STATUS_409
+                ),
+                new ezcWebdavPropStatResponse(
                     $depError,
                     ezcWebdavResponse::STATUS_424
                 )
@@ -2860,6 +2868,10 @@
                     ezcWebdavResponse::STATUS_403
                 ),
                 new ezcWebdavPropStatResponse(
+                    new ezcWebdavPropertyStorage,
+                    ezcWebdavResponse::STATUS_409
+                ),
+                new ezcWebdavPropStatResponse(
                     $depError,
                     ezcWebdavResponse::STATUS_424
                 )
@@ -2870,6 +2882,96 @@
             20
         );
     }
+
+    public function testPropPatchCombinedSetDeleteValidationError()
+    {
+        $backend = new ezcWebdavMemoryBackend();
+        $backend->options->fakeLiveProperties = true;
+        $backend->addContents( array(
+            'foo' => 'bar',
+            'bar' => array(
+                'blubb' => 'Somme blubb blubbs.',
+            )
+        ) );
+    
+        // First add some custom properties.
+        $newProperties = new ezcWebdavFlaggedPropertyStorage();
+        $newProperties->attach( $p_bar = new ezcWebdavDeadProperty( 
+            'foo:', 'bar', 'some content'
+        ), ezcWebdavPropPatchRequest::SET );
+        $newProperties->attach( $p_blubb = new ezcWebdavDeadProperty( 
+            'foo:', 'blubb', 'some other content'
+        ), ezcWebdavPropPatchRequest::SET );
+
+        $request = new ezcWebdavPropPatchRequest( '/foo' );
+        $request->updates = $newProperties;
+        $request->validateHeaders();
+        $response = $backend->proppatch( $request );
+
+        $this->assertEquals(
+            new ezcWebdavPropPatchResponse(
+                new ezcWebdavResource( '/foo' )
+            ),
+            $response,
+            'Expected property adding PROPPATCH response does not match real 
response.',
+            0,
+            20
+        );
+
+        // Then remove them again, with one live property in the middle to
+        // check for proper failed dependency response codes.
+        $updateProperties = new ezcWebdavFlaggedPropertyStorage();
+        $updateProperties->attach( $p_blubb, ezcWebdavPropPatchRequest::REMOVE 
);
+        $updateProperties->attach( 
+            $p_length = new ezcWebdavGetContentLengthProperty(), 
+            ezcWebdavPropPatchRequest::REMOVE
+        );
+
+        // Cause validation error
+        $p_length->length = 'not a number';
+
+        $updateProperties->attach( 
+            $p_foo = new ezcWebdavDeadProperty( 'foo:', 'foo', 'random 
content' ),
+            ezcWebdavPropPatchRequest::SET
+        );
+        $updateProperties->attach( $p_bar, ezcWebdavPropPatchRequest::REMOVE );
+
+        $request = new ezcWebdavPropPatchRequest( '/foo' );
+        $request->updates = $updateProperties;
+        $request->validateHeaders();
+        $response = $backend->proppatch( $request );
+
+        $failed = new ezcWebdavPropertyStorage();
+        $failed->attach( $p_length );
+
+        $depError = new ezcWebdavPropertyStorage();
+        $depError->attach( $p_foo );
+        $depError->attach( $p_bar );
+
+        $failed->rewind();
+        $depError->rewind();
+        $this->assertEquals(
+            new ezcWebdavPropPatchResponse(
+                new ezcWebdavResource( '/foo' ),
+                new ezcWebdavPropStatResponse(
+                    new ezcWebdavPropertyStorage,
+                    ezcWebdavResponse::STATUS_403
+                ),
+                new ezcWebdavPropStatResponse(
+                    $failed,
+                    ezcWebdavResponse::STATUS_409
+                ),
+                new ezcWebdavPropStatResponse(
+                    $depError,
+                    ezcWebdavResponse::STATUS_424
+                )
+            ),
+            $response,
+            'Expected property removing PROPPATCH response does not match real 
response.',
+            0,
+            20
+        );
+    }
 }
 
 ?>


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

Reply via email to