PluginTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\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)->disableOriginalConstructor()->getMock();
  58. $this->book->method('getName')->willReturn('addressbook1.vcf');
  59. $root->addChild($this->book);
  60. $this->plugin->initialize($this->server);
  61. }
  62. public function testSharing() {
  63. $this->book->expects($this->once())->method('updateShares')->with([[
  64. 'href' => 'principal:principals/admin',
  65. 'commonName' => null,
  66. 'summary' => null,
  67. 'readOnly' => false
  68. ]], ['mailto:wilfredo@example.com']);
  69. // setup request
  70. $request = new Request('POST', 'addressbook1.vcf');
  71. $request->addHeader('Content-Type', 'application/xml');
  72. $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>');
  73. $response = new Response();
  74. $this->plugin->httpPost($request, $response);
  75. }
  76. }