summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2017-05-18 10:45:42 +0200
committerJulius Härtl <jus@bitgrid.net>2017-05-18 10:45:42 +0200
commit489131333ab2db67d84baca623f3649336f417c1 (patch)
treef7677d41ba68954917608ae75aec943ee311f288 /apps
parentedb5502b9d695f1eb12b58eac09d64d76339ec05 (diff)
downloadnextcloud-server-489131333ab2db67d84baca623f3649336f417c1.tar.gz
nextcloud-server-489131333ab2db67d84baca623f3649336f417c1.zip
Inject FileAccessHelper for proper testing
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/lib/Controller/IconController.php14
-rw-r--r--apps/theming/tests/Controller/IconControllerTest.php15
2 files changed, 21 insertions, 8 deletions
diff --git a/apps/theming/lib/Controller/IconController.php b/apps/theming/lib/Controller/IconController.php
index eb51d2d799c..5532a08c83c 100644
--- a/apps/theming/lib/Controller/IconController.php
+++ b/apps/theming/lib/Controller/IconController.php
@@ -50,6 +50,8 @@ class IconController extends Controller {
private $iconBuilder;
/** @var ImageManager */
private $imageManager;
+ /** @var FileAccessHelper */
+ private $fileAccessHelper;
/**
* IconController constructor.
@@ -71,7 +73,8 @@ class IconController extends Controller {
ITimeFactory $timeFactory,
IConfig $config,
IconBuilder $iconBuilder,
- ImageManager $imageManager
+ ImageManager $imageManager,
+ FileAccessHelper $fileAccessHelper
) {
parent::__construct($appName, $request);
@@ -81,6 +84,7 @@ class IconController extends Controller {
$this->config = $config;
$this->iconBuilder = $iconBuilder;
$this->imageManager = $imageManager;
+ $this->fileAccessHelper = $fileAccessHelper;
}
/**
@@ -139,9 +143,7 @@ class IconController extends Controller {
}
if($response === null) {
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
- /** @var FileAccessHelper */
- $fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
- $response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
+ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
}
$response->cacheFor(86400);
$expires = new \DateTime();
@@ -176,9 +178,7 @@ class IconController extends Controller {
}
if($response === null) {
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
- /** @var FileAccessHelper */
- $fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
- $response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
+ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
}
$response->cacheFor(86400);
$expires = new \DateTime();
diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php
index 0a93ce1f10d..c6a40b5942e 100644
--- a/apps/theming/tests/Controller/IconControllerTest.php
+++ b/apps/theming/tests/Controller/IconControllerTest.php
@@ -24,6 +24,7 @@ namespace OCA\Theming\Tests\Controller;
use OC\Files\SimpleFS\SimpleFile;
+use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OCA\Theming\IconBuilder;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
@@ -54,6 +55,8 @@ class IconControllerTest extends TestCase {
private $config;
/** @var IconBuilder|\PHPUnit_Framework_MockObject_MockObject */
private $iconBuilder;
+ /** @var FileAccessHelper|\PHPUnit_Framework_MockObject_MockObject */
+ private $fileAccessHelper;
/** @var ImageManager */
private $imageManager;
@@ -70,6 +73,7 @@ class IconControllerTest extends TestCase {
$this->iconBuilder = $this->getMockBuilder('OCA\Theming\IconBuilder')
->disableOriginalConstructor()->getMock();
$this->imageManager = $this->getMockBuilder('OCA\Theming\ImageManager')->disableOriginalConstructor()->getMock();
+ $this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
$this->timeFactory->expects($this->any())
->method('getTime')
->willReturn(123);
@@ -82,7 +86,8 @@ class IconControllerTest extends TestCase {
$this->timeFactory,
$this->config,
$this->iconBuilder,
- $this->imageManager
+ $this->imageManager,
+ $this->fileAccessHelper
);
parent::setUp();
@@ -152,6 +157,10 @@ class IconControllerTest extends TestCase {
->method('shouldReplaceIcons')
->willReturn(false);
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
+ $this->fileAccessHelper->expects($this->once())
+ ->method('file_get_contents')
+ ->with($fallbackLogo)
+ ->willReturn(file_get_contents($fallbackLogo));
$expected = new DataDisplayResponse(file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
$expected->cacheFor(86400);
$expires = new \DateTime();
@@ -201,6 +210,10 @@ class IconControllerTest extends TestCase {
->method('shouldReplaceIcons')
->willReturn(false);
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
+ $this->fileAccessHelper->expects($this->once())
+ ->method('file_get_contents')
+ ->with($fallbackLogo)
+ ->willReturn(file_get_contents($fallbackLogo));
$expected = new DataDisplayResponse(file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
$expected->cacheFor(86400);
$expires = new \DateTime();