MountPointTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. use OC\Files\Storage\StorageFactory;
  10. use OCP\Files\Storage;
  11. class DummyStorage {
  12. }
  13. class MountPointTest extends \Test\TestCase {
  14. public function testGetStorage() {
  15. $storage = $this->createMock(Storage::class);
  16. $storage->expects($this->once())
  17. ->method('getId')
  18. ->willReturn(123);
  19. $loader = $this->createMock(StorageFactory::class);
  20. $loader->expects($this->once())
  21. ->method('wrap')
  22. ->willReturn($storage);
  23. $mountPoint = new \OC\Files\Mount\MountPoint(
  24. // just use this because a real class is needed
  25. '\Test\Files\Mount\DummyStorage',
  26. '/mountpoint',
  27. null,
  28. $loader
  29. );
  30. $this->assertEquals($storage, $mountPoint->getStorage());
  31. $this->assertEquals(123, $mountPoint->getStorageId());
  32. $this->assertEquals('/mountpoint/', $mountPoint->getMountPoint());
  33. $mountPoint->setMountPoint('another');
  34. $this->assertEquals('/another/', $mountPoint->getMountPoint());
  35. }
  36. public function testInvalidStorage() {
  37. $loader = $this->createMock(StorageFactory::class);
  38. $loader->expects($this->once())
  39. ->method('wrap')
  40. ->will($this->throwException(new \Exception('Test storage init exception')));
  41. $called = false;
  42. $wrapper = function ($mountPoint, $storage) use ($called) {
  43. $called = true;
  44. };
  45. $mountPoint = new \OC\Files\Mount\MountPoint(
  46. // just use this because a real class is needed
  47. '\Test\Files\Mount\DummyStorage',
  48. '/mountpoint',
  49. null,
  50. $loader
  51. );
  52. $this->assertNull($mountPoint->getStorage());
  53. // call it again to make sure the init code only ran once
  54. $this->assertNull($mountPoint->getStorage());
  55. $this->assertNull($mountPoint->getStorageId());
  56. // wrapping doesn't fail
  57. $mountPoint->wrapStorage($wrapper);
  58. $this->assertNull($mountPoint->getStorage());
  59. // storage wrapper never called
  60. $this->assertFalse($called);
  61. }
  62. }