diff options
Diffstat (limited to 'apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php | 115 |
1 files changed, 40 insertions, 75 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php index 48658f3ffa3..cafbdd3ca40 100644 --- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php @@ -1,44 +1,22 @@ <?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> - * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @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/> - * - */ -namespace OCA\DAV\Tests\unit\Connector\Sabre; +declare(strict_types=1); /** - * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ +namespace OCA\DAV\Tests\unit\Connector\Sabre; +use OCA\DAV\CalDAV\DefaultCalendarValidator; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\File; +use OCA\DAV\DAV\CustomPropertiesBackend; +use OCA\DAV\Db\PropertyMapper; +use OCP\IDBConnection; use OCP\IUser; +use OCP\Server; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\DAV\Tree; /** @@ -49,55 +27,42 @@ use Sabre\DAV\Tree; * @package OCA\DAV\Tests\unit\Connector\Sabre */ class CustomPropertiesBackendTest extends \Test\TestCase { - - /** - * @var \Sabre\DAV\Server - */ - private $server; - - /** - * @var \Sabre\DAV\Tree - */ - private $tree; - - /** - * @var \OCA\DAV\DAV\CustomPropertiesBackend - */ - private $plugin; - - /** - * @var \OCP\IUser - */ - private $user; + private \Sabre\DAV\Server $server; + private \Sabre\DAV\Tree&MockObject $tree; + private IUser&MockObject $user; + private DefaultCalendarValidator&MockObject $defaultCalendarValidator; + private CustomPropertiesBackend $plugin; protected function setUp(): void { parent::setUp(); + $this->server = new \Sabre\DAV\Server(); - $this->tree = $this->getMockBuilder(Tree::class) - ->disableOriginalConstructor() - ->getMock(); + $this->tree = $this->createMock(Tree::class); - $userId = $this->getUniqueID('testcustompropertiesuser'); + $userId = self::getUniqueID('testcustompropertiesuser'); - $this->user = $this->getMockBuilder(IUser::class) - ->disableOriginalConstructor() - ->getMock(); + $this->user = $this->createMock(IUser::class); $this->user->expects($this->any()) ->method('getUID') ->willReturn($userId); - $this->plugin = new \OCA\DAV\DAV\CustomPropertiesBackend( + $this->defaultCalendarValidator = $this->createMock(DefaultCalendarValidator::class); + + $this->plugin = new CustomPropertiesBackend( + $this->server, $this->tree, - \OC::$server->getDatabaseConnection(), - $this->user + Server::get(IDBConnection::class), + $this->user, + Server::get(PropertyMapper::class), + $this->defaultCalendarValidator, ); } protected function tearDown(): void { - $connection = \OC::$server->getDatabaseConnection(); + $connection = Server::get(IDBConnection::class); $deleteStatement = $connection->prepare( - 'DELETE FROM `*PREFIX*properties`' . - ' WHERE `userid` = ?' + 'DELETE FROM `*PREFIX*properties`' + . ' WHERE `userid` = ?' ); $deleteStatement->execute( [ @@ -105,12 +70,12 @@ class CustomPropertiesBackendTest extends \Test\TestCase { ] ); $deleteStatement->closeCursor(); + + parent::tearDown(); } - private function createTestNode($class) { - $node = $this->getMockBuilder($class) - ->disableOriginalConstructor() - ->getMock(); + private function createTestNode(string $class) { + $node = $this->createMock($class); $node->expects($this->any()) ->method('getId') ->willReturn(123); @@ -122,7 +87,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { return $node; } - private function applyDefaultProps($path = '/dummypath') { + private function applyDefaultProps($path = '/dummypath'): void { // properties to set $propPatch = new \Sabre\DAV\PropPatch([ 'customprop' => 'value1', @@ -146,7 +111,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { /** * Test that propFind on a missing file soft fails */ - public function testPropFindMissingFileSoftFail() { + public function testPropFindMissingFileSoftFail(): void { $propFind = new \Sabre\DAV\PropFind( '/dummypath', [ @@ -174,7 +139,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { /** * Test setting/getting properties */ - public function testSetGetPropertiesForFile() { + public function testSetGetPropertiesForFile(): void { $this->applyDefaultProps(); $propFind = new \Sabre\DAV\PropFind( @@ -200,7 +165,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { /** * Test getting properties from directory */ - public function testGetPropertiesForDirectory() { + public function testGetPropertiesForDirectory(): void { $this->applyDefaultProps('/dummypath'); $this->applyDefaultProps('/dummypath/test.txt'); @@ -247,7 +212,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase { /** * Test delete property */ - public function testDeleteProperty() { + public function testDeleteProperty(): void { $this->applyDefaultProps(); $propPatch = new \Sabre\DAV\PropPatch([ |