manager.php 2.1 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 Manager extends \PHPUnit_Framework_TestCase {
  16. /**
  17. * @var \OC\Files\Mount\Manager
  18. */
  19. private $manager;
  20. public function setup() {
  21. $this->manager = new \OC\Files\Mount\Manager();
  22. }
  23. public function testFind() {
  24. $this->assertNull($this->manager->find('/'));
  25. $rootMount = new \OC\Files\Mount\Mount(new Temporary(array()), '/');
  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(array());
  30. $mount1 = new \OC\Files\Mount\Mount($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\Mount(new Temporary(array()), '/bar');
  36. $this->manager->addMount($mount2);
  37. $this->assertEquals(2, count($this->manager->findIn('/')));
  38. $id = $mount1->getStorageId();
  39. $this->assertEquals(array($mount1), $this->manager->findByStorageId($id));
  40. $mount3 = new \OC\Files\Mount\Mount($storage, '/foo/bar');
  41. $this->manager->addMount($mount3);
  42. $this->assertEquals(array($mount1, $mount3), $this->manager->findByStorageId($id));
  43. }
  44. public function testLong() {
  45. $storage = new LongId(array());
  46. $mount = new \OC\Files\Mount\Mount($storage, '/foo');
  47. $this->manager->addMount($mount);
  48. $id = $mount->getStorageId();
  49. $storageId = $storage->getId();
  50. $this->assertEquals(array($mount), $this->manager->findByStorageId($id));
  51. $this->assertEquals(array($mount), $this->manager->findByStorageId($storageId));
  52. $this->assertEquals(array($mount), $this->manager->findByStorageId(md5($storageId)));
  53. }
  54. }