public function testValidateHeadersFailure() { $req = new ezcWebdavCopyRequest('/foo', '/bar'); $req->setHeader('Overwrite', null); try { $req->validateHeaders(); $this->fail('Exception not thrown on missing Overwrite header.'); } catch (ezcWebdavMissingHeaderException $e) { } $req->setHeader('Overwrite', 'A'); try { $req->validateHeaders(); $this->fail('Exception not thrown on invalid Overwrite header.'); } catch (ezcWebdavInvalidHeaderException $e) { } // Fix this problem to test others $req->setHeader('Overwrite', 'T'); $req->setHeader('Depth', null); try { $req->validateHeaders(); $this->fail('Exception not thrown on missing Depth header.'); } catch (ezcWebdavMissingHeaderException $e) { } $req->setHeader('Depth', 'A'); try { $req->validateHeaders(); $this->fail('Exception not thrown on invalid Depth header.'); } catch (ezcWebdavInvalidHeaderException $e) { } }
public function testCopyCollectionWithInvalidETag() { $testSourcePath = '/collection'; $testSource = "{$testSourcePath}/deep_collection"; $testDestPath = $testSourcePath; $testDest = "{$testDestPath}/copied_collection"; $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/'); // Initialize all property directories $req = new ezcWebdavPropFindRequest($testSource); $req->allProp = true; $req->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY); $req->validateHeaders(); $backend->propFind($req); $eTag = $backend->getProperty($testDestPath, 'getetag')->etag; $req = new ezcWebdavCopyRequest($testSource, $testDest); $req->setHeader('If-None-Match', array('abc23', $eTag)); $req->validateHeaders(); $res = $backend->copy($req); $this->assertEquals(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_412, '/collection', 'If-None-Match header check failed.'), $res, 'Expected response does not match real response.', 0, 20); }
public function testResourceCopyDepthInfinityErrors() { $backend = new ezcWebdavMemoryBackend(false); $backend->addContents(array('bar' => array('_1' => 'contents', '_2' => 'contents', '_3' => 'contents', '_4' => 'contents', '_5' => 'contents'))); $backend->options->failingOperations = ezcWebdavMemoryBackendOptions::REQUEST_COPY; $backend->options->failForRegexp = '(_[24]$)'; $request = new ezcWebdavCopyRequest('/bar', '/foo'); $request->setHeader('Depth', ezcWebdavRequest::DEPTH_INFINITY); $request->validateHeaders(); $response = $backend->copy($request); $this->assertEquals(new ezcWebdavMultistatusResponse(new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_423, '/bar/_2'), new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_423, '/bar/_4')), $response, 'Expected response does not match real response.', 0, 20); $content = $this->readAttribute($backend, 'content'); $this->assertEquals(array('/' => array('/bar', '/foo'), '/bar' => array('/bar/_1', '/bar/_2', '/bar/_3', '/bar/_4', '/bar/_5'), '/bar/_1' => 'contents', '/bar/_2' => 'contents', '/bar/_3' => 'contents', '/bar/_4' => 'contents', '/bar/_5' => 'contents', '/foo' => array('/foo/_1', '/foo/_3', '/foo/_5'), '/foo/_1' => 'contents', '/foo/_3' => 'contents', '/foo/_5' => 'contents'), $content); }
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); }