mountpoint.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Vincent Petry <pvince81@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. class MountPoint extends \Test\TestCase {
  10. public function testGetStorage() {
  11. $storage = $this->getMock('\OCP\Files\Storage');
  12. $storage->expects($this->once())
  13. ->method('getId')
  14. ->will($this->returnValue(123));
  15. $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
  16. $loader->expects($this->once())
  17. ->method('getInstance')
  18. ->will($this->returnValue($storage));
  19. $mountPoint = new \OC\Files\Mount\MountPoint(
  20. // just use this because a real class is needed
  21. '\Test\Files\Mount\MountPoint',
  22. '/mountpoint',
  23. null,
  24. $loader
  25. );
  26. $this->assertEquals($storage, $mountPoint->getStorage());
  27. $this->assertEquals(123, $mountPoint->getStorageId());
  28. }
  29. public function testInvalidStorage() {
  30. $loader = $this->getMock('\OCP\Files\Storage\IStorageFactory');
  31. $loader->expects($this->once())
  32. ->method('getInstance')
  33. ->will($this->throwException(new \Exception('Test storage init exception')));
  34. $called = false;
  35. $wrapper = function($mountPoint, $storage) use ($called) {
  36. $called = true;
  37. };
  38. $mountPoint = new \OC\Files\Mount\MountPoint(
  39. // just use this because a real class is needed
  40. '\Test\Files\Mount\MountPoint',
  41. '/mountpoint',
  42. null,
  43. $loader
  44. );
  45. $this->assertNull($mountPoint->getStorage());
  46. // call it again to make sure the init code only ran once
  47. $this->assertNull($mountPoint->getStorage());
  48. $this->assertNull($mountPoint->getStorageId());
  49. // wrapping doesn't fail
  50. $mountPoint->wrapStorage($wrapper);
  51. $this->assertNull($mountPoint->getStorage());
  52. // storage wrapper never called
  53. $this->assertFalse($called);
  54. }
  55. }