init( new ezcWebdavBasicPathFactory( 'http://example.com/foo/bar' ), new ezcWebdavXmlTool(), new ezcWebdavPropertyHandler(), new ezcWebdavHeaderHandler(), new ezcWebdavMockedTransport() ); parent::setUp(); } protected function tearDown() { ezcWebdavServer::getInstance()->reset(); parent::tearDown(); } public function testParseUnknownRequest() { $_SERVER['DOCUMENT_ROOT'] = '/var/www/localhost/htdocs'; $_SERVER['HTTP_USER_AGENT'] = 'RFC compliant'; $_SERVER['SCRIPT_FILENAME'] = '/var/www/localhost/htdocs'; $_SERVER['SERVER_NAME'] = 'webdav'; $_SERVER['REQUEST_METHOD'] = 'UNKNOWN'; $uri = 'http://example.com/foo/bar/baz.html'; $res = ezcWebdavServer::getInstance()->transport->parseRequest( $uri ); $this->assertEquals( new ezcWebdavErrorResponse( ezcWebdavResponse::STATUS_501, $uri ), $res, 'Error response not generated on UNKNOWN request method' ); } public function testHandleMiscException() { $e = new Exception( 'Foo bar' ); $uri = 'http://example.com/foo/bar/baz.html'; $res = ezcWebdavServer::getInstance()->transport->handleException( $e, $uri ); $this->assertEquals( new ezcWebdavErrorResponse( ezcWebdavResponse::STATUS_500, $uri, $e->getMessage() ), $res, 'Error response not generated when handling unknown exception.' ); } public function testHandleUnknownResponse() { $uri = 'http://example.com/foo/bar/baz.html'; $response = new ezcWebdavMockedErrorResponse( ezcWebdavResponse::STATUS_500, $uri, 'Foo bar' ); // Silence warning of headers already been send, but keep other errors $errRep = error_reporting( ( E_ALL | E_STRICT ) & ~E_WARNING ); $res = ezcWebdavServer::getInstance()->transport->handleResponse( $response ); // Reset old error level error_reporting( $errRep ); $this->assertNull( $res, 'Result incorrect on handling of completly unknown response.' ); } public function testFlattenResponseErrorMissingContentTypeHeader() { $uri = 'http://example.com/foo/bar/baz.html'; $info = new ezcWebdavStringDisplayInformation( new ezcWebdavMockedErrorResponse( ezcWebdavResponse::STATUS_500, $uri ), 'Foo bar' ); $info->response->setHeader( 'Server', 'Foo bar baz server' ); $info->response->validateHeaders(); try { $res = ezcWebdavServer::getInstance()->transport->flattenResponse( $info ); $this->fail( 'Exception not thrown on missing Content-Type header in string display info.' ); } catch ( ezcWebdavMissingHeaderException $e ) {} } public function testFlattenResponseErrorContentTypeHeaderTooMuch() { $uri = 'http://example.com/foo/bar/baz.html'; $info = new ezcWebdavEmptyDisplayInformation( new ezcWebdavMockedErrorResponse( ezcWebdavResponse::STATUS_500, $uri ) ); $info->response->setHeader( 'Server', 'Foo bar baz server' ); $info->response->setHeader( 'Content-Type', 'text/xml; charset="utf-8"' ); $info->response->validateHeaders(); try { $res = ezcWebdavServer::getInstance()->transport->flattenResponse( $info ); $this->fail( 'Exception not thrown on missing Content-Type header in string display info.' ); } catch ( ezcWebdavInvalidHeaderException $e ) {} } public function testParseCopyRequestErrorMissingHeader() { $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parseCopyRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing copy request without destination header.' ); } catch ( ezcWebdavMissingHeaderException $e ) { return; } } public function testParseCopyRequestErrorBodyInvalidXml() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parseCopyRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing copy request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) {} } public function testParseCopyRequestErrorMissingPropertyBehaviourTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; try { ezcWebdavServer::getInstance()->transport->parseCopyRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing copy request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) {} } public function testParseCopyRequestPropertyBehaviourOmitTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; $res = ezcWebdavServer::getInstance()->transport->parseCopyRequest( $path, $body ); $this->assertTrue( ( $res instanceof ezcWebdavCopyRequest ), 'Request not parsed correctly: Invalid request class!' ); $this->assertTrue( $res->propertyBehaviour->omit, 'Omit property of response object not set correctly.' ); } public function testParseCopyRequestPropertyBehaviourKeepaliveTagWithHrefContent() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << some property another property EOT; $res = ezcWebdavServer::getInstance()->transport->parseCopyRequest( $path, $body ); $this->assertTrue( ( $res instanceof ezcWebdavCopyRequest ), 'Request not parsed correctly: Invalid request class!' ); $this->assertEquals( array( 'some property', 'another property', ), $res->propertyBehaviour->keepAlive, 'Omit property of response object not set correctly.' ); } public function testParseMoveRequestErrorMissingHeader() { $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parseMoveRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing move request without destination header.' ); } catch ( ezcWebdavMissingHeaderException $e ) { return; } } public function testParseMoveRequestErrorBodyInvalidXml() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parseMoveRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing move request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) {} } public function testParseMoveRequestErrorMissingPropertyBehaviourTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; try { ezcWebdavServer::getInstance()->transport->parseMoveRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing move request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) {} } public function testParseMoveRequestPropertyBehaviourOmitTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; $res = ezcWebdavServer::getInstance()->transport->parseMoveRequest( $path, $body ); $this->assertTrue( ( $res instanceof ezcWebdavMoveRequest ), 'Request not parsed correctly: Invalid request class!' ); $this->assertTrue( $res->propertyBehaviour->omit, 'Omit property of response object not set correctly.' ); } public function testParseMoveRequestPropertyBehaviourKeepaliveTagWithHrefContent() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << some property another property EOT; $res = ezcWebdavServer::getInstance()->transport->parseMoveRequest( $path, $body ); $this->assertTrue( ( $res instanceof ezcWebdavMoveRequest ), 'Request not parsed correctly: Invalid request class!' ); $this->assertEquals( array( 'some property', 'another property', ), $res->propertyBehaviour->keepAlive, 'Omit property of response object not set correctly.' ); } public function testParsePropFindRequestErrorBodyInvalidXml() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parsePropFindRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing propfind request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) { return; } } public function testParsePropFindRequestErrorBodyMissingPropFindTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; try { ezcWebdavServer::getInstance()->transport->parsePropFindRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing propfind request with invalid XML root element.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) { return; } } public function testParsePropFindRequestErrorBodyMissingPropFindTagChildren() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << EOT; try { ezcWebdavServer::getInstance()->transport->parsePropFindRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing propfind request with missing child tags for the propfind XML element.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) { return; } } public function testParsePropPatchRequestErrorBodyInvalidXml() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = 'Foo bar baz'; try { ezcWebdavServer::getInstance()->transport->parsePropPatchRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing propfind request with invalid XML body.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) { return; } } public function testParsePropPatchRequestErrorBodyMissingPropertyUpdateTag() { $_SERVER['HTTP_DESTINATION'] = '/foo/bar/baz.html'; $path = '/baz.html'; $body = << Jim Whitehead Roy Fielding EOT; try { ezcWebdavServer::getInstance()->transport->parsePropPatchRequest( $path, $body ); $this->fail( 'Exception not thrown on parsing propfind request with invalid XML root element.' ); } catch ( ezcWebdavInvalidRequestBodyException $e ) { return; } } public function testProcessErrorResponseWithResponseDescription() { $uri = 'http://example.com/foo/bar/baz.html'; $response = new ezcWebdavErrorResponse( ezcWebdavResponse::STATUS_500, $uri, 'Some error occured!' ); $res = ezcWebdavServer::getInstance()->transport->processErrorResponse( $response, true ); $this->assertTrue( ( $res instanceof ezcWebdavXmlDisplayInformation ), 'Response not processed correctly: Invalid display information class!' ); $nodelist = $res->body->getElementsByTagNameNS( 'DAV:', 'responsedescription' ); $this->assertEquals( 1, $nodelist->length, 'No responsedescripion tag generated.' ); $this->assertEquals( $response->responseDescription, $nodelist->item( 0 )->nodeValue, 'Response description content not generated correctly.' ); } } ?>