2013-04-26 00:01:36 +02:00
|
|
|
<?php
|
2025-04-27 14:38:18 +02:00
|
|
|
|
2013-04-26 00:01:36 +02:00
|
|
|
/**
|
2024-05-10 15:09:14 +02:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2013-04-26 00:01:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Mount;
|
|
|
|
|
2022-03-02 19:38:21 +01:00
|
|
|
use OC\Files\SetupManagerFactory;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OC\Files\Storage\Temporary;
|
2013-04-26 00:01:36 +02:00
|
|
|
|
|
|
|
class LongId extends Temporary {
|
|
|
|
public function getId() {
|
|
|
|
return 'long:' . str_repeat('foo', 50) . parent::getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 15:38:20 +02:00
|
|
|
class ManagerTest extends \Test\TestCase {
|
2013-04-26 00:01:36 +02:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\Mount\Manager
|
|
|
|
*/
|
|
|
|
private $manager;
|
|
|
|
|
2019-11-21 16:40:38 +01:00
|
|
|
protected function setUp(): void {
|
2014-11-07 15:23:15 +01:00
|
|
|
parent::setUp();
|
2022-03-02 19:38:21 +01:00
|
|
|
$this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
|
2013-04-26 00:01:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFind() {
|
2020-03-26 09:30:18 +01:00
|
|
|
$rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
|
2013-04-26 00:01:36 +02:00
|
|
|
$this->manager->addMount($rootMount);
|
|
|
|
$this->assertEquals($rootMount, $this->manager->find('/'));
|
|
|
|
$this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
|
|
|
|
|
2020-03-26 09:30:18 +01:00
|
|
|
$storage = new Temporary([]);
|
2014-11-24 15:54:42 +01:00
|
|
|
$mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
|
2013-04-26 00:01:36 +02:00
|
|
|
$this->manager->addMount($mount1);
|
|
|
|
$this->assertEquals($rootMount, $this->manager->find('/'));
|
|
|
|
$this->assertEquals($mount1, $this->manager->find('/foo/bar'));
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($this->manager->findIn('/')));
|
2020-03-26 09:30:18 +01:00
|
|
|
$mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
|
2013-04-26 00:01:36 +02:00
|
|
|
$this->manager->addMount($mount2);
|
|
|
|
$this->assertEquals(2, count($this->manager->findIn('/')));
|
|
|
|
|
|
|
|
$id = $mount1->getStorageId();
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals([$mount1], $this->manager->findByStorageId($id));
|
2013-04-26 00:01:36 +02:00
|
|
|
|
2014-11-24 15:54:42 +01:00
|
|
|
$mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
|
2013-04-26 00:01:36 +02:00
|
|
|
$this->manager->addMount($mount3);
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
|
2013-04-26 00:01:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLong() {
|
2020-03-26 09:30:18 +01:00
|
|
|
$storage = new LongId([]);
|
2014-11-24 15:54:42 +01:00
|
|
|
$mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
|
2013-04-26 00:01:36 +02:00
|
|
|
$this->manager->addMount($mount);
|
|
|
|
|
|
|
|
$id = $mount->getStorageId();
|
|
|
|
$storageId = $storage->getId();
|
2020-03-26 09:30:18 +01:00
|
|
|
$this->assertEquals([$mount], $this->manager->findByStorageId($id));
|
|
|
|
$this->assertEquals([$mount], $this->manager->findByStorageId($storageId));
|
|
|
|
$this->assertEquals([$mount], $this->manager->findByStorageId(md5($storageId)));
|
2013-04-26 00:01:36 +02:00
|
|
|
}
|
|
|
|
}
|