Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ManagerTest.php « Mount « Files « lib « tests - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 159fffc7cb8b6a19d27fdce76c58317f682645a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?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;

use OC\Files\Storage\Temporary;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\IUserManager;

class LongId extends Temporary {
	public function getId() {
		return 'long:' . str_repeat('foo', 50) . parent::getId();
	}
}

class ManagerTest extends \Test\TestCase {
	/**
	 * @var \OC\Files\Mount\Manager
	 */
	private $manager;

	protected function setUp(): void {
		parent::setUp();
		$this->manager = new \OC\Files\Mount\Manager(
			$this->createMock(IEventLogger::class),
			$this->createMock(IMountProviderCollection::class),
			$this->createMock(IUserManager::class),
			$this->createMock(IEventDispatcher::class),
		);
	}

	public function testFind() {
		$rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
		$this->manager->addMount($rootMount);
		$this->assertEquals($rootMount, $this->manager->find('/'));
		$this->assertEquals($rootMount, $this->manager->find('/foo/bar'));

		$storage = new Temporary([]);
		$mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
		$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('/')));
		$mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
		$this->manager->addMount($mount2);
		$this->assertEquals(2, count($this->manager->findIn('/')));

		$id = $mount1->getStorageId();
		$this->assertEquals([$mount1], $this->manager->findByStorageId($id));

		$mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
		$this->manager->addMount($mount3);
		$this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
	}

	public function testLong() {
		$storage = new LongId([]);
		$mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
		$this->manager->addMount($mount);

		$id = $mount->getStorageId();
		$storageId = $storage->getId();
		$this->assertEquals([$mount], $this->manager->findByStorageId($id));
		$this->assertEquals([$mount], $this->manager->findByStorageId($storageId));
		$this->assertEquals([$mount], $this->manager->findByStorageId(md5($storageId)));
	}
}