generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from vormkracht10/test-adding-filename-from-url
Add filename to url, helper functions and test
- Loading branch information
Showing
4 changed files
with
58 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Vormkracht10\UploadcareTransformations\UploadcareTransformation; | ||
|
||
if (! function_exists('uploadcare')) { | ||
function uploadcare(string $uuid, string $cdnUrl = 'https://ucarecdn.com/'): UploadcareTransformation | ||
{ | ||
return new UploadcareTransformation($uuid, $cdnUrl); | ||
} | ||
} | ||
|
||
if (! function_exists('uc')) { | ||
function uc(string $uuid, string $cdnUrl = 'https://ucarecdn.com/'): UploadcareTransformation | ||
{ | ||
return uploadcare($uuid, $cdnUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
<?php | ||
|
||
use Vormkracht10\UploadcareTransformations\UploadcareTransformation; | ||
|
||
it('can generate a url without cdn', function () { | ||
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25'; | ||
$transformation = (new UploadcareTransformation($uuid)); | ||
$transformation = uploadcare($uuid); | ||
|
||
$url = $transformation->crop(320, '50p', 'center')->setFill('#ffffff')->getUrl(); | ||
$url = (string) $transformation->crop(320, '50p', 'center')->setFill('#ffffff'); | ||
|
||
expect($url)->toBe('https://ucarecdn.com/12a3456b-c789-1234-1de2-3cfa83096e25/crop/320x50p/center/set_fill/#ffffff'); | ||
expect($url)->toBe('https://ucarecdn.com/12a3456b-c789-1234-1de2-3cfa83096e25/crop/320x50p/center/set_fill/#ffffff/'); | ||
}); | ||
|
||
it('can generate a url with cdn', function () { | ||
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25'; | ||
$cdnUrl = 'https://example.com/cdn/'; | ||
|
||
$transformation = (new UploadcareTransformation($uuid, $cdnUrl)); | ||
$transformation = uploadcare($uuid, $cdnUrl); | ||
|
||
$url = $transformation->crop(320, '50p', 'center')->setFill('#ffffff')->getUrl(); | ||
$url = (string) $transformation->crop(320, '50p', 'center')->setFill('#ffffff'); | ||
|
||
expect($url)->toBe('https://example.com/cdn/12a3456b-c789-1234-1de2-3cfa83096e25/crop/320x50p/center/set_fill/#ffffff'); | ||
expect($url)->toBe('https://example.com/cdn/12a3456b-c789-1234-1de2-3cfa83096e25/crop/320x50p/center/set_fill/#ffffff/'); | ||
}); | ||
|
||
it('can generate a url using Conver to SRGB and ICC profile size threshold', function () { | ||
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25'; | ||
|
||
$transformation = (new UploadcareTransformation($uuid)); | ||
$transformation = uploadcare($uuid); | ||
|
||
$url = $transformation->convertToSRGB('fast')->iccProfileSizeThreshold(10)->getUrl(); | ||
$url = (string) $transformation->convertToSRGB('fast')->iccProfileSizeThreshold(10); | ||
|
||
expect($url)->toBe('https://ucarecdn.com/12a3456b-c789-1234-1de2-3cfa83096e25/max_icc_size/10/srgb/fast'); | ||
expect($url)->toBe('https://ucarecdn.com/12a3456b-c789-1234-1de2-3cfa83096e25/max_icc_size/10/srgb/fast/'); | ||
}); | ||
|
||
it('can generate a url including filename with transformations', function () { | ||
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25'; | ||
$transformation = uploadcare($uuid); | ||
|
||
$url = (string) $transformation->crop(320, '50p', 'center')->filename('test.jpg'); | ||
|
||
expect($url)->toBe('https://ucarecdn.com/12a3456b-c789-1234-1de2-3cfa83096e25/crop/320x50p/center/test.jpg'); | ||
}); |