namespace OCA\Theming\Controller;
use OCA\Theming\IconBuilder;
-use OCA\Theming\Template;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DataDisplayResponse;
-use OCP\AppFramework\Http\StreamResponse;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IRootFolder;
-use OCP\IConfig;
-use OCP\IL10N;
use OCP\IRequest;
use OCA\Theming\Util;
private $util;
/** @var ITimeFactory */
private $timeFactory;
- /** @var IL10N */
- private $l;
- /** @var IConfig */
- private $config;
- /** @var IRootFolder */
- private $rootFolder;
/** @var IconBuilder */
private $iconBuilder;
*
* @param string $appName
* @param IRequest $request
- * @param IConfig $config
* @param ThemingDefaults $themingDefaults
* @param Util $util
* @param ITimeFactory $timeFactory
- * @param IL10N $l
- * @param IRootFolder $rootFolder
+ * @param IconBuilder $iconBuilder
*/
public function __construct(
$appName,
IRequest $request,
- IConfig $config,
ThemingDefaults $themingDefaults,
Util $util,
ITimeFactory $timeFactory,
- IL10N $l,
- IRootFolder $rootFolder,
IconBuilder $iconBuilder
) {
parent::__construct($appName, $request);
$this->themingDefaults = $themingDefaults;
$this->util = $util;
$this->timeFactory = $timeFactory;
- $this->l = $l;
- $this->config = $config;
- $this->rootFolder = $rootFolder;
$this->iconBuilder = $iconBuilder;
- //if(extension_loaded('imagick')) {
- // $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util);
- //}
}
/**
* @PublicPage
* @NoCSRFRequired
*
- * @param $app app name
- * @param $image image file name (svg required)
- * @return StreamResponse|DataResponse
+ * @param $app string app name
+ * @param $image string image file name (svg required)
+ * @return DataDisplayResponse
*/
public function getThemedIcon($app, $image) {
$image = $this->util->getAppImage($app, $image);
* @PublicPage
* @NoCSRFRequired
*
- * @param $app app name
- * @return StreamResponse|DataResponse
+ * @param $app string app name
+ * @return DataDisplayResponse
*/
public function getFavicon($app="core") {
if($this->themingDefaults->shouldReplaceIcons()) {
* @PublicPage
* @NoCSRFRequired
*
- * @param $app app name
- * @return StreamResponse|DataResponse
+ * @param $app string app name
+ * @return DataDisplayResponse
*/
public function getTouchIcon($app="core") {
if($this->themingDefaults->shouldReplaceIcons()) {
return $response;
}
-
}
\ No newline at end of file
* @return DataDownloadResponse
*/
public function getJavascript() {
+ $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
$responseJS = '(function() {
OCA.Theming = {
name: ' . json_encode($this->template->getName()) . ',
slogan: ' . json_encode($this->template->getSlogan()) . ',
color: ' . json_encode($this->template->getMailHeaderColor()) . ',
inverted: ' . json_encode($this->util->invertTextColor($this->template->getMailHeaderColor())) . ',
+ cacheBuster: ' . json_encode($cacheBusterValue). '
};
})();';
$response = new Http\DataDisplayResponse($responseJS);
}
/**
- * @param $app app name
+ * @param $app string app name
* @return string image blob
*/
public function getFavicon($app) {
}
/**
- * @param $app app name
+ * @param $app string app name
* @return string image blob
*/
public function getTouchIcon($app) {
* Render app icon on themed background color
* fallback to logo
*
- * @param $app app name
+ * @param $app string app name
* @return Imagick
*/
public function renderAppIcon($app) {
/**
- * @param $app app name
+ * @param $app string app name
* @return string path to app icon / logo
*/
public function getAppIcon($app) {
$appPath = \OC_App::getAppPath($app);
-
$icon = $appPath . '/img/' . $app . '.svg';
if(file_exists($icon)) {
return $icon;
if(file_exists($icon)) {
return $icon;
}
-
if($this->config->getAppValue('theming', 'logoMime', '') !== '' && $this->rootFolder->nodeExists('/themedinstancelogo')) {
return $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
}
}
/**
- * @param $app app name
- * @param $image relative path to image in app folder
+ * @param $app string app name
+ * @param $image string relative path to image in app folder
* @return string absolute path to image
*/
public function getAppImage($app, $image) {
$appPath = \OC_App::getAppPath($app);
-
if($app==="core") {
$icon = \OC::$SERVERROOT . '/core/img/' . $image;
if(file_exists($icon)) {
return $icon;
}
}
-
$icon = $appPath . '/img/' . $image;
if(file_exists($icon)) {
return $icon;
/**
* replace default color with a custom one
*
- * @param $svg content of a svg file
- * @param $color color to match
+ * @param $svg string content of a svg file
+ * @param $color string color to match
* @return string
*/
public function colorizeSvg($svg, $color) {
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
- * @author Julius Haertl <jus@bitgrid.net>
+ * @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*/
namespace OCA\Theming\Tests\Controller;
-use OCA\Theming\Controller\IconController;
-use OCA\Theming\IconBuilder;
-use OCA\Theming\Util;
+
use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DataDisplayResponse;
-use OCP\Files\IRootFolder;
-use OCP\IConfig;
-use OCP\IL10N;
use OCP\IRequest;
use Test\TestCase;
-use OCA\Theming\ThemingDefaults;
-use \Imagick;
+use OCA\Theming\Util;
+use OCA\Theming\Controller\IconController;
+
class IconControllerTest extends TestCase {
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
private $request;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
- private $config;
- /** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
private $themingDefaults;
/** @var Util */
private $util;
/** @var \OCP\AppFramework\Utility\ITimeFactory */
private $timeFactory;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
- private $l10n;
- /** @var IconController */
private $iconController;
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
- private $rootFolder;
- /** @var IconBuilder */
private $iconBuilder;
public function setUp() {
$this->request = $this->getMockBuilder('OCP\IRequest')->getMock();
- $this->config = $this->getMockBuilder('OCP\IConfig')->getMock();
$this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults')
->disableOriginalConstructor()->getMock();
$this->util = $this->getMockBuilder('\OCA\Theming\Util')->disableOriginalConstructor()
$this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory')
->disableOriginalConstructor()
->getMock();
- $this->l10n = $this->getMockBuilder('OCP\IL10N')->getMock();
- $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
$this->iconBuilder = $this->getMockBuilder('OCA\Theming\IconBuilder')
->disableOriginalConstructor()->getMock();
$this->iconController = new IconController(
'theming',
$this->request,
- $this->config,
$this->themingDefaults,
$this->util,
$this->timeFactory,
- $this->l10n,
- $this->rootFolder,
$this->iconBuilder
);
slogan: "",
color: "#000",
inverted: false,
+ cacheBuster: null
};
})();';
$expected = new Http\DataDisplayResponse($expectedResponse);
slogan: "awesome",
color: "#ffffff",
inverted: true,
+ cacheBuster: null
};
})();';
$expected = new Http\DataDisplayResponse($expectedResponse);
* @param $file
*/
public function testRenderAppIcon($app, $color, $file) {
-
$this->themingDefaults->expects($this->once())
->method('getMailHeaderColor')
->willReturn($color);
$this->assertEquals($icon, $expectedIcon);
$icon->destroy();
$expectedIcon->destroy();
- //$this->assertLessThan(0.0005, $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]);
-
+ // FIXME: We may need some comparison of the generated and the test images
+ // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
/**
* @param $file
*/
public function testGetTouchIcon($app, $color, $file) {
-
$this->themingDefaults->expects($this->once())
->method('getMailHeaderColor')
->willReturn($color);
$this->assertEquals($icon, $expectedIcon);
$icon->destroy();
$expectedIcon->destroy();
- //$this->assertLessThan(0.0005, $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]);
-
+ // FIXME: We may need some comparison of the generated and the test images
+ // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
/**
* @param $file
*/
public function testGetFavicon($app, $color, $file) {
-
$this->themingDefaults->expects($this->once())
->method('getMailHeaderColor')
->willReturn($color);
$this->assertEquals(32, $icon->getImageHeight());
$icon->destroy();
$expectedIcon->destroy();
- //$this->assertLessThan(0.0005, $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1]);
-
+ // FIXME: We may need some comparison of the generated and the test images
+ // cloud be something like $expectedIcon->compareImages($icon, Imagick::METRIC_MEANABSOLUTEERROR)[1])
}
}
protected $util;
/** @var IConfig */
protected $config;
+ /** @var IRootFolder */
protected $rootFolder;
+
protected function setUp() {
parent::setUp();
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
path += '.svg';
+ if(OCA.Theming) {
+ path += "?v=" + OCA.Theming.cacheBuster;
+ }
+
// Cache the result
OC.MimeType._mimeTypeIcons[mimeType] = path;
return path;