ManagerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Files\Mount;
  9. use OC\Files\SetupManagerFactory;
  10. use OC\Files\Storage\Temporary;
  11. class LongId extends Temporary {
  12. public function getId() {
  13. return 'long:' . str_repeat('foo', 50) . parent::getId();
  14. }
  15. }
  16. class ManagerTest extends \Test\TestCase {
  17. /**
  18. * @var \OC\Files\Mount\Manager
  19. */
  20. private $manager;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
  24. }
  25. public function testFind() {
  26. $rootMount = new \OC\Files\Mount\MountPoint(new Temporary([]), '/');
  27. $this->manager->addMount($rootMount);
  28. $this->assertEquals($rootMount, $this->manager->find('/'));
  29. $this->assertEquals($rootMount, $this->manager->find('/foo/bar'));
  30. $storage = new Temporary([]);
  31. $mount1 = new \OC\Files\Mount\MountPoint($storage, '/foo');
  32. $this->manager->addMount($mount1);
  33. $this->assertEquals($rootMount, $this->manager->find('/'));
  34. $this->assertEquals($mount1, $this->manager->find('/foo/bar'));
  35. $this->assertEquals(1, count($this->manager->findIn('/')));
  36. $mount2 = new \OC\Files\Mount\MountPoint(new Temporary([]), '/bar');
  37. $this->manager->addMount($mount2);
  38. $this->assertEquals(2, count($this->manager->findIn('/')));
  39. $id = $mount1->getStorageId();
  40. $this->assertEquals([$mount1], $this->manager->findByStorageId($id));
  41. $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
  42. $this->manager->addMount($mount3);
  43. $this->assertEquals([$mount1, $mount3], $this->manager->findByStorageId($id));
  44. }
  45. public function testLong() {
  46. $storage = new LongId([]);
  47. $mount = new \OC\Files\Mount\MountPoint($storage, '/foo');
  48. $this->manager->addMount($mount);
  49. $id = $mount->getStorageId();
  50. $storageId = $storage->getId();
  51. $this->assertEquals([$mount], $this->manager->findByStorageId($id));
  52. $this->assertEquals([$mount], $this->manager->findByStorageId($storageId));
  53. $this->assertEquals([$mount], $this->manager->findByStorageId(md5($storageId)));
  54. }
  55. }