2016-03-30 17:08:35 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
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;
|
|
|
|
|
|
|
|
|
|
use OCP\Files\IRootFolder;
|
2016-09-07 14:24:06 -04:00
|
|
|
use OCP\IUserManager;
|
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 {
|
2022-11-14 11:06:28 -05:00
|
|
|
/** @var IRootFolder|MockObject */
|
2016-03-30 17:08:35 -04:00
|
|
|
protected $rootFolder;
|
2022-11-14 11:06:28 -05:00
|
|
|
/** @var IUserManager|MockObject */
|
|
|
|
|
protected $userManager;
|
2016-03-30 17:08:35 -04:00
|
|
|
/** @var \OCP\Share\IShare */
|
|
|
|
|
protected $share;
|
|
|
|
|
|
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);
|
2016-05-11 14:48:27 -04:00
|
|
|
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
2016-03-30 17:08:35 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
public function testSetIdInvalid(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
$this->expectExceptionMessage('String expected.');
|
|
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
$this->share->setId(1.2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
public function testSetIdOnce(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
|
|
|
|
|
$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');
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
public function testSetProviderIdInt(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
$this->expectExceptionMessage('String expected.');
|
|
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
$this->share->setProviderId(42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testSetProviderIdString(): void {
|
|
|
|
|
$this->share->setProviderId('foo');
|
|
|
|
|
$this->share->setId('bar');
|
|
|
|
|
$this->assertEquals('foo:bar', $this->share->getFullId());
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
|
2016-03-30 17:08:35 -04:00
|
|
|
public function testSetProviderIdOnce(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
|
|
|
|
|
$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');
|
|
|
|
|
}
|
|
|
|
|
}
|