ShareTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @author Roeland Jago Douma <rullzer@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Share20;
  22. use OCP\Files\IRootFolder;
  23. use OCP\IUserManager;
  24. /**
  25. * Class ShareTest
  26. *
  27. * @package Test\Share20
  28. */
  29. class ShareTest extends \Test\TestCase {
  30. /** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
  31. protected $rootFolder;
  32. /** @var \OCP\Share\IShare */
  33. protected $share;
  34. protected function setUp(): void {
  35. $this->rootFolder = $this->createMock(IRootFolder::class);
  36. $this->userManager = $this->createMock(IUserManager::class);
  37. $this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
  38. }
  39. public function testSetIdInvalid() {
  40. $this->expectException(\InvalidArgumentException::class);
  41. $this->expectExceptionMessage('String expected.');
  42. $this->share->setId(1.2);
  43. }
  44. public function testSetIdInt() {
  45. $this->share->setId(42);
  46. $this->assertEquals('42', $this->share->getId());
  47. }
  48. public function testSetIdString() {
  49. $this->share->setId('foo');
  50. $this->assertEquals('foo', $this->share->getId());
  51. }
  52. public function testSetIdOnce() {
  53. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  54. $this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
  55. $this->share->setId('foo');
  56. $this->share->setId('bar');
  57. }
  58. public function testSetProviderIdInt() {
  59. $this->expectException(\InvalidArgumentException::class);
  60. $this->expectExceptionMessage('String expected.');
  61. $this->share->setProviderId(42);
  62. }
  63. public function testSetProviderIdString() {
  64. $this->share->setProviderId('foo');
  65. $this->share->setId('bar');
  66. $this->assertEquals('foo:bar', $this->share->getFullId());
  67. }
  68. public function testSetProviderIdOnce() {
  69. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  70. $this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
  71. $this->share->setProviderId('foo');
  72. $this->share->setProviderId('bar');
  73. }
  74. }