Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-03-29 00:42:20 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2017-03-29 00:42:20 +0300
commit3a0ef65f332691177ee8449fce54296c80c69f1f (patch)
tree291d73e347c6a893cd8b98e47f4d564a70211a44 /tests/Core
parenta40405531cc0a5fcb81dc5d12b739a7f951948e9 (diff)
Fix controller tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/Core')
-rw-r--r--tests/Core/Controller/CssControllerTest.php68
-rw-r--r--tests/Core/Controller/JsControllerTest.php68
2 files changed, 134 insertions, 2 deletions
diff --git a/tests/Core/Controller/CssControllerTest.php b/tests/Core/Controller/CssControllerTest.php
index 60fef9dddad..7fa358e056e 100644
--- a/tests/Core/Controller/CssControllerTest.php
+++ b/tests/Core/Controller/CssControllerTest.php
@@ -40,6 +40,9 @@ class CssControllerTest extends TestCase {
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
private $appData;
+ /** @var IRequests|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
/** @var CssController */
private $controller;
@@ -52,9 +55,11 @@ class CssControllerTest extends TestCase {
$timeFactory->method('getTime')
->willReturn(1337);
+ $this->request = $this->createMock(IRequest::class);
+
$this->controller = new CssController(
'core',
- $this->createMock(IRequest::class),
+ $this->request,
$this->appData,
$timeFactory
);
@@ -108,4 +113,65 @@ class CssControllerTest extends TestCase {
$this->assertEquals($expected, $result);
}
+ public function testGetGzipFile() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $gzipFile = $this->createMock(ISimpleFile::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->with('file.css.gz')
+ ->willReturn($gzipFile);
+
+ $this->request->method('getHeader')
+ ->with('Accept-Encoding')
+ ->willReturn('gzip, deflate');
+
+ $expected = new FileDisplayResponse($gzipFile, Http::STATUS_OK, ['Content-Type' => 'text/css']);
+ $expected->addHeader('Content-Encoding', 'gzip');
+ $expected->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp(1337);
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $expected->addHeader('Pragma', 'cache');
+
+ $result = $this->controller->getCss('file.css', 'myapp');
+ $this->assertEquals($expected, $result);
+ }
+
+ public function testGetGzipFileNotFound() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $file = $this->createMock(ISimpleFile::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(
+ function($fileName) use ($file) {
+ if ($fileName === 'file.css') {
+ return $file;
+ }
+ throw new NotFoundException();
+ })
+ );
+
+ $this->request->method('getHeader')
+ ->with('Accept-Encoding')
+ ->willReturn('gzip, deflate');
+
+ $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']);
+ $expected->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp(1337);
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $expected->addHeader('Pragma', 'cache');
+
+ $result = $this->controller->getCss('file.css', 'myapp');
+ $this->assertEquals($expected, $result);
+ }
+
}
diff --git a/tests/Core/Controller/JsControllerTest.php b/tests/Core/Controller/JsControllerTest.php
index febb785f60d..8f48a7c3390 100644
--- a/tests/Core/Controller/JsControllerTest.php
+++ b/tests/Core/Controller/JsControllerTest.php
@@ -42,6 +42,9 @@ class JsControllerTest extends TestCase {
/** @var JsController */
private $controller;
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
public function setUp() {
parent::setUp();
@@ -51,9 +54,11 @@ class JsControllerTest extends TestCase {
$timeFactory->method('getTime')
->willReturn(1337);
+ $this->request = $this->createMock(IRequest::class);
+
$this->controller = new JsController(
'core',
- $this->createMock(IRequest::class),
+ $this->request,
$this->appData,
$timeFactory
);
@@ -107,4 +112,65 @@ class JsControllerTest extends TestCase {
$this->assertEquals($expected, $result);
}
+ public function testGetGzipFile() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $gzipFile = $this->createMock(ISimpleFile::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->with('file.js.gz')
+ ->willReturn($gzipFile);
+
+ $this->request->method('getHeader')
+ ->with('Accept-Encoding')
+ ->willReturn('gzip, deflate');
+
+ $expected = new FileDisplayResponse($gzipFile, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
+ $expected->addHeader('Content-Encoding', 'gzip');
+ $expected->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp(1337);
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $expected->addHeader('Pragma', 'cache');
+
+ $result = $this->controller->getJs('file.js', 'myapp');
+ $this->assertEquals($expected, $result);
+ }
+
+ public function testGetGzipFileNotFound() {
+ $folder = $this->createMock(ISimpleFolder::class);
+ $file = $this->createMock(ISimpleFile::class);
+ $this->appData->method('getFolder')
+ ->with('myapp')
+ ->willReturn($folder);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(
+ function($fileName) use ($file) {
+ if ($fileName === 'file.js') {
+ return $file;
+ }
+ throw new NotFoundException();
+ })
+ );
+
+ $this->request->method('getHeader')
+ ->with('Accept-Encoding')
+ ->willReturn('gzip, deflate');
+
+ $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
+ $expected->cacheFor(86400);
+ $expires = new \DateTime();
+ $expires->setTimestamp(1337);
+ $expires->add(new \DateInterval('PT24H'));
+ $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
+ $expected->addHeader('Pragma', 'cache');
+
+ $result = $this->controller->getJs('file.js', 'myapp');
+ $this->assertEquals($expected, $result);
+ }
+
}