/Webdav/tests/backend_file_test.php
PHP | 2619 lines | 2082 code | 430 blank | 107 comment | 18 complexity | e2ce78c45c1476fe3f449fe2a076ab6b MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * Basic test cases for the file backend.
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- * @package Webdav
- * @subpackage Tests
- * @version //autogentag//
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
- */
- /**
- * Reqiuire base test
- */
- /**
- * Tests for ezcWebdavFileBackend class.
- *
- * @package Webdav
- * @subpackage Tests
- */
- class ezcWebdavFileBackendTest extends ezcTestCase
- {
- const KEEP_TEMP_DIR = false;
- protected $tempDir;
- protected $oldTimezone;
- public static function suite()
- {
- return new PHPUnit_Framework_TestSuite( 'ezcWebdavFileBackendTest' );
- }
- protected function recursiveTouch( $source, $time )
- {
- $dh = opendir( $source );
- while( $file = readdir( $dh ) )
- {
- if ( ( $file === '.' ) ||
- ( $file === '..' ) )
- {
- continue;
- }
- if ( is_dir( $path = $source . '/' . $file ) )
- {
- touch( $path, $time, $time );
- $this->recursiveTouch( $path, $time );
- }
- else
- {
- touch( $path, $time, $time );
- }
- }
- }
- /**
- * Recursively copy a file or directory.
- *
- * Recursively copy a file or directory in $source to the given
- * destination. If a depth is given, the operation will stop, if the given
- * recursion depth is reached. A depth of -1 means no limit, while a depth
- * of 0 means, that only the current file or directory will be copied,
- * without any recursion.
- *
- * You may optionally define modes used to create files and directories.
- *
- * @throws ezcBaseFileNotFoundException
- * If the $sourceDir directory is not a directory or does not exist.
- * @throws ezcBaseFilePermissionException
- * If the $sourceDir directory could not be opened for reading, or the
- * destination is not writeable.
- *
- * @param string $source
- * @param string $destination
- * @param int $depth
- * @param int $dirMode
- * @param int $fileMode
- * @return void
- */
- static protected function copyRecursive( $source, $destination, $depth = -1, $dirMode = 0775, $fileMode = 0664 )
- {
- // Check if source file exists at all.
- if ( !is_file( $source ) && !is_dir( $source ) )
- {
- throw new ezcBaseFileNotFoundException( $source );
- }
- // Destination file should NOT exist
- if ( is_file( $destination ) || is_dir( $destination ) )
- {
- throw new ezcBaseFilePermissionException( $destination, ezcBaseFileException::WRITE );
- }
- // Skip non readable files in source directory
- if ( !is_readable( $source ) )
- {
- return;
- }
- // Copy
- if ( is_dir( $source ) )
- {
- mkdir( $destination );
- // To ignore umask, umask() should not be changed with
- // multithreaded servers...
- chmod( $destination, $dirMode );
- }
- elseif ( is_file( $source ) )
- {
- copy( $source, $destination );
- chmod( $destination, $fileMode );
- }
- if ( ( $depth === 0 ) ||
- ( !is_dir( $source ) ) )
- {
- // Do not recurse (any more)
- return;
- }
- // Recurse
- //
- // Read directory using glob(), to get a pre-sorted result.
- $files = glob( $source . '/*' );
- foreach ( $files as $fullName )
- {
- $file = basename( $fullName );
- if ( empty( $file ) )
- {
- continue;
- }
- self::copyRecursive(
- $source . '/' . $file,
- $destination . '/' . $file,
- $depth - 1, $dirMode, $fileMode
- );
- }
- }
- protected function compareResponse( $test, ezcWebdavResponse $response )
- {
- $dataDir = dirname( __FILE__ ) . '/data/responses/file';
- if ( !is_file( $file = $dataDir . '/' . $test . '.ser' ) )
- {
- file_put_contents( $file, serialize( $response ) );
- return $this->markTestSkipped( 'Reponse serialized. Please check generated response.' );
- }
- $this->assertEquals(
- $response,
- unserialize( file_get_contents( $file ) ),
- 'Response does not equal serialzed response.',
- 20
- );
- }
- public function setUp()
- {
- parent::setUp();
- static $i = 0;
- $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d', ++$i ) ) . '/';
-
- self::copyRecursive(
- dirname( __FILE__ ) . '/data/backend_file',
- $this->tempDir . 'backend/'
- );
- // Remove SVN directories from temporary backend
- $svnDirs = ezcFile::findRecursive(
- $this->tempDir . 'backend/',
- array( '(/\.svn/entries$)' )
- );
- foreach ( $svnDirs as $dir )
- {
- ezcFile::removeRecursive( dirname( $dir ) );
- }
- // Explicitely set mtime and ctime
- $this->recursiveTouch(
- $this->tempDir . 'backend/',
- // Change this once 64bit systems are common, or we reached year 2038
- 2147483647
- );
- // Store current timezone and switch to UTC for test
- $this->oldTimezone = date_default_timezone_get();
- date_default_timezone_set( 'UTC' );
- }
- public function tearDown()
- {
- // Reset old timezone
- date_default_timezone_set( $this->oldTimezone );
- if ( !$this->hasFailed() || self::KEEP_TEMP_DIR === false )
- {
- $this->removeTempDir();
- }
- parent::tearDown();
- }
- public function testFileBackendOptionsInFileBackend()
- {
- $server = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertEquals(
- $server->options,
- new ezcWebdavFileBackendOptions(),
- 'Expected initially unmodified backend options class.'
- );
- $this->assertSame(
- $server->options->noLock,
- false,
- 'Expected successfull access on option.'
- );
- try
- {
- // Read access
- $server->unknownProperty;
- }
- catch ( ezcBasePropertyNotFoundException $e )
- {
- return true;
- }
- $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
- }
- public function testFileBackendOptionsSetInFileBackend()
- {
- $server = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $options = new ezcWebdavFileBackendOptions();
- $options->noLock = true;
- $this->assertSame(
- $server->options->noLock,
- false,
- 'Wrong initial value before changed option class.'
- );
- $server->options = $options;
- $this->assertSame(
- $server->options->noLock,
- true,
- 'Expected modified value, because of changed option class.'
- );
- try
- {
- $server->unknownProperty = $options;
- }
- catch ( ezcBasePropertyNotFoundException $e )
- {
- return true;
- }
- $this->fail( 'Expected ezcBasePropertyNotFoundException.' );
- }
- public function testResourceHead()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavHeadRequest( '/resource' );
- $request->validateHeaders();
- $response = $backend->head( $request );
- $expectedResponse = new ezcWebdavHeadResponse(
- new ezcWebdavResource(
- '/resource',
- $backend->getAllProperties( '/resource' )
- )
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testCollectionHead()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavHeadRequest( '/collection' );
- $request->validateHeaders();
- $response = $backend->head( $request );
- $expectedResponse = new ezcWebdavHeadResponse(
- new ezcWebdavCollection(
- '/collection',
- $backend->getAllProperties( '/collection' )
- )
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceHeadError()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavHeadRequest( '/unknown' );
- $request->validateHeaders();
- $response = $backend->head( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/unknown'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceGet()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavGetRequest( '/resource' );
- $request->validateHeaders();
- $response = $backend->get( $request );
-
- $expectedResponse = new ezcWebdavGetResourceResponse(
- new ezcWebdavResource(
- '/resource',
- $backend->getAllProperties( '/resource' ),
- "Some webdav contents.\n"
- )
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceGetError()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavGetRequest( '/unknown' );
- $request->validateHeaders();
- $response = $backend->get( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/unknown'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testCollectionGet()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavGetRequest( '/collection' );
- $request->validateHeaders();
- $response = $backend->get( $request );
- $expectedResponse = new ezcWebdavGetCollectionResponse(
- new ezcWebdavCollection(
- '/collection',
- $backend->getAllProperties( '/collection' ),
- array(
- new ezcWebdavCollection(
- '/collection/deep_collection'
- ),
- new ezcWebdavResource(
- '/collection/test.txt'
- ),
- )
- )
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceDeepGet()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavGetRequest( '/collection/deep_collection/deep_test.txt' );
- $request->validateHeaders();
- $response = $backend->get( $request );
- $expectedResponse = new ezcWebdavGetResourceResponse(
- new ezcWebdavResource(
- '/collection/deep_collection/deep_test.txt',
- $backend->getAllProperties( '/collection/deep_collection/deep_test.txt' ),
- "=========\nTest file\n=========\n\nAnd again some randome contents...\n"
- )
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection/deep_collection/deep_test.txt', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopy()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/new_resource' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyProperties()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $backend->options->useMimeExts = false;
- $newProperties = new ezcWebdavFlaggedPropertyStorage();
- $newProperties->attach(
- $p1 = new ezcWebdavGetContentTypeProperty( 'text/xml' ),
- ezcWebdavPropPatchRequest::SET
- );
- $newProperties->attach(
- $p2 = new ezcWebdavDeadProperty( 'foo:', 'bar', "<?xml version=\"1.0\"?>\n<bar xmlns=\"foo:\">some content</bar>\n" ),
- ezcWebdavPropPatchRequest::SET
- );
- $request = new ezcWebdavPropPatchRequest( '/resource' );
- $request->updates = $newProperties;
- $request->validateHeaders();
- $response = $backend->proppatch( $request );
- $request = new ezcWebdavCopyRequest( '/resource', '/new_resource' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/.ezc/new_resource.xml' ),
- 'Expected creation of property storage.'
- );
- $request = new ezcWebdavPropFindRequest( '/new_resource' );
- $request->prop = $newProperties;
- $request->validateHeaders();
- $response = $backend->propfind( $request );
- $responseProperty = new ezcWebdavBasicPropertyStorage();
- $responseProperty->attach( $p1 );
- $responseProperty->attach( $p2 );
- $responseProperty->rewind();
- $expectedResponse = new ezcWebdavMultistatusResponse(
- new ezcWebdavPropFindResponse(
- new ezcWebdavResource( '/new_resource' ),
- new ezcWebdavPropStatResponse(
- $responseProperty
- )
- )
- );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyError()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/unknown', '/irrelevant' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/unknown'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyF()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/collection/resource' );
- $request->setHeader( 'Overwrite', 'F' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyOverwrite()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/collection/test.txt' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- true
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyOverwriteFailed()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/collection/test.txt' );
- $request->setHeader( 'Overwrite', 'F' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_412,
- '/collection/test.txt'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyDestinationNotExisting()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/dum/di' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/dum/di'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopySourceEqualsDest()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/resource', '/resource' );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_403,
- '/resource'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceCopyDepthZero()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
- $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_ZERO );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/new_collection' ),
- 'Expected created collection.'
- );
- }
- public function testResourceCopyDepthInfinity()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
- $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavCopyResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/new_collection' ),
- 'Expected created collection.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
- 'Expected created file in collection.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
- 'Expected created deep file in collection.'
- );
- }
- public function testResourceCopyDepthInfinityErrors()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- // Cause error by making file not readable
- chmod ( $this->tempDir . 'backend/collection/test.txt', 0 );
- $request = new ezcWebdavCopyRequest( '/collection', '/new_collection' );
- $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
- $request->validateHeaders();
- $response = $backend->copy( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMultistatusResponse(
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_423,
- '/collection/test.txt'
- )
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/new_collection' ),
- 'Expected created collection.'
- );
- $this->assertFalse(
- is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
- 'Expected file in collection not to be created.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
- 'Expected created deep file in collection.'
- );
- chmod ( $this->tempDir . 'backend/collection/test.txt', 0777 );
- }
- public function testResourceMove()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/dest' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMoveResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveError()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/unknown', '/irrelevant' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/unknown'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveF()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/dest' );
- $request->setHeader( 'Overwrite', 'F' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMoveResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveOverwrite()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/collection/test.txt' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMoveResponse(
- true
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveOverwriteFailed()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/collection/test.txt' );
- $request->setHeader( 'Overwrite', 'F' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_412,
- '/collection/test.txt'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveDestinationNotExisting()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/dum/di' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/dum/di'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveSourceEqualsDest()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMoveRequest( '/resource', '/resource' );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_403,
- '/resource'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceMoveDepthInfinity()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected existing collection before request.'
- );
- $request = new ezcWebdavMoveRequest( '/collection', '/new_collection' );
- $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMoveResponse(
- false
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertFalse(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected removed collection.'
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/new_collection' ),
- 'Expected created collection.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
- 'Expected created file in collection.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
- 'Expected created deep file in collection.'
- );
- }
- public function testResourceMoveDepthInfinityErrors()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- // Cause error by making file not readable
- chmod ( $this->tempDir . 'backend/collection/test.txt', 0 );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected existing collection before request.'
- );
- $request = new ezcWebdavMoveRequest( '/collection', '/new_collection' );
- $request->setHeader( 'Depth', ezcWebdavRequest::DEPTH_INFINITY );
- $request->validateHeaders();
- $response = $backend->move( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMultistatusResponse(
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_423,
- '/collection/test.txt'
- )
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected collection not to be removed.'
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/new_collection' ),
- 'Expected created collection.'
- );
- $this->assertFalse(
- is_file( $this->tempDir . 'backend/new_collection/test.txt' ),
- 'Expected file in collection not to be created.'
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/new_collection/deep_collection/deep_test.txt' ),
- 'Expected created deep file in collection.'
- );
- chmod ( $this->tempDir . 'backend/collection/test.txt', 0777 );
- }
- public function testResourceDelete()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected existing file.'
- );
- $request = new ezcWebdavDeleteRequest( '/resource' );
- $request->validateHeaders();
- $response = $backend->delete( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavDeleteResponse(
- '/resource'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertFalse(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected file to be removed.'
- );
- }
- public function testCollectionDelete()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected existing directory.'
- );
- $request = new ezcWebdavDeleteRequest( '/collection' );
- $request->validateHeaders();
- $response = $backend->delete( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavDeleteResponse(
- '/collection'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertFalse(
- is_dir( $this->tempDir . 'backend/collection' ),
- 'Expected directory to be removed.'
- );
- }
- public function testResourceDeleteError404()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavDeleteRequest( '/unknown' );
- $request->validateHeaders();
- $response = $backend->delete( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/unknown'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testResourceDeleteCausedError()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/collection/test.txt' ),
- 'Expected existing file.'
- );
- chmod ( $this->tempDir . 'backend/collection', 0 );
- // @TODO: This can be removed with the latest PHPUnit release, but for
- // now we need it, or the is_file() call on backend/collection/test.txt
- // will return a wrong cached result.
- clearstatcache();
- $request = new ezcWebdavDeleteRequest( '/collection/test.txt' );
- $request->validateHeaders();
- $response = $backend->delete( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_404,
- '/collection/test.txt'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected still existing file.'
- );
- chmod ( $this->tempDir . 'backend/collection', 0777 );
- }
- public function testResourceDeleteFailure()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/collection/test.txt' ),
- 'Expected existing file.'
- );
- chmod ( $this->tempDir . 'backend/collection', 0555 );
- // @TODO: This can be removed with the latest PHPUnit release, but for
- // now we need it, or the is_file() call on backend/collection/test.txt
- // will return a wrong cached result.
- clearstatcache();
- $request = new ezcWebdavDeleteRequest( '/collection/test.txt' );
- $request->validateHeaders();
- $response = $backend->delete( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMultistatusResponse(
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_403,
- '/collection/test.txt'
- )
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected still existing file.'
- );
- chmod ( $this->tempDir . 'backend/collection', 0777 );
- }
- public function testMakeCollectionOnExistingCollection()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMakeCollectionRequest( '/collection' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_405,
- '/collection'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testMakeCollectionOnExistingRessource()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMakeCollectionRequest( '/resource' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_405,
- '/resource'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testMakeCollectionMissingParent()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMakeCollectionRequest( '/dum/di' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/dum/di'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testMakeCollectionInRessource()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMakeCollectionRequest( '/resource/collection' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_403,
- '/resource/collection'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testMakeCollectionWithRequestBody()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavMakeCollectionRequest( '/collection/new_collection', 'with request body' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_415,
- '/collection/new_collection'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testMakeCollection()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertFalse(
- is_dir( $this->tempDir . 'backend/collection/new_collection' ),
- 'Expected collection not existing yet.'
- );
- $request = new ezcWebdavMakeCollectionRequest( '/collection/new_collection' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMakeCollectionResponse(
- '/bar/foo'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection/new_collection' ),
- 'Expected created collection.'
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection/new_collection/.ezc' ),
- 'Expected property storage in directory.'
- );
- }
- public function testMakeCollectionWithSpaces()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertFalse(
- is_dir( $this->tempDir . 'backend/collection/new_collection' ),
- 'Collection to create exists.'
- );
- $request = new ezcWebdavMakeCollectionRequest( '/collection/collection%20with%20spaces' );
- $request->validateHeaders();
- $response = $backend->makeCollection( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavMakeCollectionResponse(
- '/collection/collection%20with%20spaces'
- ),
- 'Expected response does not match real response.'
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection/collection%20with%20spaces' ),
- 'Expected created collection.'
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection/collection%20with%20spaces/.ezc' ),
- 'Expected property storage in directory.'
- );
- $this->assertEquals(
- 'collection with spaces',
- $backend->getAllProperties( '/collection/collection%20with%20spaces' )->get( 'displayname', 'DAV:' )->displayName
- );
- }
- public function testPutOnExistingCollection()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavPutRequest( '/collection', 'some content' );
- $request->setHeader( 'Content-Length', 23 );
- $request->validateHeaders();
- $response = $backend->put( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/collection'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testPutMissingParent()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavPutRequest( '/dum/di', 'some content' );
- $request->setHeader( 'Content-Length', 23 );
- $request->validateHeaders();
- $response = $backend->put( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/dum/di'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testPutInRessource()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $request = new ezcWebdavPutRequest( '/resource/new_resource', 'some content' );
- $request->setHeader( 'Content-Length', 23 );
- $request->validateHeaders();
- $response = $backend->put( $request );
- $this->assertEquals(
- $response,
- new ezcWebdavErrorResponse(
- ezcWebdavResponse::STATUS_409,
- '/resource/new_resource'
- ),
- 'Expected response does not match real response.',
- 0,
- 20
- );
- }
- public function testPut()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertFalse(
- is_file( $this->tempDir . 'backend/collection/new_resource' ),
- 'Expected resource not existing yet.'
- );
- $request = new ezcWebdavPutRequest( '/collection/new_resource', 'some content' );
- $request->setHeader( 'Content-Length', 23 );
- $request->validateHeaders();
- $response = $backend->put( $request );
- $expectedResponse = new ezcWebdavPutResponse(
- '/collection/new_resource'
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/collection/new_resource', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/collection/new_resource' ),
- 'Expected created resource.'
- );
- $this->assertEquals(
- 'some content',
- file_get_contents( $this->tempDir . 'backend/collection/new_resource' )
- );
- $this->assertTrue(
- is_dir( $this->tempDir . 'backend/collection/.ezc' ),
- 'Expected property storage in directory.'
- );
- }
- public function testPutOnExistingRessource()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected created resource.'
- );
- $this->assertEquals(
- "Some webdav contents.\n",
- file_get_contents( $this->tempDir . 'backend/resource' )
- );
- $request = new ezcWebdavPutRequest( '/resource', 'some content' );
- $request->setHeader( 'Content-Length', strlen( $request->body ) );
- $request->validateHeaders();
- $response = $backend->put( $request );
-
- $expectedResponse = new ezcWebdavPutResponse(
- '/resource'
- );
- $expectedResponse->setHeader( 'ETag', $backend->getProperty( '/resource', 'getetag' )->etag );
- $this->assertEquals(
- $expectedResponse,
- $response,
- 'Expected response does not match real response.',
- 0,
- 20
- );
- $this->assertTrue(
- is_file( $this->tempDir . 'backend/resource' ),
- 'Expected created resource.'
- );
- $this->assertEquals(
- 'some content',
- file_get_contents( $this->tempDir . 'backend/resource' )
- );
- }
- public function testPropFindOnResource()
- {
- $backend = new ezcWebdavFileBackend( $this->tempDir . 'backend/' );
- $requestedProperties = new ezcWebdavBasicPropertyStorage();
- $requestedProperties->attach(
- $prop1 = new ezcWebdavGetContentLengthProperty()
- );
- $requestedProperties->attach(
- $prop2 = new ezcWebdavGetLastModifiedProperty()
- );
- $requestedProperties->attach(
- $prop3 = new ezcWebdavDeadProperty( 'http://apache.org/dav/props/', 'executable' )
- );
- $request = new ezcWebdavPropFindRequest( '/resource' );
- $request->prop = $requestedProperties;
- $request->validateHeaders();
- $response = $backend->propfind( $request );
- $this->compareResponse( __FUNCTION__, $response );
- }
- public function testPropMimeTypeOnResourceNoExt()
- {
- if ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) ||
- ezcBaseFeatures::hasExtensionSupport( 'mime_magic' ) )
- {
- $this->markTestSkipped( 'Test is run only, when no mime type detection is available.' );
- }
- $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/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 testPropMimeTypeOnResourceMimeMagicExt()
- {
- if ( ezcBaseFeatures::hasExtensionSupport( 'fileinfo' ) ||
- !ezcBaseFeatures::hasExtensionSupport( 'mime_magic' ) )
- {
- $this->markTestSkipped( 'Test is run only, when only mime magic extension is available.' );
- }
- $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.',
- …
Large files files are truncated, but you can click here to view the full file