2016-03-30 17:08:35 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-03-30 17:08:35 -04:00
|
|
|
*/
|
2019-11-22 14:52:10 -05:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
namespace Test\Share20;
|
|
|
|
|
|
2025-06-12 12:31:58 -04:00
|
|
|
use OC\Share20\Share;
|
2016-03-30 17:08:35 -04:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-09-07 14:24:06 -04:00
|
|
|
use OCP\IUserManager;
|
2025-06-12 12:31:58 -04:00
|
|
|
use OCP\Share\Exceptions\IllegalIDChangeException;
|
2025-06-30 10:56:59 -04:00
|
|
|
use OCP\Share\IShare;
|
2022-11-14 11:06:28 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-03-30 17:08:35 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ShareTest
|
|
|
|
|
*
|
|
|
|
|
* @package Test\Share20
|
|
|
|
|
*/
|
|
|
|
|
class ShareTest extends \Test\TestCase {
|
2026-01-15 11:32:18 -05:00
|
|
|
protected IRootFolder&MockObject $rootFolder;
|
|
|
|
|
protected IUserManager&MockObject $userManager;
|
|
|
|
|
protected IShare $share;
|
2016-03-30 17:08:35 -04:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-09-07 14:24:06 -04:00
|
|
|
$this->rootFolder = $this->createMock(IRootFolder::class);
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->share = new Share($this->rootFolder, $this->userManager);
|
2016-03-30 17:08:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetIdInt(): void {
|
|
|
|
|
$this->share->setId(42);
|
|
|
|
|
$this->assertEquals('42', $this->share->getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetIdString(): void {
|
|
|
|
|
$this->share->setId('foo');
|
|
|
|
|
$this->assertEquals('foo', $this->share->getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetIdOnce(): void {
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->expectException(IllegalIDChangeException::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
|
|
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
$this->share->setId('foo');
|
|
|
|
|
$this->share->setId('bar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetProviderIdString(): void {
|
|
|
|
|
$this->share->setProviderId('foo');
|
|
|
|
|
$this->share->setId('bar');
|
|
|
|
|
$this->assertEquals('foo:bar', $this->share->getFullId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSetProviderIdOnce(): void {
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->expectException(IllegalIDChangeException::class);
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
|
|
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
$this->share->setProviderId('foo');
|
|
|
|
|
$this->share->setProviderId('bar');
|
|
|
|
|
}
|
|
|
|
|
}
|