Skip to content

Commit 8077f52

Browse files
authored
Merge pull request #194 from jasonvarga/master
Save pjpg as jpg when including file extensions
2 parents 0075841 + 0d8a660 commit 8077f52

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Server.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ public function getCachePath($path, array $params = [])
281281
}
282282

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

287289
return $cachedPath;

tests/ServerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,26 @@ public function testGetCachePathWithExtensionAndFmParam()
205205
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', ['fm' => 'gif']));
206206
}
207207

208+
public function testGetCachePathWithExtensionAndPjpgFmParam()
209+
{
210+
$this->server->setCacheWithFileExtensions(true);
211+
$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', ['fm' => 'pjpg']));
212+
}
213+
208214
public function testGetCachePathWithExtensionAndFmFromDefaults()
209215
{
210216
$this->server->setCacheWithFileExtensions(true);
211217
$this->server->setDefaults(['fm' => 'gif']);
212218
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', []));
213219
}
214220

221+
public function testGetCachePathWithExtensionAndPjpgFmFromDefaults()
222+
{
223+
$this->server->setCacheWithFileExtensions(true);
224+
$this->server->setDefaults(['fm' => 'pjpg']);
225+
$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', []));
226+
}
227+
215228
public function testGetCachePathWithExtensionAndFmFromPreset()
216229
{
217230
$this->server->setCacheWithFileExtensions(true);
@@ -223,6 +236,17 @@ public function testGetCachePathWithExtensionAndFmFromPreset()
223236
$this->assertEquals('image.jpg/eb6091e07fb06219634a3c82afb88239.gif', $this->server->getCachePath('image.jpg', ['p' => 'gif']));
224237
}
225238

239+
public function testGetCachePathWithExtensionAndPjpgFmFromPreset()
240+
{
241+
$this->server->setCacheWithFileExtensions(true);
242+
243+
$this->server->setPresets(['pjpg' => [
244+
'fm' => 'pjpg',
245+
]]);
246+
247+
$this->assertEquals('image.jpg/ce5cb75f4a37dec0a0a49854e94123eb.jpg', $this->server->getCachePath('image.jpg', ['p' => 'pjpg']));
248+
}
249+
226250
public function testCacheFileExists()
227251
{
228252
$this->server->setCache(Mockery::mock('League\Flysystem\FilesystemInterface', function ($mock) {

0 commit comments

Comments
 (0)