PluginTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  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\DAV\Sharing;
  28. use OCA\DAV\Connector\Sabre\Auth;
  29. use OCA\DAV\DAV\Sharing\IShareable;
  30. use OCA\DAV\DAV\Sharing\Plugin;
  31. use OCP\IConfig;
  32. use OCP\IRequest;
  33. use Sabre\DAV\Server;
  34. use Sabre\DAV\SimpleCollection;
  35. use Sabre\HTTP\Request;
  36. use Sabre\HTTP\Response;
  37. use Test\TestCase;
  38. class PluginTest extends TestCase {
  39. /** @var Plugin */
  40. private $plugin;
  41. /** @var Server */
  42. private $server;
  43. /** @var IShareable | \PHPUnit\Framework\MockObject\MockObject */
  44. private $book;
  45. protected function setUp(): void {
  46. parent::setUp();
  47. /** @var Auth | \PHPUnit\Framework\MockObject\MockObject $authBackend */
  48. $authBackend = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
  49. $authBackend->method('isDavAuthenticated')->willReturn(true);
  50. /** @var IRequest $request */
  51. $request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock();
  52. $config = $this->createMock(IConfig::class);
  53. $this->plugin = new Plugin($authBackend, $request, $config);
  54. $root = new SimpleCollection('root');
  55. $this->server = new \Sabre\DAV\Server($root);
  56. /** @var SimpleCollection $node */
  57. $this->book = $this->getMockBuilder(IShareable::class)->
  58. disableOriginalConstructor()->
  59. getMock();
  60. $this->book->method('getName')->willReturn('addressbook1.vcf');
  61. $root->addChild($this->book);
  62. $this->plugin->initialize($this->server);
  63. }
  64. public function testSharing(): void {
  65. $this->book->expects($this->once())->method('updateShares')->with([[
  66. 'href' => 'principal:principals/admin',
  67. 'commonName' => null,
  68. 'summary' => null,
  69. 'readOnly' => false
  70. ]], ['mailto:wilfredo@example.com']);
  71. // setup request
  72. $request = new Request('POST', 'addressbook1.vcf');
  73. $request->addHeader('Content-Type', 'application/xml');
  74. $request->setBody('<?xml version="1.0" encoding="utf-8" ?><CS:share xmlns:D="DAV:" xmlns:CS="http://owncloud.org/ns"><CS:set><D:href>principal:principals/admin</D:href><CS:read-write/></CS:set> <CS:remove><D:href>mailto:wilfredo@example.com</D:href></CS:remove></CS:share>');
  75. $response = new Response();
  76. $this->plugin->httpPost($request, $response);
  77. }
  78. }