public function testStore()
 {
     list($fsManager, $distributor) = $this->getMocks();
     $resource = file_get_contents(__DIR__ . '/sample.png');
     $distributor->shouldReceive('allot')->once()->with($resource)->andReturn('local');
     $mockFilesystem = m::mock('Illuminate\\Contracts\\Filesystem\\Filesystem');
     $mockFilesystem->shouldReceive('put')->once()->with('attached/filenamestring', $resource)->andReturnNull();
     $fsManager->shouldReceive('disk')->once()->with('local')->andReturn($mockFilesystem);
     $instance = new FileHandler($fsManager, $distributor);
     $file = $instance->store($resource, 'attached/filenamestring');
     $this->assertInstanceOf('Xpressengine\\Storage\\File', $file);
     $this->assertEquals('local', $file->disk);
     $this->assertEquals('attached', $file->path);
     $this->assertEquals('image/png', $file->mime);
 }
示例#2
0
 /**
  * create file
  *
  * @param string      $content  file content
  * @param string      $path     directory for saved
  * @param string      $name     saved name
  * @param string|null $disk     disk for saved
  * @param string|null $parentId original file id
  * @return File
  */
 public function create($content, $path, $name, $disk = null, $parentId = null)
 {
     $id = $this->keygen->generate();
     $file = $this->files->store($content, $this->makePathname($id, $path, $name), $disk);
     $file->id = $id;
     $file->clientname = $name;
     if ($parentId !== null) {
         $file->parentId = $parentId;
     }
     return $this->repo->insert($file);
 }