PluginTest.php 2.9 KB

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