From 12c8cdfb8f29187405268eeaf2e3f29770f70d25 Mon Sep 17 00:00:00 2001 From: Muhammed Sari Date: Mon, 21 Mar 2022 12:02:04 +0100 Subject: [PATCH 1/2] Fix responsive url generation --- src/Support/UrlGenerator/DefaultUrlGenerator.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Support/UrlGenerator/DefaultUrlGenerator.php b/src/Support/UrlGenerator/DefaultUrlGenerator.php index 27066c820..d185bfc07 100644 --- a/src/Support/UrlGenerator/DefaultUrlGenerator.php +++ b/src/Support/UrlGenerator/DefaultUrlGenerator.php @@ -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 From f2cbc2aa250a8d1dc0e2328727f8309a06ecae37 Mon Sep 17 00:00:00 2001 From: Muhammed Sari Date: Tue, 22 Mar 2022 09:18:57 +0100 Subject: [PATCH 2/2] Update tests --- .../MediaConversions/MediaCollectionTest.php | 12 +++++----- tests/Feature/Media/ToHtmlTest.php | 4 ++-- .../ResponsiveImages/ResponsiveImageTest.php | 22 +++++++++---------- .../UrlGenerator/BaseUrlGeneratorTest.php | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php index 9d4fcc8b9..ba4225096 100644 --- a/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php +++ b/tests/Feature/FileAdder/MediaConversions/MediaCollectionTest.php @@ -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([]); diff --git a/tests/Feature/Media/ToHtmlTest.php b/tests/Feature/Media/ToHtmlTest.php index d5dd668ff..177928596 100644 --- a/tests/Feature/Media/ToHtmlTest.php +++ b/tests/Feature/Media/ToHtmlTest.php @@ -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(''); + expect($imgTag)->toEqual(''); }); test('the loading attribute can be specified on the conversion', function () { diff --git a/tests/ResponsiveImages/ResponsiveImageTest.php b/tests/ResponsiveImages/ResponsiveImageTest.php index 11fac66b7..77bdd15cc 100644 --- a/tests/ResponsiveImages/ResponsiveImageTest.php +++ b/tests/ResponsiveImages/ResponsiveImageTest.php @@ -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([]); diff --git a/tests/Support/UrlGenerator/BaseUrlGeneratorTest.php b/tests/Support/UrlGenerator/BaseUrlGeneratorTest.php index 10ccf4a9b..48dccc108 100644 --- a/tests/Support/UrlGenerator/BaseUrlGeneratorTest.php +++ b/tests/Support/UrlGenerator/BaseUrlGeneratorTest.php @@ -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/'); });