function testForItemIdReturnsCollectionOfFiles()
 {
     $http_response = dummyObject(['status' => '200', 'body' => '{"data":[{"id":2,"item_id":1,"size":121,"field":"el1","filename":"food.jpg","url":"http://example.com/b33f"}]}']);
     $request = $this->getMockBuilder('\\Test\\Request')->getMock();
     $request->method('get')->with($this->equalTo('items/1/files'))->willReturn(new \GatherContent\Response($http_response));
     $subject = new FileCollection($request);
     $files = $subject->forItemId(1);
     $this->assertCount(1, $files);
     $file = $files[0];
     $this->assertInstanceOf('\\GatherContent\\Model\\File', $file);
     $this->assertSame(2, $file->id);
     $this->assertSame(1, $file->item_id);
     $this->assertSame(121, $file->size);
     $this->assertEquals('el1', $file->field);
     $this->assertEquals('food.jpg', $file->filename);
     $this->assertEquals('http://example.com/b33f', $file->url);
 }
 public function getFile($filename = NULL)
 {
     if (is_array($this->editors)) {
         Assets::package($this->editors);
     }
     if (is_null($filename)) {
         return $this->collection->newFile();
     }
     if ($file = $this->collection->findFile($filename)) {
         return $file;
     }
     $this->throwFailException($this->smartRedirect()->withErrors(trans("{$this->moduleNamespace}{$this->sectionPrefix}.messages.not_found")));
 }
 /**
  * @inheritdoc
  */
 public function offsetUnset($offset)
 {
     $this->deleted[] = $this->data[$offset];
     parent::offsetUnset($offset);
 }
 /**
  * Finds a collection inside this collection
  *
  * @param   string name
  * @return  io.collections.IOCollection
  * @throws  io.OperationNotSupportedException
  * @throws  io.IOException
  */
 public function findCollection($name)
 {
     $qualified = $this->qualifiedName($name);
     if (!is_dir($qualified)) {
         return NULL;
     }
     $found = new FileCollection($qualified);
     $found->setOrigin($this);
     return $found;
 }
 public function testErrorString()
 {
     $_FILES = ['userfile' => ['name' => 'someFile.txt', 'type' => 'text/plain', 'size' => '124', 'tmp_name' => '/tmp/myTempFile.txt', 'error' => UPLOAD_ERR_INI_SIZE]];
     $expected = 'The file "someFile.txt" exceeds your upload_max_filesize ini directive.';
     $collection = new FileCollection();
     $file = $collection->getFile('userfile');
     $this->assertEquals($expected, $file->getErrorString());
 }