InvalidPathTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\unit\Connector\Sabre\Exception;
  8. use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
  9. class InvalidPathTest extends \Test\TestCase {
  10. public function testSerialization(): void {
  11. // create xml doc
  12. $DOM = new \DOMDocument('1.0', 'utf-8');
  13. $DOM->formatOutput = true;
  14. $error = $DOM->createElementNS('DAV:', 'd:error');
  15. $error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV);
  16. $DOM->appendChild($error);
  17. // serialize the exception
  18. $message = '1234567890';
  19. $retry = false;
  20. $expectedXml = <<<EOD
  21. <?xml version="1.0" encoding="utf-8"?>
  22. <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns">
  23. <o:retry xmlns:o="o:">false</o:retry>
  24. <o:reason xmlns:o="o:">1234567890</o:reason>
  25. </d:error>
  26. EOD;
  27. $ex = new InvalidPath($message, $retry);
  28. $server = $this->getMockBuilder('Sabre\DAV\Server')
  29. ->disableOriginalConstructor()
  30. ->getMock();
  31. $ex->serialize($server, $error);
  32. // assert
  33. $xml = $DOM->saveXML();
  34. $this->assertEquals($expectedXml, $xml);
  35. }
  36. }