Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix responsive url generation #2852

Merged
merged 2 commits into from
Mar 22, 2022
Merged
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
4 changes: 1 addition & 3 deletions src/Support/UrlGenerator/DefaultUrlGenerator.php
Original file line number Diff line number Diff line change
@@ -31,11 +31,9 @@ public function getPath(): string

public function getResponsiveImagesDirectoryUrl(): string
{
$base = Str::finish($this->getBaseMediaDirectoryUrl(), '/');

$path = $this->pathGenerator->getPathForResponsiveImages($this->media);

return Str::finish(url($base.$path), '/');
return Str::finish($this->getDisk()->url($path), '/');
}

protected function getRootOfDisk(): string
12 changes: 6 additions & 6 deletions tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php
Original file line number Diff line number Diff line change
@@ -173,9 +173,9 @@ public function registerMediaCollections(): void
$media = $model->getMedia('images')->first();

$this->assertEquals([
'http://localhost/media/1/responsive-images/test___media_library_original_340_280.jpg',
'http://localhost/media/1/responsive-images/test___media_library_original_284_234.jpg',
'http://localhost/media/1/responsive-images/test___media_library_original_237_195.jpg',
'/media/1/responsive-images/test___media_library_original_340_280.jpg',
'/media/1/responsive-images/test___media_library_original_284_234.jpg',
'/media/1/responsive-images/test___media_library_original_237_195.jpg',
], $media->getResponsiveImageUrls());

expect($media->getResponsiveImageUrls('non-existing-conversion'))->toEqual([]);
@@ -198,9 +198,9 @@ public function registerMediaCollections(): void
$media = $model->getMedia('images')->first();

$this->assertEquals([
'http://localhost/media/1/responsive-images/test___media_library_original_340_280.jpg',
'http://localhost/media/1/responsive-images/test___media_library_original_284_234.jpg',
'http://localhost/media/1/responsive-images/test___media_library_original_237_195.jpg',
'/media/1/responsive-images/test___media_library_original_340_280.jpg',
'/media/1/responsive-images/test___media_library_original_284_234.jpg',
'/media/1/responsive-images/test___media_library_original_237_195.jpg',
], $media->getResponsiveImageUrls());

expect($media->getResponsiveImageUrls('non-existing-conversion'))->toEqual([]);
4 changes: 2 additions & 2 deletions tests/Feature/Media/ToHtmlTest.php
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@
expect((string)$image)->toContain('data:image/svg+xml;base64,');
});

it('will not rendering extra javascript or including base64 svg when tiny placeholders are turned off', function () {
it('will not render extra javascript or include base64 svg when tiny placeholders are turned off', function () {
config()->set('media-library.responsive_images.use_tiny_placeholders', false);

$media = $this->testModelWithConversion
@@ -87,7 +87,7 @@

$imgTag = $media->refresh()->img();

expect($imgTag)->toEqual('<img srcset="http://localhost/media/2/responsive-images/test___media_library_original_340_280.jpg 340w, http://localhost/media/2/responsive-images/test___media_library_original_284_234.jpg 284w, http://localhost/media/2/responsive-images/test___media_library_original_237_195.jpg 237w" src="/media/2/test.jpg" width="340" height="280">');
expect($imgTag)->toEqual('<img srcset="/media/2/responsive-images/test___media_library_original_340_280.jpg 340w, /media/2/responsive-images/test___media_library_original_284_234.jpg 284w, /media/2/responsive-images/test___media_library_original_237_195.jpg 237w" src="/media/2/test.jpg" width="340" height="280">');
});

test('the loading attribute can be specified on the conversion', function () {
22 changes: 11 additions & 11 deletions tests/ResponsiveImages/ResponsiveImageTest.php
Original file line number Diff line number Diff line change
@@ -15,13 +15,13 @@
$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertEquals([
"http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_340_280.jpg",
"http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg",
"http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg",
"/media/1/responsive-images/{$this->fileName}___media_library_original_340_280.jpg",
"/media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg",
"/media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg",
], $media->getResponsiveImageUrls());

$this->assertEquals([
"http://localhost/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg",
"/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg",
], $media->getResponsiveImageUrls("thumb"));

expect($media->getResponsiveImageUrls("non-existing-conversion"))->toEqual([]);
@@ -36,13 +36,13 @@
$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertStringContainsString(
"http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_340_280.jpg 340w, http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg 284w, http://localhost/media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg 237w",
"/media/1/responsive-images/{$this->fileName}___media_library_original_340_280.jpg 340w, /media/1/responsive-images/{$this->fileName}___media_library_original_284_234.jpg 284w, /media/1/responsive-images/{$this->fileName}___media_library_original_237_195.jpg 237w",
$media->getSrcset()
);
expect($media->getSrcset())->toContain("data:image/svg+xml;base64");

$this->assertStringContainsString(
"http://localhost/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg 50w",
"/media/1/responsive-images/{$this->fileName}___thumb_50_41.jpg 50w",
$media->getSrcset("thumb")
);
expect($media->getSrcset("thumb"))->toContain("data:image/svg+xml;base64,");
@@ -87,7 +87,7 @@
$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertEquals([
"http://localhost/media2/1/responsive-images/{$this->fileName}___thumb_50_41.jpg",
"/media2/1/responsive-images/{$this->fileName}___thumb_50_41.jpg",
], $media->getResponsiveImageUrls("thumb"));
});

@@ -101,13 +101,13 @@
$media = $this->testModelWithResponsiveImages->getFirstMedia();

$this->assertSame([
"http://localhost/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_340_280.jpg",
"http://localhost/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_284_234.jpg",
"http://localhost/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_237_195.jpg",
"/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_340_280.jpg",
"/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_284_234.jpg",
"/media/1/responsive-images/{$this->fileNameWithUnderscore}___media_library_original_237_195.jpg",
], $media->getResponsiveImageUrls());

$this->assertSame([
"http://localhost/media/1/responsive-images/{$this->fileNameWithUnderscore}___thumb_50_41.jpg",
"/media/1/responsive-images/{$this->fileNameWithUnderscore}___thumb_50_41.jpg",
], $media->getResponsiveImageUrls("thumb"));

expect($media->getResponsiveImageUrls("non-existing-conversion"))->toBe([]);
2 changes: 1 addition & 1 deletion tests/Support/UrlGenerator/BaseUrlGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -56,5 +56,5 @@
it('can get the responsive images directory url', function () {
$this->config->set('filesystems.disks.public.url', 'http://localhost/media/');

expect($this->urlGenerator->getResponsiveImagesDirectoryUrl())->toEqual('http://localhost/media/1/responsive-images/');
expect($this->urlGenerator->getResponsiveImagesDirectoryUrl())->toEqual('/media/1/responsive-images/');
});