use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\Response;
-use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException;
*
* @param $app string app name
* @param $image string image file name (svg required)
- * @return FileDisplayResponse
+ * @return FileDisplayResponse|NotFoundResponse
*/
public function getThemedIcon($app, $image) {
try {
$icon = $this->iconBuilder->colorSvg($app, $image);
$iconFile = $this->imageManager->setCachedImage("icon-" . $app . '-' . str_replace("/","_",$image), $icon);
}
- $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
- $response->cacheFor(86400);
- $expires = new \DateTime();
- $expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
- $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
- $response->addHeader('Pragma', 'cache');
- return $response;
+ if ($iconFile !== false) {
+ $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
+ } else {
+ return new NotFoundResponse();
+ }
}
/**
* @NoCSRFRequired
*
* @param $app string app name
- * @return FileDisplayResponse|DataDisplayResponse
+ * @return FileDisplayResponse|NotFoundResponse
*/
public function getFavicon($app = "core") {
if ($this->themingDefaults->shouldReplaceIcons()) {
$icon = $this->iconBuilder->getFavicon($app);
$iconFile = $this->imageManager->setCachedImage('favIcon-' . $app, $icon);
}
- $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
- $response->cacheFor(86400);
- $expires = new \DateTime();
- $expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
- $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
- $response->addHeader('Pragma', 'cache');
- } else {
- $response = new Response();
- $response->setStatus(Http::STATUS_NOT_FOUND);
- $response->cacheFor(0);
- $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
+ if ($iconFile !== false) {
+ $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
+ }
}
- return $response;
+ return new NotFoundResponse();
}
/**
* @NoCSRFRequired
*
* @param $app string app name
- * @return FileDisplayResponse|DataDisplayResponse
+ * @return FileDisplayResponse|NotFoundResponse
*/
public function getTouchIcon($app = "core") {
if ($this->themingDefaults->shouldReplaceIcons()) {
$icon = $this->iconBuilder->getTouchIcon($app);
$iconFile = $this->imageManager->setCachedImage('touchIcon-' . $app, $icon);
}
- $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
- $response->cacheFor(86400);
- $expires = new \DateTime();
- $expires->setTimestamp($this->timeFactory->getTime());
- $expires->add(new \DateInterval('PT24H'));
- $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
- $response->addHeader('Pragma', 'cache');
- } else {
- $response = new Response();
- $response->setStatus(Http::STATUS_NOT_FOUND);
- $response->cacheFor(0);
- $response->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
+ if ($iconFile !== false) {
+ $response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/png']);
+ $response->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp($this->timeFactory->getTime());
+ $expires->add(new \DateInterval('PT24H'));
+ $response->addHeader('Expires', $expires->format(\DateTime::RFC2822));
+ $response->addHeader('Pragma', 'cache');
+ return $response;
+ }
}
- return $response;
+ return new NotFoundResponse();
}
}
/**
* @param $app string app name
- * @return string image blob
+ * @return string|false image blob
*/
public function getFavicon($app) {
$icon = $this->renderAppIcon($app);
+ if($icon === false) {
+ return false;
+ }
$icon->resizeImage(32, 32, Imagick::FILTER_LANCZOS, 1);
$icon->setImageFormat("png24");
$data = $icon->getImageBlob();
/**
* @param $app string app name
- * @return string image blob
+ * @return string|false image blob
*/
public function getTouchIcon($app) {
$icon = $this->renderAppIcon($app);
+ if($icon === false) {
+ return false;
+ }
$icon->setImageFormat("png24");
$data = $icon->getImageBlob();
$icon->destroy();
* fallback to logo
*
* @param $app string app name
- * @return Imagick
+ * @return Imagick|false
*/
public function renderAppIcon($app) {
$appIcon = $this->util->getAppIcon($app);
$appIconContent = file_get_contents($appIcon);
+ if($appIconContent === false) {
+ return false;
+ }
$color = $this->themingDefaults->getMailHeaderColor();
$mime = mime_content_type($appIcon);
public function colorSvg($app, $image) {
$imageFile = $this->util->getAppImage($app, $image);
$svg = file_get_contents($imageFile);
- $color = $this->util->elementColor($this->themingDefaults->getMailHeaderColor());
- $svg = $this->util->colorizeSvg($svg, $color);
- return $svg;
+ if ($svg !== false) {
+ $color = $this->util->elementColor($this->themingDefaults->getMailHeaderColor());
+ $svg = $this->util->colorizeSvg($svg, $color);
+ return $svg;
+ } else {
+ return false;
+ }
}
}
use OCA\Theming\ImageManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDisplayResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IConfig;
$expected->setStatus(Http::STATUS_NOT_FOUND);
$expected->cacheFor(0);
$expected->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
- $this->assertEquals($expected, $this->iconController->getFavicon());
+ $this->assertInstanceOf(NotFoundResponse::class, $this->iconController->getFavicon());
}
public function testGetTouchIconDefault() {
$this->themingDefaults->expects($this->any())
->method('shouldReplaceIcons')
->willReturn(false);
- $expected = new Http\Response();
- $expected->setStatus(Http::STATUS_NOT_FOUND);
- $expected->cacheFor(0);
- $expected->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
- $this->assertEquals($expected, $this->iconController->getTouchIcon());
+ $this->assertInstanceOf(NotFoundResponse::class, $this->iconController->getTouchIcon());
}
}
use OCA\Theming\IconBuilder;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
+use OCP\AppFramework\Http\NotFoundResponse;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use Test\TestCase;
// cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ */
+ public function testGetFaviconNotFound() {
+ $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $iconBuilder = new IconBuilder($this->themingDefaults, $util);
+ $util->expects($this->once())
+ ->method('getAppIcon')
+ ->willReturn('notexistingfile');
+ $this->assertFalse($iconBuilder->getFavicon('noapp'));
+ }
+
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ */
+ public function testGetTouchIconNotFound() {
+ $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $iconBuilder = new IconBuilder($this->themingDefaults, $util);
+ $util->expects($this->once())
+ ->method('getAppIcon')
+ ->willReturn('notexistingfile');
+ $this->assertFalse($iconBuilder->getTouchIcon('noapp'));
+ }
+
+ /**
+ * @expectedException \PHPUnit_Framework_Error_Warning
+ */
+ public function testColorSvgNotFound() {
+ $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock();
+ $iconBuilder = new IconBuilder($this->themingDefaults, $util);
+ $util->expects($this->once())
+ ->method('getAppImage')
+ ->willReturn('notexistingfile');
+ $this->assertFalse($iconBuilder->colorSvg('noapp','noimage'));
+ }
}