Inject FileAccessHelper for proper testing

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2017-05-18 10:45:42 +02:00
parent edb5502b9d
commit 489131333a
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 21 additions and 8 deletions

View File

@ -50,6 +50,8 @@ class IconController extends Controller {
private $iconBuilder; private $iconBuilder;
/** @var ImageManager */ /** @var ImageManager */
private $imageManager; private $imageManager;
/** @var FileAccessHelper */
private $fileAccessHelper;
/** /**
* IconController constructor. * IconController constructor.
@ -71,7 +73,8 @@ class IconController extends Controller {
ITimeFactory $timeFactory, ITimeFactory $timeFactory,
IConfig $config, IConfig $config,
IconBuilder $iconBuilder, IconBuilder $iconBuilder,
ImageManager $imageManager ImageManager $imageManager,
FileAccessHelper $fileAccessHelper
) { ) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
@ -81,6 +84,7 @@ class IconController extends Controller {
$this->config = $config; $this->config = $config;
$this->iconBuilder = $iconBuilder; $this->iconBuilder = $iconBuilder;
$this->imageManager = $imageManager; $this->imageManager = $imageManager;
$this->fileAccessHelper = $fileAccessHelper;
} }
/** /**
@ -139,9 +143,7 @@ class IconController extends Controller {
} }
if($response === null) { if($response === null) {
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
/** @var FileAccessHelper */ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
} }
$response->cacheFor(86400); $response->cacheFor(86400);
$expires = new \DateTime(); $expires = new \DateTime();
@ -176,9 +178,7 @@ class IconController extends Controller {
} }
if($response === null) { if($response === null) {
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png';
/** @var FileAccessHelper */ $response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
$fileAccessHelper = \OC::$server->query(FileAccessHelper::class);
$response = new DataDisplayResponse($fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
} }
$response->cacheFor(86400); $response->cacheFor(86400);
$expires = new \DateTime(); $expires = new \DateTime();

View File

@ -24,6 +24,7 @@ namespace OCA\Theming\Tests\Controller;
use OC\Files\SimpleFS\SimpleFile; use OC\Files\SimpleFS\SimpleFile;
use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OCA\Theming\IconBuilder; use OCA\Theming\IconBuilder;
use OCA\Theming\ImageManager; use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults; use OCA\Theming\ThemingDefaults;
@ -54,6 +55,8 @@ class IconControllerTest extends TestCase {
private $config; private $config;
/** @var IconBuilder|\PHPUnit_Framework_MockObject_MockObject */ /** @var IconBuilder|\PHPUnit_Framework_MockObject_MockObject */
private $iconBuilder; private $iconBuilder;
/** @var FileAccessHelper|\PHPUnit_Framework_MockObject_MockObject */
private $fileAccessHelper;
/** @var ImageManager */ /** @var ImageManager */
private $imageManager; private $imageManager;
@ -70,6 +73,7 @@ class IconControllerTest extends TestCase {
$this->iconBuilder = $this->getMockBuilder('OCA\Theming\IconBuilder') $this->iconBuilder = $this->getMockBuilder('OCA\Theming\IconBuilder')
->disableOriginalConstructor()->getMock(); ->disableOriginalConstructor()->getMock();
$this->imageManager = $this->getMockBuilder('OCA\Theming\ImageManager')->disableOriginalConstructor()->getMock(); $this->imageManager = $this->getMockBuilder('OCA\Theming\ImageManager')->disableOriginalConstructor()->getMock();
$this->fileAccessHelper = $this->createMock(FileAccessHelper::class);
$this->timeFactory->expects($this->any()) $this->timeFactory->expects($this->any())
->method('getTime') ->method('getTime')
->willReturn(123); ->willReturn(123);
@ -82,7 +86,8 @@ class IconControllerTest extends TestCase {
$this->timeFactory, $this->timeFactory,
$this->config, $this->config,
$this->iconBuilder, $this->iconBuilder,
$this->imageManager $this->imageManager,
$this->fileAccessHelper
); );
parent::setUp(); parent::setUp();
@ -152,6 +157,10 @@ class IconControllerTest extends TestCase {
->method('shouldReplaceIcons') ->method('shouldReplaceIcons')
->willReturn(false); ->willReturn(false);
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; $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 = new DataDisplayResponse(file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
$expected->cacheFor(86400); $expected->cacheFor(86400);
$expires = new \DateTime(); $expires = new \DateTime();
@ -201,6 +210,10 @@ class IconControllerTest extends TestCase {
->method('shouldReplaceIcons') ->method('shouldReplaceIcons')
->willReturn(false); ->willReturn(false);
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; $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 = new DataDisplayResponse(file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
$expected->cacheFor(86400); $expected->cacheFor(86400);
$expires = new \DateTime(); $expires = new \DateTime();