1
0

MountPointTest.php 2.0 KB

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