public function testWrappedStorage() { $storage = $this->getMockBuilder('\\OC\\Files\\Storage\\Wrapper\\Wrapper')->disableOriginalConstructor()->getMock(); $loader = $this->getMock('\\OCP\\Files\\Storage\\IStorageFactory'); $loader->expects($this->never())->method('getInstance'); $loader->expects($this->never())->method('wrap'); $mountPoint = new \OC\Files\Mount\MountPoint($storage, '/mountpoint', null, $loader); $this->assertEquals($storage, $mountPoint->getStorage()); }
public function testWrapper() { $test = $this; $wrapper = function ($mountPoint, $storage) use(&$test) { $test->assertEquals('/foo/', $mountPoint); $test->assertInstanceOf('\\OC\\Files\\Storage\\Storage', $storage); return new Wrapper(array('storage' => $storage)); }; $loader = new StorageFactory(); $loader->addStorageWrapper('test_wrapper', $wrapper); $storage = $this->getMockBuilder('\\OC\\Files\\Storage\\Temporary')->disableOriginalConstructor()->getMock(); $mount = new \OC\Files\Mount\MountPoint($storage, '/foo', array(), $loader); $this->assertInstanceOf('\\OC\\Files\\Storage\\Wrapper\\Wrapper', $mount->getStorage()); }
public function testInvalidStorage() { $loader = $this->getMock('\\OCP\\Files\\Storage\\IStorageFactory'); $loader->expects($this->once())->method('getInstance')->will($this->throwException(new \Exception('Test storage init exception'))); $called = false; $wrapper = function ($mountPoint, $storage) use($called) { $called = true; }; $mountPoint = new \OC\Files\Mount\MountPoint('\\Test\\Files\\Mount\\MountPoint', '/mountpoint', null, $loader); $this->assertNull($mountPoint->getStorage()); // call it again to make sure the init code only ran once $this->assertNull($mountPoint->getStorage()); $this->assertNull($mountPoint->getStorageId()); // wrapping doesn't fail $mountPoint->wrapStorage($wrapper); $this->assertNull($mountPoint->getStorage()); // storage wrapper never called $this->assertFalse($called); }