ShareTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. use PHPUnit\Framework\MockObject\MockObject;
  25. /**
  26. * Class ShareTest
  27. *
  28. * @package Test\Share20
  29. */
  30. class ShareTest extends \Test\TestCase {
  31. /** @var IRootFolder|MockObject */
  32. protected $rootFolder;
  33. /** @var IUserManager|MockObject */
  34. protected $userManager;
  35. /** @var \OCP\Share\IShare */
  36. protected $share;
  37. protected function setUp(): void {
  38. $this->rootFolder = $this->createMock(IRootFolder::class);
  39. $this->userManager = $this->createMock(IUserManager::class);
  40. $this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
  41. }
  42. public function testSetIdInvalid() {
  43. $this->expectException(\InvalidArgumentException::class);
  44. $this->expectExceptionMessage('String expected.');
  45. $this->share->setId(1.2);
  46. }
  47. public function testSetIdInt() {
  48. $this->share->setId(42);
  49. $this->assertEquals('42', $this->share->getId());
  50. }
  51. public function testSetIdString() {
  52. $this->share->setId('foo');
  53. $this->assertEquals('foo', $this->share->getId());
  54. }
  55. public function testSetIdOnce() {
  56. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  57. $this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
  58. $this->share->setId('foo');
  59. $this->share->setId('bar');
  60. }
  61. public function testSetProviderIdInt() {
  62. $this->expectException(\InvalidArgumentException::class);
  63. $this->expectExceptionMessage('String expected.');
  64. $this->share->setProviderId(42);
  65. }
  66. public function testSetProviderIdString() {
  67. $this->share->setProviderId('foo');
  68. $this->share->setId('bar');
  69. $this->assertEquals('foo:bar', $this->share->getFullId());
  70. }
  71. public function testSetProviderIdOnce() {
  72. $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
  73. $this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
  74. $this->share->setProviderId('foo');
  75. $this->share->setProviderId('bar');
  76. }
  77. }