summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-05-08 12:40:20 +0200
committerJulius Härtl <jus@bitgrid.net>2018-06-05 16:47:38 +0200
commit9b919245f67f5511d6be7910f61d639b290eab26 (patch)
tree51dc22ed31709c7e78af630de298b548dba3f863 /apps
parent4a5826cddb19c8a3cd8c112eea29d87630591293 (diff)
downloadnextcloud-server-9b919245f67f5511d6be7910f61d639b290eab26.tar.gz
nextcloud-server-9b919245f67f5511d6be7910f61d639b290eab26.zip
Adjust ImageManager tests for png generation
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/lib/ImageManager.php9
-rw-r--r--apps/theming/tests/ImageManagerTest.php55
2 files changed, 51 insertions, 13 deletions
diff --git a/apps/theming/lib/ImageManager.php b/apps/theming/lib/ImageManager.php
index 693d2bbe1d4..850cd3e69bd 100644
--- a/apps/theming/lib/ImageManager.php
+++ b/apps/theming/lib/ImageManager.php
@@ -33,9 +33,6 @@ use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IURLGenerator;
-/**
- * @property IURLGenerator urlGenerator
- */
class ImageManager {
/** @var IConfig */
@@ -55,7 +52,7 @@ class ImageManager {
* @param IConfig $config
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
- * @param ThemingDefaults $themingDefaults
+ * @param ICacheFactory $cacheFactory
*/
public function __construct(IConfig $config,
IAppData $appData,
@@ -97,10 +94,10 @@ class ImageManager {
*/
public function getImage(string $key, bool $useSvg = false): ISimpleFile {
$logo = $this->config->getAppValue('theming', $key . 'Mime', false);
- if ($logo === false) {
+ $folder = $this->appData->getFolder('images');
+ if ($logo === false || !$folder->fileExists($key)) {
throw new NotFoundException();
}
- $folder = $this->appData->getFolder('images');
if (!$useSvg && $this->shouldReplaceIcons()) {
if (!$folder->fileExists($key . '.png')) {
try {
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php
index 3993efc1c52..501ec0e1432 100644
--- a/apps/theming/tests/ImageManagerTest.php
+++ b/apps/theming/tests/ImageManagerTest.php
@@ -26,6 +26,7 @@ namespace OCA\Theming\Tests;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IURLGenerator;
use Test\TestCase;
@@ -43,19 +44,36 @@ class ImageManagerTest extends TestCase {
protected $imageManager;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;
+ /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $cacheFactory;
protected function setUp() {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->imageManager = new ImageManager(
$this->config,
$this->appData,
- $this->urlGenerator
+ $this->urlGenerator,
+ $this->cacheFactory
);
}
+ private function checkImagick() {
+ if(!extension_loaded('imagick')) {
+ $this->markTestSkipped('Imagemagick is required for dynamic icon generation.');
+ }
+ $checkImagick = new \Imagick();
+ if (count($checkImagick->queryFormats('SVG')) < 1) {
+ $this->markTestSkipped('No SVG provider present.');
+ }
+ if (count($checkImagick->queryFormats('PNG')) < 1) {
+ $this->markTestSkipped('No PNG provider present.');
+ }
+ }
+
public function mockGetImage($key, $file) {
/** @var \PHPUnit_Framework_MockObject_MockObject $folder */
$folder = $this->createMock(ISimpleFolder::class);
@@ -65,10 +83,28 @@ class ImageManagerTest extends TestCase {
->with('logo')
->willThrowException(new NotFoundException());
} else {
- $folder->expects($this->once())
+ $file->expects($this->once())
+ ->method('getContent')
+ ->willReturn(file_get_contents(__DIR__ . '/../../../tests/data/testimage.png'));
+ $folder->expects($this->at(0))
+ ->method('fileExists')
+ ->with('logo')
+ ->willReturn(true);
+ $folder->expects($this->at(1))
+ ->method('fileExists')
+ ->with('logo.png')
+ ->willReturn(false);
+ $folder->expects($this->at(2))
->method('getFile')
->with('logo')
->willReturn($file);
+ $newFile = $this->createMock(ISimpleFile::class);
+ $folder->expects($this->at(3))
+ ->method('newFile')
+ ->with('logo.png')
+ ->willReturn($newFile);
+ $newFile->expects($this->once())
+ ->method('putContent');
$this->appData->expects($this->once())
->method('getFolder')
->with('images')
@@ -77,12 +113,13 @@ class ImageManagerTest extends TestCase {
}
public function testGetImageUrl() {
+ $this->checkImagick();
$file = $this->createMock(ISimpleFile::class);
$this->config->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
- ['theming', 'logoMime', false]
+ ['theming', 'logoMime', '']
)
->willReturn(0);
$this->mockGetImage('logo', $file);
@@ -108,27 +145,31 @@ class ImageManagerTest extends TestCase {
}
public function testGetImageUrlAbsolute() {
+ $this->checkImagick();
$file = $this->createMock(ISimpleFile::class);
$this->config->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
- ['theming', 'logoMime', false]
+ ['theming', 'logoMime', '']
)
->willReturn(0);
$this->mockGetImage('logo', $file);
$this->urlGenerator->expects($this->at(0))
- ->method('linkToRoute')
- ->willReturn('url-to-image');
+ ->method('getBaseUrl')
+ ->willReturn('baseurl');
$this->urlGenerator->expects($this->at(1))
->method('getAbsoluteUrl')
- ->with('url-to-image?v=0')
+ ->willReturn('url-to-image-absolute?v=0');
+ $this->urlGenerator->expects($this->at(2))
+ ->method('getAbsoluteUrl')
->willReturn('url-to-image-absolute?v=0');
$this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo'));
}
public function testGetImage() {
+ $this->checkImagick();
$this->config->expects($this->once())
->method('getAppValue')->with('theming', 'logoMime', false)
->willReturn('png');