Permalink
Browse files

Fix width and height detection not working properly

  • Loading branch information...
carakas committed Aug 6, 2018
1 parent 7df975e commit b4412e5117b6feb12ffeffbbbb73f2a239b78afe
Showing with 23 additions and 5 deletions.
  1. +3 −3 src/ForkCMS/Utility/Thumbnails.php
  2. +20 −2 tests/Utility/ThumbnailsTest.php
@@ -141,9 +141,9 @@ public function getFolders(string $inPath, bool $includeSourceFolder = false): a
$folders[] = [
'dirname' => $dirname,
'path' => $directory->getRealPath(),
'width' => is_int($chunks[0]) ? (int) $chunks[0] : null,
'height' => is_int($chunks[1]) ? (int) $chunks[1] : null,
'url' => (mb_substr($inPath, 0, mb_strlen($this->sitePath)) === $this->sitePath)
'width' => is_numeric($chunks[0]) ? (int) $chunks[0] : null,
'height' => is_numeric($chunks[1]) ? (int) $chunks[1] : null,
'url' => (0 === mb_strpos($inPath, $this->sitePath))
? mb_substr($inPath, mb_strlen($this->sitePath)) : ''
];
}
@@ -11,6 +11,8 @@ class ThumbnailsTest extends TestCase
private const PORTRAIT = '500x1000';
private const SOURCE = 'source';
private const SQUARE = '500x500';
private const ONLY_WIDTH = '500x';
private const ONLY_HEIGHT = 'x500';
/** @var array */
private $folders = [];
@@ -51,7 +53,7 @@ private function deleteFiles()
protected function setUp()
{
// Init variables
$sitePathWWW = dirname(__FILE__) . '/..';
$sitePathWWW = __DIR__ . '/../../var/cache/test';
$this->rootPath = realpath($sitePathWWW);
$this->filename = '1.jpg';
$this->thumbnails = new Thumbnails($sitePathWWW);
@@ -60,13 +62,15 @@ protected function setUp()
$this->rootPath . '/' . self::SQUARE,
$this->rootPath . '/' . self::PORTRAIT,
$this->rootPath . '/' . self::LANDSCAPE,
$this->rootPath . '/' . self::ONLY_HEIGHT,
$this->rootPath . '/' . self::ONLY_WIDTH,
];
$this->createFolders();
// Copy our file to /source folder
copy(
$this->rootPath . '/../src/Backend/Core/Installer/Data/images/' . $this->filename,
$this->rootPath . '/../../../src/Backend/Core/Installer/Data/images/' . $this->filename,
$this->rootPath . '/' . self::SOURCE . '/' . $this->filename
);
}
@@ -85,13 +89,27 @@ public function testClassMethods()
// Test thumbnail folders
$this->assertEquals(
[
[
'dirname' => self::ONLY_WIDTH,
'path' => $this->rootPath . '/' . self::ONLY_WIDTH,
'url' => '',
'width' => (int) explode('x', self::ONLY_WIDTH)[0],
'height' => null,
],
[
'dirname' => self::LANDSCAPE,
'path' => $this->rootPath . '/' . self::LANDSCAPE,
'url' => '',
'width' => (int) explode('x', self::LANDSCAPE)[0],
'height' => (int) explode('x', self::LANDSCAPE)[1],
],
[
'dirname' => self::ONLY_HEIGHT,
'path' => $this->rootPath . '/' . self::ONLY_HEIGHT,
'url' => '',
'width' => null,
'height' => (int) explode('x', self::ONLY_HEIGHT)[1],
],
[
'dirname' => self::PORTRAIT,
'path' => $this->rootPath . '/' . self::PORTRAIT,

0 comments on commit b4412e5

Please sign in to comment.