summaryrefslogtreecommitdiffstats
path: root/apps/theming
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-11-18 14:55:07 +0100
committerGitHub <noreply@github.com>2016-11-18 14:55:07 +0100
commit8b9ad46ba3ef876f00dc6bdadd7b51d7b1fa1c78 (patch)
treebc9c6a21ddc68656d8fd93c67f11b754a358afdb /apps/theming
parent6c11c54434b29bb9f7f07ba9a8070ed8308bc5a4 (diff)
parent4ac5fdcf11b0ca7dd985d50a91393a1c185821ff (diff)
downloadnextcloud-server-8b9ad46ba3ef876f00dc6bdadd7b51d7b1fa1c78.tar.gz
nextcloud-server-8b9ad46ba3ef876f00dc6bdadd7b51d7b1fa1c78.zip
Merge pull request #768 from nextcloud/s3-objectstore
Add S3 objectstore backend
Diffstat (limited to 'apps/theming')
-rw-r--r--apps/theming/lib/Controller/ThemingController.php27
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php49
2 files changed, 46 insertions, 30 deletions
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php
index 09b4a14f2b0..1eefb2e3dd7 100644
--- a/apps/theming/lib/Controller/ThemingController.php
+++ b/apps/theming/lib/Controller/ThemingController.php
@@ -32,9 +32,12 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\StreamResponse;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Files\File;
use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
@@ -255,15 +258,17 @@ class ThemingController extends Controller {
* @PublicPage
* @NoCSRFRequired
*
- * @return StreamResponse|DataResponse
+ * @return StreamResponse|NotFoundResponse
*/
public function getLogo() {
- $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
- if(!file_exists($pathToLogo)) {
- return new DataResponse();
+ try {
+ /** @var File $file */
+ $file = $this->rootFolder->get('themedinstancelogo');
+ } catch (NotFoundException $e) {
+ return new NotFoundResponse();
}
- $response = new Http\StreamResponse($pathToLogo);
+ $response = new Http\StreamResponse($file->fopen('r'));
$response->cacheFor(3600);
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
$response->addHeader('Content-Disposition', 'attachment');
@@ -276,15 +281,17 @@ class ThemingController extends Controller {
* @PublicPage
* @NoCSRFRequired
*
- * @return StreamResponse|DataResponse
+ * @return StreamResponse|NotFoundResponse
*/
public function getLoginBackground() {
- $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedbackgroundlogo';
- if(!file_exists($pathToLogo)) {
- return new DataResponse();
+ try {
+ /** @var File $file */
+ $file = $this->rootFolder->get('themedbackgroundlogo');
+ } catch (NotFoundException $e) {
+ return new NotFoundResponse();
}
- $response = new StreamResponse($pathToLogo);
+ $response = new StreamResponse($file->fopen('r'));
$response->cacheFor(3600);
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
$response->addHeader('Content-Disposition', 'attachment');
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index d9d5005e25f..c9f6ff8a885 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -28,7 +28,9 @@ use OCA\Theming\Controller\ThemingController;
use OCA\Theming\Util;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
+use OCP\Files\File;
use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
@@ -338,26 +340,30 @@ class ThemingControllerTest extends TestCase {
}
public function testGetLogoNotExistent() {
- $expected = new DataResponse();
+ $this->rootFolder->method('get')
+ ->with($this->equalTo('themedinstancelogo'))
+ ->willThrowException(new NotFoundException());
+
+ $expected = new Http\NotFoundResponse();
$this->assertEquals($expected, $this->themingController->getLogo());
}
public function testGetLogo() {
- $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
- $tmpLogo = $dataFolder . '/themedinstancelogo';
- touch($tmpLogo);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('datadirectory', \OC::$SERVERROOT . '/data/')
- ->willReturn($dataFolder);
+ $file = $this->createMock(File::class);
+ $this->rootFolder->method('get')
+ ->with('themedinstancelogo')
+ ->willReturn($file);
+ $file->method('fopen')
+ ->with('r')
+ ->willReturn('mypath');
+
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'logoMime', '')
->willReturn('text/svg');
- @$expected = new Http\StreamResponse($tmpLogo);
+ @$expected = new Http\StreamResponse('mypath');
$expected->cacheFor(3600);
$expected->addHeader('Expires', date(\DateTime::RFC2822, 123));
$expected->addHeader('Content-Disposition', 'attachment');
@@ -368,26 +374,29 @@ class ThemingControllerTest extends TestCase {
public function testGetLoginBackgroundNotExistent() {
- $expected = new DataResponse();
+ $this->rootFolder->method('get')
+ ->with('themedbackgroundlogo')
+ ->willThrowException(new NotFoundException());
+ $expected = new Http\NotFoundResponse();
$this->assertEquals($expected, $this->themingController->getLoginBackground());
}
public function testGetLoginBackground() {
- $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
- $tmpLogo = $dataFolder . '/themedbackgroundlogo';
- touch($tmpLogo);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('datadirectory', \OC::$SERVERROOT . '/data/')
- ->willReturn($dataFolder);
+ $file = $this->createMock(File::class);
+ $this->rootFolder->method('get')
+ ->with('themedbackgroundlogo')
+ ->willReturn($file);
+ $file->method('fopen')
+ ->with('r')
+ ->willReturn('mypath');
+
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime', '')
->willReturn('image/png');
- @$expected = new Http\StreamResponse($tmpLogo);
+ @$expected = new Http\StreamResponse('mypath');
$expected->cacheFor(3600);
$expected->addHeader('Expires', date(\DateTime::RFC2822, 123));
$expected->addHeader('Content-Disposition', 'attachment');