2016-03-31 00:08:35 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
namespace Test\Share20;
|
|
|
|
|
|
|
|
use OCP\Files\IRootFolder;
|
2016-09-07 21:24:06 +03:00
|
|
|
use OCP\IUserManager;
|
2016-03-31 00:08:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ShareTest
|
|
|
|
*
|
|
|
|
* @package Test\Share20
|
|
|
|
*/
|
|
|
|
class ShareTest extends \Test\TestCase {
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IRootFolder|\PHPUnit\Framework\MockObject\MockObject */
|
2016-03-31 00:08:35 +03:00
|
|
|
protected $rootFolder;
|
|
|
|
/** @var \OCP\Share\IShare */
|
|
|
|
protected $share;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-09-07 21:24:06 +03:00
|
|
|
$this->rootFolder = $this->createMock(IRootFolder::class);
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2016-05-11 21:48:27 +03:00
|
|
|
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
|
2016-03-31 00:08:35 +03:00
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
public function testSetIdInvalid() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessage('String expected.');
|
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
$this->share->setId(1.2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetIdInt() {
|
|
|
|
$this->share->setId(42);
|
|
|
|
$this->assertEquals('42', $this->share->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testSetIdString() {
|
|
|
|
$this->share->setId('foo');
|
|
|
|
$this->assertEquals('foo', $this->share->getId());
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
public function testSetIdOnce() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
|
|
|
|
$this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
|
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
$this->share->setId('foo');
|
|
|
|
$this->share->setId('bar');
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
public function testSetProviderIdInt() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessage('String expected.');
|
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
$this->share->setProviderId(42);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testSetProviderIdString() {
|
|
|
|
$this->share->setProviderId('foo');
|
|
|
|
$this->share->setId('bar');
|
|
|
|
$this->assertEquals('foo:bar', $this->share->getFullId());
|
|
|
|
}
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
public function testSetProviderIdOnce() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
|
|
|
|
$this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
|
|
|
|
|
2016-03-31 00:08:35 +03:00
|
|
|
$this->share->setProviderId('foo');
|
|
|
|
$this->share->setProviderId('bar');
|
|
|
|
}
|
|
|
|
}
|