Skip to content

Commit

Permalink
Merge branch 'release/0.1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrossi committed Apr 21, 2017
2 parents 4afe61b + e83062c commit 82fc3a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Field/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ protected function fillFields(Post $attachment)

/**
* @param string $size
* @param bool $useOriginalFallback
*
* @return Image
*/
public function size($size)
public function size($size, $useOriginalFallback = false)
{
if (isset($this->sizes[$size])) {
return $this->fillThumbnailFields($this->sizes[$size]);
}

return $this->fillThumbnailFields($this->sizes['thumbnail']);
return $useOriginalFallback ? $this : $this->fillThumbnailFields($this->sizes['thumbnail']);
}

/**
Expand All @@ -117,6 +118,9 @@ protected function fillThumbnailFields(array $data)
$size->height = $data['height'];
$size->mime_type = $data['mime-type'];

$urlPath = dirname($this->url);
$size->url = sprintf('%s/%s', $urlPath, $size->filename);

return $size;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/ContentFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ public function testImageFieldValue()
$this->assertEquals('1920', $image->width);
$this->assertEquals('1080', $image->height);
$this->assertEquals('maxresdefault-1.jpg', $image->filename);

// Test existing image size
$this->assertEquals('1024', $image->size('large')->width);
$this->assertNotEmpty($image->size('large')->url);

// Test non existing image size with thumbnail as fallback
$this->assertEquals('150', $image->size('fake_size')->width);
$this->assertNotEmpty($image->size('fake_size')->url);

// Test non existing image size with original as fallback
$this->assertEquals($image->width, $image->size('fake_size', true)->width);
$this->assertEquals($image->height, $image->size('fake_size', true)->height);
$this->assertNotEmpty($image->size('fake_size', true)->url);

$this->assertEquals('image/jpeg', $image->mime_type);
$this->assertEquals('This is a caption', $image->description);
}
Expand Down

0 comments on commit 82fc3a4

Please sign in to comment.