ManagerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Files\Mount;
  8. use OC\Files\SetupManagerFactory;
  9. use OC\Files\Storage\Temporary;
  10. class LongId extends Temporary {
  11. public function getId() {
  12. return 'long:' . str_repeat('foo', 50) . parent::getId();
  13. }
  14. }
  15. class ManagerTest extends \Test\TestCase {
  16. /**
  17. * @var \OC\Files\Mount\Manager
  18. */
  19. private $manager;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
  23. }
  24. public function testFind(): void {
  25. $rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
  26. $this->manager->addMount($rootMount);
  27. $this->assertEquals($rootMount, $this->manager->find('/'));
  28. $this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
  29. $storage = new Temporary([]);
  30. $mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
  31. $this->manager->addMount($mount1);
  32. $this->assertEquals($rootMount, $this->manager->find('/'));
  33. $this->assertEquals($mount1, $this->manager->find('/foo/bar'));
  34. $this->assertEquals(1, count($this->manager->findIn('/')));
  35. $mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
  36. $this->manager->addMount($mount2);
  37. $this->assertEquals(2, count($this->manager->findIn('/')));
  38. $id = $mount1->getStorageId();
  39. $this->assertEquals([$mount1], $this->manager->findByStorageId($id));
  40. $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
  41. $this->manager->addMount($mount3);
  42. $this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
  43. }
  44. public function testLong(): void {
  45. $storage = new LongId([]);
  46. $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
  47. $this->manager->addMount($mount);
  48. $id = $mount->getStorageId();
  49. $storageId = $storage->getId();
  50. $this->assertEquals([$mount], $this->manager->findByStorageId($id));
  51. $this->assertEquals([$mount], $this->manager->findByStorageId($storageId));
  52. $this->assertEquals([$mount], $this->manager->findByStorageId(md5($storageId)));
  53. }
  54. }