You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CopyEtagHeaderPluginTest.php 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\DAV\Tests\unit\Connector\Sabre;
  28. use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
  29. use OCA\DAV\Connector\Sabre\File;
  30. use Sabre\DAV\Server;
  31. use Sabre\DAV\Tree;
  32. use Test\TestCase;
  33. /**
  34. * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
  35. * This file is licensed under the Affero General Public License version 3 or
  36. * later.
  37. * See the COPYING-README file.
  38. */
  39. class CopyEtagHeaderPluginTest extends TestCase {
  40. /** @var CopyEtagHeaderPlugin */
  41. private $plugin;
  42. /** @var Server */
  43. private $server;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. $this->server = new \Sabre\DAV\Server();
  47. $this->plugin = new CopyEtagHeaderPlugin();
  48. $this->plugin->initialize($this->server);
  49. }
  50. public function testCopyEtag() {
  51. $request = new \Sabre\Http\Request('GET', 'dummy.file');
  52. $response = new \Sabre\Http\Response();
  53. $response->setHeader('Etag', 'abcd');
  54. $this->plugin->afterMethod($request, $response);
  55. $this->assertEquals('abcd', $response->getHeader('OC-Etag'));
  56. }
  57. public function testNoopWhenEmpty() {
  58. $request = new \Sabre\Http\Request('GET', 'dummy.file');
  59. $response = new \Sabre\Http\Response();
  60. $this->plugin->afterMethod($request, $response);
  61. $this->assertNull($response->getHeader('OC-Etag'));
  62. }
  63. public function testAfterMove() {
  64. $node = $this->getMockBuilder(File::class)
  65. ->disableOriginalConstructor()
  66. ->getMock();
  67. $node->expects($this->once())
  68. ->method('getETag')
  69. ->willReturn('123456');
  70. $tree = $this->getMockBuilder(Tree::class)
  71. ->disableOriginalConstructor()
  72. ->getMock();
  73. $tree->expects($this->once())
  74. ->method('getNodeForPath')
  75. ->with('test.txt')
  76. ->willReturn($node);
  77. $this->server->tree = $tree;
  78. $this->plugin->afterMove('', 'test.txt');
  79. $this->assertEquals('123456', $this->server->httpResponse->getHeader('OC-Etag'));
  80. $this->assertEquals('123456', $this->server->httpResponse->getHeader('Etag'));
  81. }
  82. }