You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShareTest.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. public function setUp() {
  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. /**
  40. * @expectedException \InvalidArgumentException
  41. * @expectedExceptionMessage String expected.
  42. */
  43. public function testSetIdInvalid() {
  44. $this->share->setId(1.2);
  45. }
  46. public function testSetIdInt() {
  47. $this->share->setId(42);
  48. $this->assertEquals('42', $this->share->getId());
  49. }
  50. public function testSetIdString() {
  51. $this->share->setId('foo');
  52. $this->assertEquals('foo', $this->share->getId());
  53. }
  54. /**
  55. * @expectedException \OCP\Share\Exceptions\IllegalIDChangeException
  56. * @expectedExceptionMessage Not allowed to assign a new internal id to a share
  57. */
  58. public function testSetIdOnce() {
  59. $this->share->setId('foo');
  60. $this->share->setId('bar');
  61. }
  62. /**
  63. * @expectedException \InvalidArgumentException
  64. * @expectedExceptionMessage String expected.
  65. */
  66. public function testSetProviderIdInt() {
  67. $this->share->setProviderId(42);
  68. }
  69. public function testSetProviderIdString() {
  70. $this->share->setProviderId('foo');
  71. $this->share->setId('bar');
  72. $this->assertEquals('foo:bar', $this->share->getFullId());
  73. }
  74. /**
  75. * @expectedException \OCP\Share\Exceptions\IllegalIDChangeException
  76. * @expectedExceptionMessage Not allowed to assign a new provider id to a share
  77. */
  78. public function testSetProviderIdOnce() {
  79. $this->share->setProviderId('foo');
  80. $this->share->setProviderId('bar');
  81. }
  82. }