PluginTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\CardDAV\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\IRequest;
  32. use Sabre\DAV\Server;
  33. use Sabre\DAV\SimpleCollection;
  34. use Sabre\HTTP\Request;
  35. use Sabre\HTTP\Response;
  36. use Test\TestCase;
  37. class PluginTest extends TestCase {
  38. /** @var Plugin */
  39. private $plugin;
  40. /** @var Server */
  41. private $server;
  42. /** @var IShareable | \PHPUnit_Framework_MockObject_MockObject */
  43. private $book;
  44. protected function setUp(): void {
  45. parent::setUp();
  46. /** @var Auth | \PHPUnit_Framework_MockObject_MockObject $authBackend */
  47. $authBackend = $this->getMockBuilder(Auth::class)->disableOriginalConstructor()->getMock();
  48. $authBackend->method('isDavAuthenticated')->willReturn(true);
  49. /** @var IRequest $request */
  50. $request = $this->getMockBuilder(IRequest::class)->disableOriginalConstructor()->getMock();
  51. $this->plugin = new Plugin($authBackend, $request);
  52. $root = new SimpleCollection('root');
  53. $this->server = new \Sabre\DAV\Server($root);
  54. /** @var SimpleCollection $node */
  55. $this->book = $this->getMockBuilder(IShareable::class)->disableOriginalConstructor()->getMock();
  56. $this->book->method('getName')->willReturn('addressbook1.vcf');
  57. $root->addChild($this->book);
  58. $this->plugin->initialize($this->server);
  59. }
  60. public function testSharing() {
  61. $this->book->expects($this->once())->method('updateShares')->with([[
  62. 'href' => 'principal:principals/admin',
  63. 'commonName' => null,
  64. 'summary' => null,
  65. 'readOnly' => false
  66. ]], ['mailto:wilfredo@example.com']);
  67. // setup request
  68. $request = new Request('POST', 'addressbook1.vcf');
  69. $request->addHeader('Content-Type', 'application/xml');
  70. $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>');
  71. $response = new Response();
  72. $this->plugin->httpPost($request, $response);
  73. }
  74. }