diff options
Diffstat (limited to 'apps/theming/tests/Controller/IconControllerTest.php')
-rw-r--r-- | apps/theming/tests/Controller/IconControllerTest.php | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php index add11df3e6d..c6a40b5942e 100644 --- a/apps/theming/tests/Controller/IconControllerTest.php +++ b/apps/theming/tests/Controller/IconControllerTest.php @@ -24,10 +24,12 @@ 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; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataDisplayResponse; use OCP\AppFramework\Http\NotFoundResponse; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -53,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; @@ -69,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); @@ -81,7 +86,8 @@ class IconControllerTest extends TestCase { $this->timeFactory, $this->config, $this->iconBuilder, - $this->imageManager + $this->imageManager, + $this->fileAccessHelper ); parent::setUp(); @@ -150,11 +156,19 @@ class IconControllerTest extends TestCase { $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->assertInstanceOf(NotFoundResponse::class, $this->iconController->getFavicon()); + $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(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $expected->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $expected->addHeader('Pragma', 'cache'); + $this->assertEquals($expected, $this->iconController->getFavicon()); } public function testGetTouchIconDefault() { @@ -195,7 +209,19 @@ class IconControllerTest extends TestCase { $this->themingDefaults->expects($this->any()) ->method('shouldReplaceIcons') ->willReturn(false); - $this->assertInstanceOf(NotFoundResponse::class, $this->iconController->getTouchIcon()); + $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(); + $expires->setTimestamp($this->timeFactory->getTime()); + $expires->add(new \DateInterval('PT24H')); + $expected->addHeader('Expires', $expires->format(\DateTime::RFC2822)); + $expected->addHeader('Pragma', 'cache'); + $this->assertEquals($expected, $this->iconController->getTouchIcon()); } } |