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
path: root/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-08-30 11:01:57 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2019-10-17 02:17:04 +0300
commit5f744699ca36aefa919668cb717ae15c045be89a (patch)
tree7a9864212574d12dfce761b267fad2abd3c125f5 /tests
parenta2adb6aad7d798b192738ca0fa757f8aa3f406c4 (diff)
Lets use the server methods for caching
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-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
9 files changed, 50 insertions, 26 deletions
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;