1
0

ManagerTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\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() {
  21. parent::setUp();
  22. $this->manager = new \OC\Files\Mount\Manager();
  23. }
  24. public function testFind() {
  25. $this->assertNull($this->manager->find('/'));
  26. $rootMount = new \OC\Files\Mount\MountPoint(new Temporary(array()), '/');
  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(array());
  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(array()), '/bar');
  37. $this->manager->addMount($mount2);
  38. $this->assertEquals(2, count($this->manager->findIn('/')));
  39. $id = $mount1->getStorageId();
  40. $this->assertEquals(array($mount1), $this->manager->findByStorageId($id));
  41. $mount3 = new \OC\Files\Mount\MountPoint($storage, '/foo/bar');
  42. $this->manager->addMount($mount3);
  43. $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id));
  44. }
  45. public function testLong() {
  46. $storage = new LongId(array());
  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(array($mount), $this->manager->findByStorageId($id));
  52. $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId));
  53. $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId)));
  54. }
  55. }