public function testDownloadThrownExceptionWhenFileNotExists() { list($handler, $repo, $auth, $keygen) = $this->getMocks(); $mockFile = m::mock('Xpressengine\\Storage\\File'); $handler->shouldReceive('exists')->once()->with($mockFile)->andReturn(false); $instance = new Storage($handler, $repo, $auth, $keygen); try { $instance->download($mockFile); $this->assertTrue(false); } catch (\Exception $e) { $this->assertInstanceOf('Xpressengine\\Storage\\Exceptions\\FileDoesNotExistException', $e); } }
/** * file download * * @param EditorHandler $handler editor handler * @param Storage $storage storage * @param string $instanceId instance id * @param string $id * @return void */ public function fileDownload(EditorHandler $handler, Storage $storage, $instanceId, $id) { if (empty($id) || !($file = File::find($id))) { throw new InvalidArgumentException(); } if (Gate::denies('download', new Instance($handler->getPermKey($instanceId)))) { throw new AccessDeniedHttpException(); } $storage->download($file); }