Skip to content

Commit

Permalink
Merge pull request #194 from jasonvarga/master
Browse files Browse the repository at this point in the history
Save pjpg as jpg when including file extensions
  • Loading branch information
reinink authored May 9, 2017
2 parents 0075841 + 0d8a660 commit 8077f52
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public function getCachePath($path, array $params = [])
}

if ($this->cacheWithFileExtensions) {
$cachedPath .= '.'.(isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']);
$ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']);
$ext = ($ext === 'pjpg') ? 'jpg' : $ext;
$cachedPath .= '.'.$ext;
}

return $cachedPath;
Expand Down
24 changes: 24 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,26 @@ public function testGetCachePathWithExtensionAndFmParam()
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', ['fm' => 'gif']));
}

public function testGetCachePathWithExtensionAndPjpgFmParam()
{
$this->server->setCacheWithFileExtensions(true);
$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', ['fm' => 'pjpg']));
}

public function testGetCachePathWithExtensionAndFmFromDefaults()
{
$this->server->setCacheWithFileExtensions(true);
$this->server->setDefaults(['fm' => 'gif']);
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', []));
}

public function testGetCachePathWithExtensionAndPjpgFmFromDefaults()
{
$this->server->setCacheWithFileExtensions(true);
$this->server->setDefaults(['fm' => 'pjpg']);
$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', []));
}

public function testGetCachePathWithExtensionAndFmFromPreset()
{
$this->server->setCacheWithFileExtensions(true);
Expand All @@ -223,6 +236,17 @@ public function testGetCachePathWithExtensionAndFmFromPreset()
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', ['p' => 'gif']));
}

public function testGetCachePathWithExtensionAndPjpgFmFromPreset()
{
$this->server->setCacheWithFileExtensions(true);

$this->server->setPresets(['pjpg' => [
'fm' => 'pjpg',
]]);

$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', ['p' => 'pjpg']));
}

public function testCacheFileExists()
{
$this->server->setCache(Mockery::mock('League\Flysystem\FilesystemInterface', function ($mock) {
Expand Down

0 comments on commit 8077f52

Please sign in to comment.