2013-04-26 02:01:36 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Mount;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\Files\Storage\Temporary;
|
2013-04-26 02:01:36 +04:00
|
|
|
|
|
|
|
class LongId extends Temporary {
|
|
|
|
public function getId() {
|
|
|
|
return 'long:' . str_repeat('foo', 50) . parent::getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 16:38:20 +03:00
|
|
|
class ManagerTest extends \Test\TestCase {
|
2013-04-26 02:01:36 +04:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\Mount\Manager
|
|
|
|
*/
|
|
|
|
private $manager;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::setUp();
|
2013-04-26 02:01:36 +04:00
|
|
|
$this->manager = new \OC\Files\Mount\Manager();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFind() {
|
|
|
|
$this->assertNull($this->manager->find('/'));
|
|
|
|
|
2014-11-24 17:54:42 +03:00
|
|
|
$rootMount = new \OC\Files\Mount\MountPoint(new Temporary(array()), '/');
|
2013-04-26 02:01:36 +04:00
|
|
|
$this->manager->addMount($rootMount);
|
|
|
|
$this->assertEquals($rootMount, $this->manager->find('/'));
|
|
|
|
$this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
|
|
|
|
|
|
|
|
$storage = new Temporary(array());
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
|
2013-04-26 02:01:36 +04: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('/')));
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount2 = new \OC\Files\Mount\MountPoint(new Temporary(array()), '/bar');
|
2013-04-26 02:01:36 +04:00
|
|
|
$this->manager->addMount($mount2);
|
|
|
|
$this->assertEquals(2, count($this->manager->findIn('/')));
|
|
|
|
|
|
|
|
$id = $mount1->getStorageId();
|
|
|
|
$this->assertEquals(array($mount1), $this->manager->findByStorageId($id));
|
|
|
|
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
|
2013-04-26 02:01:36 +04:00
|
|
|
$this->manager->addMount($mount3);
|
|
|
|
$this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLong() {
|
|
|
|
$storage = new LongId(array());
|
2014-11-24 17:54:42 +03:00
|
|
|
$mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
|
2013-04-26 02:01:36 +04:00
|
|
|
$this->manager->addMount($mount);
|
|
|
|
|
|
|
|
$id = $mount->getStorageId();
|
|
|
|
$storageId = $storage->getId();
|
|
|
|
$this->assertEquals(array($mount), $this->manager->findByStorageId($id));
|
|
|
|
$this->assertEquals(array($mount), $this->manager->findByStorageId($storageId));
|
|
|
|
$this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId)));
|
|
|
|
}
|
|
|
|
}
|