aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests/External/CacheTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/tests/External/CacheTest.php')
-rw-r--r--apps/files_sharing/tests/External/CacheTest.php89
1 files changed, 50 insertions, 39 deletions
diff --git a/apps/files_sharing/tests/External/CacheTest.php b/apps/files_sharing/tests/External/CacheTest.php
index a31a748a69b..39e2057a24c 100644
--- a/apps/files_sharing/tests/External/CacheTest.php
+++ b/apps/files_sharing/tests/External/CacheTest.php
@@ -1,30 +1,23 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.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/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Files_Sharing\Tests\External;
+use OC\Federation\CloudIdManager;
+use OC\Files\Storage\Storage;
+use OCA\Files_Sharing\External\Cache;
use OCA\Files_Sharing\Tests\TestCase;
+use OCP\Contacts\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Federation\ICloudIdManager;
+use OCP\Files\Cache\ICacheEntry;
+use OCP\ICacheFactory;
+use OCP\IURLGenerator;
+use OCP\IUserManager;
/**
* Class Cache
@@ -34,14 +27,16 @@ use OCA\Files_Sharing\Tests\TestCase;
* @package OCA\Files_Sharing\Tests\External
*/
class CacheTest extends TestCase {
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ protected $contactsManager;
/**
- * @var \OC\Files\Storage\Storage
+ * @var Storage
**/
private $storage;
/**
- * @var \OCA\Files_Sharing\External\Cache
+ * @var Cache
*/
private $cache;
@@ -50,9 +45,21 @@ class CacheTest extends TestCase {
*/
private $remoteUser;
- protected function setUp() {
+ /** @var ICloudIdManager */
+ private $cloudIdManager;
+
+ protected function setUp(): void {
parent::setUp();
+ $this->contactsManager = $this->createMock(IManager::class);
+
+ $this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
+ $this->contactsManager,
+ $this->createMock(IURLGenerator::class),
+ $this->createMock(IUserManager::class),
+ );
$this->remoteUser = $this->getUniqueID('remoteuser');
$this->storage = $this->getMockBuilder('\OCA\Files_Sharing\External\Storage')
@@ -61,30 +68,35 @@ class CacheTest extends TestCase {
$this->storage
->expects($this->any())
->method('getId')
- ->will($this->returnValue('dummystorage::'));
- $this->cache = new \OCA\Files_Sharing\External\Cache(
+ ->willReturn('dummystorage::');
+
+ $this->contactsManager->expects($this->any())
+ ->method('search')
+ ->willReturn([]);
+
+ $this->cache = new Cache(
$this->storage,
- 'http://example.com/owncloud',
- $this->remoteUser
+ $this->cloudIdManager->getCloudId($this->remoteUser, 'http://example.com/owncloud')
);
+ $this->cache->insert('', ['size' => 0, 'mtime' => 0, 'mimetype' => ICacheEntry::DIRECTORY_MIMETYPE]);
$this->cache->put(
'test.txt',
- array(
+ [
'mimetype' => 'text/plain',
'size' => 5,
'mtime' => 123,
- )
+ ]
);
}
- protected function tearDown() {
+ protected function tearDown(): void {
if ($this->cache) {
$this->cache->clear();
}
parent::tearDown();
}
- public function testGetInjectsOwnerDisplayName() {
+ public function testGetInjectsOwnerDisplayName(): void {
$info = $this->cache->get('test.txt');
$this->assertEquals(
$this->remoteUser . '@example.com/owncloud',
@@ -92,27 +104,27 @@ class CacheTest extends TestCase {
);
}
- public function testGetReturnsFalseIfNotFound() {
+ public function testGetReturnsFalseIfNotFound(): void {
$info = $this->cache->get('unexisting-entry.txt');
$this->assertFalse($info);
}
- public function testGetFolderPopulatesOwner() {
+ public function testGetFolderPopulatesOwner(): void {
$dirId = $this->cache->put(
'subdir',
- array(
+ [
'mimetype' => 'httpd/unix-directory',
'size' => 5,
'mtime' => 123,
- )
+ ]
);
$this->cache->put(
'subdir/contents.txt',
- array(
+ [
'mimetype' => 'text/plain',
'size' => 5,
'mtime' => 123,
- )
+ ]
);
$results = $this->cache->getFolderContentsById($dirId);
@@ -122,5 +134,4 @@ class CacheTest extends TestCase {
$results[0]['displayname_owner']
);
}
-
}