InvalidPathTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\Connector\Sabre\Exception;
  25. use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
  26. class InvalidPathTest extends \Test\TestCase {
  27. public function testSerialization(): void {
  28. // create xml doc
  29. $DOM = new \DOMDocument('1.0', 'utf-8');
  30. $DOM->formatOutput = true;
  31. $error = $DOM->createElementNS('DAV:', 'd:error');
  32. $error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV);
  33. $DOM->appendChild($error);
  34. // serialize the exception
  35. $message = "1234567890";
  36. $retry = false;
  37. $expectedXml = <<<EOD
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns">
  40. <o:retry xmlns:o="o:">false</o:retry>
  41. <o:reason xmlns:o="o:">1234567890</o:reason>
  42. </d:error>
  43. EOD;
  44. $ex = new InvalidPath($message, $retry);
  45. $server = $this->getMockBuilder('Sabre\DAV\Server')
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. $ex->serialize($server, $error);
  49. // assert
  50. $xml = $DOM->saveXML();
  51. $this->assertEquals($expectedXml, $xml);
  52. }
  53. }