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
4 changes: 4 additions & 0 deletions src/Responsive.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static function getPresets(Asset $asset): array
$index = 0;

foreach ($configPresets as $preset => $data) {
if(!($data['w'] ?? false)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If w is null you shouldn't have to do the ?? false. Also; shouldn't we also have the width config? Maybe in the future add a validator that validates the config?

continue;
}

$size = $data['w'].'w';

if ($index < (count($configPresets) - 1)) {
Expand Down
24 changes: 24 additions & 0 deletions tests/ResponsiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protected function setUp(): void
'placeholder' => ['w' => 32, 'h' => 32, 'q' => 100, 'fit' => 'contain'],
'xs' => ['w' => 320, 'h' => 320, 'q' => 100, 'fit' => 'contain'],
'sm' => ['w' => 640, 'h' => 640, 'q' => 100, 'fit' => 'contain'],
'sm-h' => ['w' => null, 'h' => 640, 'q' => 100, 'fit' => 'contain'],
]);
}

Expand Down Expand Up @@ -105,4 +106,27 @@ public function it_handles_image_generation(): void

$asset->delete();
}

#[Test]
public function it_creates_mime_type_source_when_configured(): void
{
$asset = $this->uploadTestAsset('upload.png');
config()->set('justbetter.glide-directive.sources', 'mime_type');

$view = Responsive::handle($asset);
/* @phpstan-ignore-next-line */
$rendered = $view->render();

$this->assertStringNotContainsString('<source type="image/webp"', $rendered);

config()->set('justbetter.glide-directive.sources', 'webp');

$view = Responsive::handle($asset);
/* @phpstan-ignore-next-line */
$rendered = $view->render();

$this->assertStringNotContainsString('<source type="image/png"', $rendered);

$asset->delete();
}
}