ShareTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Share20;
  8. use OCP\Files\IRootFolder;
  9. use OCP\IUserManager;
  10. use PHPUnit\Framework\MockObject\MockObject;
  11. /**
  12. * Class ShareTest
  13. *
  14. * @package Test\Share20
  15. */
  16. class ShareTest extends \Test\TestCase {
  17. /** @var IRootFolder|MockObject */
  18. protected $rootFolder;
  19. /** @var IUserManager|MockObject */
  20. protected $userManager;
  21. /** @var \OCP\Share\IShare */
  22. protected $share;
  23. protected function setUp(): void {
  24. $this->rootFolder = $this->createMock(IRootFolder::class);
  25. $this->userManager = $this->createMock(IUserManager::class);
  26. $this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
  27. }
  28. public function testSetIdInvalid(): void {
  29. $this->expectException(\InvalidArgumentException::class);
  30. $this->expectExceptionMessage('String expected.');
  31. $this->share->setId(1.2);
  32. }
  33. public function testSetIdInt(): void {
  34. $this->share->setId(42);
  35. $this->assertEquals('42', $this->share->getId());
  36. }
  37. public function testSetIdString(): void {
  38. $this->share->setId('foo');
  39. $this->assertEquals('foo', $this->share->getId());
  40. }
  41. public function testSetIdOnce(): void {
  42. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  43. $this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
  44. $this->share->setId('foo');
  45. $this->share->setId('bar');
  46. }
  47. public function testSetProviderIdInt(): void {
  48. $this->expectException(\InvalidArgumentException::class);
  49. $this->expectExceptionMessage('String expected.');
  50. $this->share->setProviderId(42);
  51. }
  52. public function testSetProviderIdString(): void {
  53. $this->share->setProviderId('foo');
  54. $this->share->setId('bar');
  55. $this->assertEquals('foo:bar', $this->share->getFullId());
  56. }
  57. public function testSetProviderIdOnce(): void {
  58. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  59. $this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
  60. $this->share->setProviderId('foo');
  61. $this->share->setProviderId('bar');
  62. }
  63. }