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

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Controller/AccountsController.php3
-rw-r--r--lib/Controller/AliasesController.php2
-rw-r--r--lib/Controller/AutoCompleteController.php2
-rw-r--r--lib/Controller/AvatarsController.php16
-rw-r--r--lib/Controller/FoldersController.php2
-rw-r--r--lib/Controller/LocalAttachmentsController.php2
-rwxr-xr-xlib/Controller/MessagesController.php12
-rw-r--r--lib/Controller/PageController.php1
-rw-r--r--lib/Controller/PreferencesController.php2
-rw-r--r--lib/Http/AvatarDownloadResponse.php2
-rw-r--r--lib/Http/CacheHeaders.php46
-rw-r--r--lib/Http/HtmlResponse.php2
-rw-r--r--lib/Http/JSONErrorResponse.php1
-rw-r--r--lib/Http/JSONResponse.php35
-rw-r--r--lib/Http/Middleware/ErrorMiddleware.php2
-rw-r--r--lib/Http/ProxyDownloadResponse.php5
-rw-r--r--tests/Controller/AccountsControllerTest.php2
-rw-r--r--tests/Controller/AliasesControllerTest.php4
-rw-r--r--tests/Controller/AutoconfigControllerTest.php2
-rw-r--r--tests/Controller/AvatarControllerTest.php32
-rw-r--r--tests/Controller/FoldersControllerTest.php2
-rw-r--r--tests/Controller/LocalAttachmentsControllerTest.php2
-rw-r--r--tests/Controller/MessagesControllerTest.php28
-rw-r--r--tests/Controller/PreferencesControllerTest.php2
-rw-r--r--tests/Http/Middleware/ErrorMiddlewareTest.php2
25 files changed, 67 insertions, 144 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php
index 61fee9a7f..0198a34ba 100644
--- a/lib/Controller/AccountsController.php
+++ b/lib/Controller/AccountsController.php
@@ -30,11 +30,9 @@ declare(strict_types=1);
namespace OCA\Mail\Controller;
use Exception;
-use Horde_Exception;
use OCA\Mail\Contracts\IMailTransmission;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\ServiceException;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Model\NewMessageData;
use OCA\Mail\Model\RepliedMessageData;
use OCA\Mail\Service\AccountService;
@@ -43,6 +41,7 @@ use OCA\Mail\Service\GroupsIntegration;
use OCA\Mail\Service\SetupService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
diff --git a/lib/Controller/AliasesController.php b/lib/Controller/AliasesController.php
index 1d16f19de..cda86bd65 100644
--- a/lib/Controller/AliasesController.php
+++ b/lib/Controller/AliasesController.php
@@ -24,10 +24,10 @@ declare(strict_types=1);
namespace OCA\Mail\Controller;
use OCA\Mail\Exception\NotImplemented;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\AliasesService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
diff --git a/lib/Controller/AutoCompleteController.php b/lib/Controller/AutoCompleteController.php
index a97340241..b714c5e1d 100644
--- a/lib/Controller/AutoCompleteController.php
+++ b/lib/Controller/AutoCompleteController.php
@@ -23,9 +23,9 @@ declare(strict_types=1);
namespace OCA\Mail\Controller;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\AutoCompletion\AutoCompleteService;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class AutoCompleteController extends Controller {
diff --git a/lib/Controller/AvatarsController.php b/lib/Controller/AvatarsController.php
index d7202dfda..7d5d26b7e 100644
--- a/lib/Controller/AvatarsController.php
+++ b/lib/Controller/AvatarsController.php
@@ -26,11 +26,10 @@ namespace OCA\Mail\Controller;
use OCA\Mail\Contracts\IAvatarService;
use OCA\Mail\Http\AvatarDownloadResponse;
-use OCA\Mail\Http\JSONResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
class AvatarsController extends Controller {
@@ -41,19 +40,14 @@ class AvatarsController extends Controller {
/** @var string */
private $uid;
- /** @var ITimeFactory */
- private $timeFactory;
-
public function __construct(string $appName,
IRequest $request,
IAvatarService $avatarService,
- string $UserId,
- ITimeFactory $timeFactory) {
+ string $UserId) {
parent::__construct($appName, $request);
$this->avatarService = $avatarService;
$this->uid = $UserId;
- $this->timeFactory = $timeFactory;
}
/**
@@ -80,7 +74,7 @@ class AvatarsController extends Controller {
// Debounce this a bit
// (cache for one day)
- $response->setCacheHeaders(24 * 60 * 60, $this->timeFactory);
+ $response->cacheFor(24*60*60);
return $response;
}
@@ -88,7 +82,7 @@ class AvatarsController extends Controller {
$response = new JSONResponse($avatar);
// Let the browser cache this for a week
- $response->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory);
+ $response->cacheFor(7 * 24 * 60 * 60);
return $response;
}
@@ -118,7 +112,7 @@ class AvatarsController extends Controller {
$resp->addHeader('Content-Type', $avatar->getMime());
// Let the browser cache this for a week
- $resp->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory);
+ $resp->cacheFor(7 * 24 * 60 * 60);
return $resp;
}
diff --git a/lib/Controller/FoldersController.php b/lib/Controller/FoldersController.php
index 6c5409df5..5316bfb1c 100644
--- a/lib/Controller/FoldersController.php
+++ b/lib/Controller/FoldersController.php
@@ -29,11 +29,11 @@ use function base64_decode;
use function is_array;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Exception\NotImplemented;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\IMAP\Sync\Request as SyncRequest;
use OCA\Mail\Service\AccountService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class FoldersController extends Controller {
diff --git a/lib/Controller/LocalAttachmentsController.php b/lib/Controller/LocalAttachmentsController.php
index 5d6dfdd45..ce98814ba 100644
--- a/lib/Controller/LocalAttachmentsController.php
+++ b/lib/Controller/LocalAttachmentsController.php
@@ -26,10 +26,10 @@ namespace OCA\Mail\Controller;
use OCA\Mail\Contracts\IAttachmentService;
use OCA\Mail\Exception\ClientException;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\Attachment\UploadedFile;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class LocalAttachmentsController extends Controller {
diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php
index a6d1821d7..32a87956a 100755
--- a/lib/Controller/MessagesController.php
+++ b/lib/Controller/MessagesController.php
@@ -85,9 +85,6 @@ class MessagesController extends Controller {
/** @var IURLGenerator */
private $urlGenerator;
- /** @var ITimeFactory */
- private $timeFactory;
-
/**
* @param string $appName
* @param IRequest $request
@@ -98,7 +95,6 @@ class MessagesController extends Controller {
* @param IL10N $l10n
* @param IMimeTypeDetector $mimeTypeDetector
* @param IURLGenerator $urlGenerator
- * @param ITimeFactory $timeFactory
*/
public function __construct(string $appName,
IRequest $request,
@@ -110,8 +106,7 @@ class MessagesController extends Controller {
ILogger $logger,
IL10N $l10n,
IMimeTypeDetector $mimeTypeDetector,
- IURLGenerator $urlGenerator,
- ITimeFactory $timeFactory) {
+ IURLGenerator $urlGenerator) {
parent::__construct($appName, $request);
$this->accountService = $accountService;
@@ -123,7 +118,7 @@ class MessagesController extends Controller {
$this->l10n = $l10n;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->urlGenerator = $urlGenerator;
- $this->timeFactory = $timeFactory;
+ $this->mailManager = $mailManager;
}
/**
@@ -257,8 +252,7 @@ class MessagesController extends Controller {
$htmlResponse->setContentSecurityPolicy($policy);
// Enable caching
- $htmlResponse->setCacheHeaders(60 * 60, $this->timeFactory);
- $htmlResponse->addHeader('Pragma', 'cache');
+ $htmlResponse->cacheFor(60 * 60);
return $htmlResponse;
} catch (Exception $ex) {
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index c74ce8c57..6538dd50a 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -28,7 +28,6 @@ namespace OCA\Mail\Controller;
use Exception;
use OCA\Mail\Contracts\IUserPreferences;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\AliasesService;
use OCA\Mail\Service\MailManager;
diff --git a/lib/Controller/PreferencesController.php b/lib/Controller/PreferencesController.php
index 1e00a118d..280f70422 100644
--- a/lib/Controller/PreferencesController.php
+++ b/lib/Controller/PreferencesController.php
@@ -28,8 +28,8 @@ namespace OCA\Mail\Controller;
use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Exception\ClientException;
-use OCA\Mail\Http\JSONResponse;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
class PreferencesController extends Controller {
diff --git a/lib/Http/AvatarDownloadResponse.php b/lib/Http/AvatarDownloadResponse.php
index 0030e3d55..532c464c5 100644
--- a/lib/Http/AvatarDownloadResponse.php
+++ b/lib/Http/AvatarDownloadResponse.php
@@ -27,8 +27,6 @@ use OCP\AppFramework\Http\DownloadResponse;
class AvatarDownloadResponse extends DownloadResponse {
- use CacheHeaders;
-
/** @var string */
private $content;
diff --git a/lib/Http/CacheHeaders.php b/lib/Http/CacheHeaders.php
deleted file mode 100644
index c1ec0c999..000000000
--- a/lib/Http/CacheHeaders.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Mail\Http;
-
-use DateInterval;
-use DateTime;
-use OCP\AppFramework\Utility\ITimeFactory;
-
-trait CacheHeaders {
-
- public function setCacheHeaders(int $cacheFor, ITimeFactory $timeFactory) {
- $this->cacheFor($cacheFor);
-
- $expires = new DateTime();
- $expires->setTimestamp($timeFactory->getTime());
- $expires->add(new DateInterval('PT' . $cacheFor . 'S'));
- $this->addHeader('Expires', $expires->format(DateTime::RFC1123));
-
- $this->addHeader('Pragma', 'cache');
- }
-
-}
diff --git a/lib/Http/HtmlResponse.php b/lib/Http/HtmlResponse.php
index c50d251ca..37cd8b78d 100644
--- a/lib/Http/HtmlResponse.php
+++ b/lib/Http/HtmlResponse.php
@@ -29,8 +29,6 @@ use OCP\AppFramework\Http\Response;
class HtmlResponse extends Response {
- use CacheHeaders;
-
/** @var string */
private $content;
diff --git a/lib/Http/JSONErrorResponse.php b/lib/Http/JSONErrorResponse.php
index 69ff2aae7..4579f9bcb 100644
--- a/lib/Http/JSONErrorResponse.php
+++ b/lib/Http/JSONErrorResponse.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\Mail\Http;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
class JSONErrorResponse extends JSONResponse {
diff --git a/lib/Http/JSONResponse.php b/lib/Http/JSONResponse.php
deleted file mode 100644
index 3ede7e46e..000000000
--- a/lib/Http/JSONResponse.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Mail\Http;
-
-use OCP\AppFramework\Http\JSONResponse as Base;
-
-class JSONResponse extends Base {
-
- use CacheHeaders;
-
-}
diff --git a/lib/Http/Middleware/ErrorMiddleware.php b/lib/Http/Middleware/ErrorMiddleware.php
index 9b5e60ab5..ab495804f 100644
--- a/lib/Http/Middleware/ErrorMiddleware.php
+++ b/lib/Http/Middleware/ErrorMiddleware.php
@@ -30,10 +30,10 @@ use Exception;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Http\JSONErrorResponse;
-use OCA\Mail\Http\JSONResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
diff --git a/lib/Http/ProxyDownloadResponse.php b/lib/Http/ProxyDownloadResponse.php
index c8af04ee3..3fa4d3275 100644
--- a/lib/Http/ProxyDownloadResponse.php
+++ b/lib/Http/ProxyDownloadResponse.php
@@ -31,8 +31,6 @@ use OCP\AppFramework\Utility\ITimeFactory;
class ProxyDownloadResponse extends DownloadResponse {
- use CacheHeaders;
-
/** @var string */
private $content;
@@ -51,10 +49,9 @@ class ProxyDownloadResponse extends DownloadResponse {
$this->content = $content;
- $time = OC::$server->query(ITimeFactory::class);
$now = (new DateTime('now'))->getTimestamp();
$expires = (new DateTime('now + 11 months'))->getTimestamp();
- $this->setCacheHeaders($expires - $now, $time);
+ $this->cacheFor($expires - $now);
}
/**
diff --git a/tests/Controller/AccountsControllerTest.php b/tests/Controller/AccountsControllerTest.php
index b5ef64b6a..aaeed5348 100644
--- a/tests/Controller/AccountsControllerTest.php
+++ b/tests/Controller/AccountsControllerTest.php
@@ -29,7 +29,6 @@ use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailTransmission;
use OCA\Mail\Controller\AccountsController;
use OCA\Mail\Exception\ClientException;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Model\NewMessageData;
use OCA\Mail\Model\RepliedMessageData;
use OCA\Mail\Service\AccountService;
@@ -39,6 +38,7 @@ use OCA\Mail\Service\SetupService;
use OCA\Mail\Service\GroupsIntegration;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
diff --git a/tests/Controller/AliasesControllerTest.php b/tests/Controller/AliasesControllerTest.php
index 37a42d3f6..506f09ca3 100644
--- a/tests/Controller/AliasesControllerTest.php
+++ b/tests/Controller/AliasesControllerTest.php
@@ -24,8 +24,8 @@ namespace OCA\Mail\Tests\Controller;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Controller\AliasesController;
use OCA\Mail\Db\Alias;
-use OCA\Mail\Http\JSONResponse;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
class AliasesControllerTest extends TestCase {
private $controller;
@@ -54,7 +54,7 @@ class AliasesControllerTest extends TestCase {
$this->userSession->expects($this->once())
->method('getUser')
->will($this->returnValue($this->user));
-
+
$this->controller = new AliasesController($this->appName, $this->request, $this->aliasService, $this->userSession);
}
diff --git a/tests/Controller/AutoconfigControllerTest.php b/tests/Controller/AutoconfigControllerTest.php
index 848b52d08..3b9144001 100644
--- a/tests/Controller/AutoconfigControllerTest.php
+++ b/tests/Controller/AutoconfigControllerTest.php
@@ -23,7 +23,7 @@ namespace OCA\Mail\Tests\Controller;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Controller\AutoCompleteController;
-use OCA\Mail\Http\JSONResponse;
+use OCP\AppFramework\Http\JSONResponse;
class AutoConfigControllerTest extends TestCase {
diff --git a/tests/Controller/AvatarControllerTest.php b/tests/Controller/AvatarControllerTest.php
index 1577297da..96bbe0120 100644
--- a/tests/Controller/AvatarControllerTest.php
+++ b/tests/Controller/AvatarControllerTest.php
@@ -27,10 +27,10 @@ namespace OCA\Mail\Tests\Controller;
use OCA\Mail\Contracts\IAvatarService;
use OCA\Mail\Controller\AvatarsController;
use OCA\Mail\Http\AvatarDownloadResponse;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\Avatar\Avatar;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
@@ -41,23 +41,35 @@ class AvatarControllerTest extends TestCase {
/** @var IAvatarService|PHPUnit_Framework_MockObject_MockObject */
private $avatarService;
- /** @var ITimeFactory|PHPUnit_Framework_MockObject_MockObject */
- private $timeFactory;
-
/** @var AvatarsController */
private $controller;
+ /** @var ITimeFactory */
+ private $oldFactory;
+
protected function setUp() {
parent::setUp();
$request = $this->createMock(IRequest::class);
$this->avatarService = $this->createMock(IAvatarService::class);
- $this->timeFactory = $this->createMocK(ITimeFactory::class);
- $this->timeFactory->expects($this->any())
+
+ $timeFactory = $this->createMocK(ITimeFactory::class);
+ $timeFactory->expects($this->any())
->method('getTime')
->willReturn(10000);
+ $this->oldFactory = \OC::$server->offsetGet(ITimeFactory::class);
+ \OC::$server->registerService(ITimeFactory::class, function() use ($timeFactory) {
+ return $timeFactory;
+ });
+
+ $this->controller = new AvatarsController('mail', $request, $this->avatarService, 'jane');
+ }
+
+ protected function tearDown() {
+ parent::tearDown();
- $this->controller = new AvatarsController('mail', $request, $this->avatarService, 'jane', $this->timeFactory);
+ \OC::$server->offsetUnset(ITimeFactory::class);
+ \OC::$server->offsetSet(ITimeFactory::class, $this->oldFactory);
}
public function testGetUrl() {
@@ -71,7 +83,7 @@ class AvatarControllerTest extends TestCase {
$resp = $this->controller->url($email);
$expected = new JSONResponse($avatar);
- $expected->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory);
+ $expected->cacheFor(7 * 24 * 60 * 60);
$this->assertEquals($expected, $resp);
}
@@ -85,7 +97,7 @@ class AvatarControllerTest extends TestCase {
$resp = $this->controller->url($email);
$expected = new JSONResponse([], Http::STATUS_NOT_FOUND);
- $expected->setCacheHeaders(24 * 60 * 60, $this->timeFactory);
+ $expected->cacheFor(24 * 60 * 60);
$this->assertEquals($expected, $resp);
}
@@ -100,7 +112,7 @@ class AvatarControllerTest extends TestCase {
$expected = new AvatarDownloadResponse('data');
$expected->addHeader('Content-Type', 'image/jpeg');
- $expected->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory);
+ $expected->cacheFor(7 * 24 * 60 * 60);
$this->assertEquals($expected, $resp);
}
diff --git a/tests/Controller/FoldersControllerTest.php b/tests/Controller/FoldersControllerTest.php
index 46d56e6b5..e3f49aaaa 100644
--- a/tests/Controller/FoldersControllerTest.php
+++ b/tests/Controller/FoldersControllerTest.php
@@ -27,10 +27,10 @@ use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\FoldersController;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Folder;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\IMAP\FolderStats;
use OCA\Mail\Service\AccountService;
use ChristophWurst\Nextcloud\Testing\TestCase;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use PHPUnit_Framework_MockObject_MockObject;
diff --git a/tests/Controller/LocalAttachmentsControllerTest.php b/tests/Controller/LocalAttachmentsControllerTest.php
index a3db84bd2..f3e4a2e1e 100644
--- a/tests/Controller/LocalAttachmentsControllerTest.php
+++ b/tests/Controller/LocalAttachmentsControllerTest.php
@@ -26,8 +26,8 @@ use OCA\Mail\Contracts\IAttachmentService;
use OCA\Mail\Controller\LocalAttachmentsController;
use OCA\Mail\Db\LocalAttachment;
use OCA\Mail\Exception\ClientException;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Service\Attachment\UploadedFile;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use PHPUnit_Framework_MockObject_MockObject;
diff --git a/tests/Controller/MessagesControllerTest.php b/tests/Controller/MessagesControllerTest.php
index d1e29e99a..dc6db2f88 100644
--- a/tests/Controller/MessagesControllerTest.php
+++ b/tests/Controller/MessagesControllerTest.php
@@ -100,8 +100,8 @@ class MessagesControllerTest extends TestCase {
/** @var MockObject|IURLGenerator */
private $urlGenerator;
- /** @var MockObject|ITimeFactory */
- private $timeFactory;
+ /** @var ITimeFactory */
+ private $oldFactory;
protected function setUp() {
parent::setUp();
@@ -118,7 +118,15 @@ class MessagesControllerTest extends TestCase {
$this->l10n = $this->createMock(IL10N::class);
$this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
+
+ $timeFactory = $this->createMocK(ITimeFactory::class);
+ $timeFactory->expects($this->any())
+ ->method('getTime')
+ ->willReturn(10000);
+ $this->oldFactory = \OC::$server->offsetGet(ITimeFactory::class);
+ \OC::$server->registerService(ITimeFactory::class, function() use ($timeFactory) {
+ return $timeFactory;
+ });
$this->controller = new MessagesController(
$this->appName,
@@ -131,8 +139,7 @@ class MessagesControllerTest extends TestCase {
$this->logger,
$this->l10n,
$this->mimeTypeDetector,
- $this->urlGenerator,
- $this->timeFactory
+ $this->urlGenerator
);
$this->account = $this->createMock(Account::class);
@@ -141,6 +148,13 @@ class MessagesControllerTest extends TestCase {
$this->attachment = $this->createMock(Attachment::class);
}
+ protected function tearDown() {
+ parent::tearDown();
+
+ \OC::$server->offsetUnset(ITimeFactory::class);
+ \OC::$server->offsetSet(ITimeFactory::class, $this->oldFactory);
+ }
+
public function testIndex() {
// TODO: write test
$this->markTestSkipped('todo');
@@ -170,11 +184,9 @@ class MessagesControllerTest extends TestCase {
->method('getMessage')
->with($this->account, $folderId, $messageId, true)
->willReturn($message);
- $this->timeFactory->method('getTime')->willReturn(1000);
$expectedResponse = new HtmlResponse('');
- $expectedResponse->setCacheHeaders(3600, $this->timeFactory);
- $expectedResponse->addHeader('Pragma', 'cache');
+ $expectedResponse->cacheFor(3600);
if (class_exists('\OCP\AppFramework\Http\ContentSecurityPolicy')) {
$policy = new ContentSecurityPolicy();
$policy->allowEvalScript(false);
diff --git a/tests/Controller/PreferencesControllerTest.php b/tests/Controller/PreferencesControllerTest.php
index 046d97e6e..d96de2355 100644
--- a/tests/Controller/PreferencesControllerTest.php
+++ b/tests/Controller/PreferencesControllerTest.php
@@ -26,8 +26,8 @@ namespace OCA\Mail\Tests\Controller;
use OCA\Mail\Contracts\IUserPreferences;
use OCA\Mail\Controller\PreferencesController;
-use OCA\Mail\Http\JSONResponse;
use ChristophWurst\Nextcloud\Testing\TestCase;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use PHPUnit_Framework_MockObject_MockObject;
diff --git a/tests/Http/Middleware/ErrorMiddlewareTest.php b/tests/Http/Middleware/ErrorMiddlewareTest.php
index 8f4a68d59..4eb382ca0 100644
--- a/tests/Http/Middleware/ErrorMiddlewareTest.php
+++ b/tests/Http/Middleware/ErrorMiddlewareTest.php
@@ -27,11 +27,11 @@ namespace OCA\Mail\Tests\Http\Middleware;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Exception\ServiceException;
-use OCA\Mail\Http\JSONResponse;
use OCA\Mail\Http\Middleware\ErrorMiddleware;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IConfig;
use OCP\ILogger;