PageRenderTime 109ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/lib/files/mount/manager.php

https://github.com/sezuan/core
PHP | 67 lines | 45 code | 13 blank | 9 comment | 0 complexity | 8d7a4ab1e34018378ef4f52986d5542a MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  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. }