CopyEtagHeaderPluginTest.php 2.8 KB

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