Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Form/Eloquent/Uploads/Thumbnails/Thumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,10 @@ private function resolveThumbnailPath(?int $width = null, ?int $height = null):
// Strip double /
return Str::replace('//', '/', $thumbnailPath);
}

public function __toString()
{
// Return URL when Thumbnail is used as a string
return $this->make();
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Form/Eloquent/Uploads/SharpUploadModelTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Code16\Sharp\Form\Eloquent\Uploads\SharpUploadModel;
use Code16\Sharp\Form\Eloquent\Uploads\Thumbnails\Thumbnail;
use Code16\Sharp\Tests\Fixtures\Person;
use Illuminate\Support\Facades\Storage;

Expand Down Expand Up @@ -43,6 +44,16 @@
->toBeTrue();
});

it('allows to display thumbnails with no width or height params', function () {
$file = createImage();
$upload = createSharpUploadModel($file);

expect($upload->thumbnail())
->toBeInstanceOf(Thumbnail::class)
->and((string) $upload->thumbnail())
->toStartWith('/storage/thumbnails/data/-_q-90/'.basename($file));
});

it('returns null on error with a thumbnail creation', function () {
$file = createImage();
$upload = createSharpUploadModel($file);
Expand Down
Loading