diff options
author | Anna Larch <anna@nextcloud.com> | 2021-07-07 12:45:00 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2021-07-12 16:03:34 +0300 |
commit | 6d44305d0f1133f15d2b7fabad1a5919d4b43546 (patch) | |
tree | 820954e99f3377e1ec785b8877a7e5214e4a1cff /tests | |
parent | 4ecb5a1f060a5a8f25722d0676f8b67b005cbbd6 (diff) |
Move userId to controller
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/Service/AvatarServiceIntegrationTest.php | 3 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 10 | ||||
-rw-r--r-- | tests/Unit/Controller/PreferencesControllerTest.php | 8 | ||||
-rw-r--r-- | tests/Unit/Listener/AddressCollectionListenerTest.php | 15 | ||||
-rw-r--r-- | tests/Unit/Service/AvatarServiceTest.php | 28 | ||||
-rw-r--r-- | tests/Unit/Service/UserPreferenceServiceTest.php | 10 |
6 files changed, 49 insertions, 25 deletions
diff --git a/tests/Integration/Service/AvatarServiceIntegrationTest.php b/tests/Integration/Service/AvatarServiceIntegrationTest.php index 93d042712..ee8fe4b58 100644 --- a/tests/Integration/Service/AvatarServiceIntegrationTest.php +++ b/tests/Integration/Service/AvatarServiceIntegrationTest.php @@ -24,6 +24,7 @@ namespace OCA\Mail\Tests\Integration\Service; +use ChristophWurst\Nextcloud\Testing\TestUser; use OC; use OCA\Mail\Contracts\IAvatarService; use ChristophWurst\Nextcloud\Testing\TestCase; @@ -31,10 +32,12 @@ use OCP\ICache; use OCP\ICacheFactory; class AvatarServiceIntegrationTest extends TestCase { + use TestUser; /** @var IAvatarService */ private $service; + private function clearCache() { /* @var $cacheFactory ICacheFactory */ $cacheFactory = OC::$server->query(ICacheFactory::class); diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index 0d9b95015..ea075c71b 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -129,11 +129,11 @@ class PageControllerTest extends TestCase { $this->preferences->expects($this->exactly(5)) ->method('getPreference') ->willReturnMap([ - ['account-settings', '[]', json_encode([])], - ['external-avatars', 'true', 'true'], - ['reply-mode', 'top', 'bottom'], - ['collect-data', 'true', 'true'], - ['tag-classified-messages', 'true', 'true'], + [$this->userId, 'account-settings', '[]', json_encode([])], + [$this->userId, 'external-avatars', 'true', 'true'], + [$this->userId, 'reply-mode', 'top', 'bottom'], + [$this->userId, 'collect-data', 'true', 'true'], + [$this->userId, 'tag-classified-messages', 'true', 'true'], ]); $this->accountService->expects($this->once()) ->method('findByUserId') diff --git a/tests/Unit/Controller/PreferencesControllerTest.php b/tests/Unit/Controller/PreferencesControllerTest.php index ec60ffa91..97aa1ac22 100644 --- a/tests/Unit/Controller/PreferencesControllerTest.php +++ b/tests/Unit/Controller/PreferencesControllerTest.php @@ -45,13 +45,13 @@ class PreferencesControllerTest extends TestCase { $request = $this->createMock(IRequest::class); $this->preferences = $this->createMock(IUserPreferences::class); - $this->controller = new PreferencesController($request, $this->preferences); + $this->controller = new PreferencesController($request, $this->preferences, 'george'); } public function testGetPreference() { $this->preferences->expects($this->once()) ->method('getPreference') - ->with('test') + ->with('george', 'test') ->willReturn(123); $expected = new JSONResponse(['value' => 123]); @@ -63,8 +63,8 @@ class PreferencesControllerTest extends TestCase { public function testSetPreference() { $this->preferences->expects($this->once()) ->method('setPreference') - ->with('test') - ->willReturnArgument(1); + ->with('george', 'test') + ->willReturnArgument(2); $expected = new JSONResponse([ 'value' => 123, ]); diff --git a/tests/Unit/Listener/AddressCollectionListenerTest.php b/tests/Unit/Listener/AddressCollectionListenerTest.php index df3814fc0..c3c4f34d9 100644 --- a/tests/Unit/Listener/AddressCollectionListenerTest.php +++ b/tests/Unit/Listener/AddressCollectionListenerTest.php @@ -82,10 +82,15 @@ class AddressCollectionListenerTest extends TestCase { } public function testHandleOptOut() { - $event = $this->createMock(MessageSentEvent::class); + $account = $this->createConfiguredMock(Account::class, [ + 'getUserId' => 'test' + ]); + $event = $this->createConfiguredMock(MessageSentEvent::class, [ + 'getAccount' => $account + ]); $this->preferences->expects($this->once()) ->method('getPreference') - ->with('collect-data', 'true') + ->with('test', 'collect-data', 'true') ->willReturn('false'); $this->addressCollector->expects($this->never()) ->method('addAddresses'); @@ -95,7 +100,9 @@ class AddressCollectionListenerTest extends TestCase { public function testHandle() { /** @var Account|MockObject $account */ - $account = $this->createMock(Account::class); + $account = $this->createConfiguredMock(Account::class, [ + 'getUserId' => 'test' + ]); /** @var NewMessageData|MockObject $newMessageData */ $newMessageData = $this->createMock(NewMessageData::class); /** @var RepliedMessageData|MockObject $repliedMessageData */ @@ -104,7 +111,7 @@ class AddressCollectionListenerTest extends TestCase { $message = $this->createMock(IMessage::class); $this->preferences->expects($this->once()) ->method('getPreference') - ->with('collect-data', 'true') + ->with('test','collect-data', 'true') ->willReturn('true'); /** @var Horde_Mime_Mail|MockObject $mail */ $mail = $this->createMock(Horde_Mime_Mail::class); diff --git a/tests/Unit/Service/AvatarServiceTest.php b/tests/Unit/Service/AvatarServiceTest.php index 4d0c5162d..9c1551acc 100644 --- a/tests/Unit/Service/AvatarServiceTest.php +++ b/tests/Unit/Service/AvatarServiceTest.php @@ -36,6 +36,7 @@ use OCA\Mail\Service\Avatar\IAvatarSource; use OCA\Mail\Service\AvatarService; use ChristophWurst\Nextcloud\Testing\TestCase; use OCP\IURLGenerator; +use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; class AvatarServiceTest extends TestCase { @@ -62,6 +63,9 @@ class AvatarServiceTest extends TestCase { /** @var AvatarService */ private $avatarService; + /** @var IUser|MockObject */ + private $user; + protected function setUp(): void { parent::setUp(); @@ -71,9 +75,19 @@ class AvatarServiceTest extends TestCase { $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->avatarFactory = $this->createMock(AvatarFactory::class); $this->preferences = $this->createMock(IUserPreferences::class); - - $this->avatarService = new AvatarService($this->source, $this->downloader, - $this->cache, $this->urlGenerator, $this->avatarFactory, $this->preferences); + $this->user = $this->createConfiguredMock(IUser::class, [ + 'getUID' => 'test' + ]); + + $this->avatarService = new AvatarService( + $this->source, + $this->downloader, + $this->cache, + $this->urlGenerator, + $this->avatarFactory, + $this->preferences, + $this->user + ); } public function testGetCachedAvatarUrl() { @@ -95,7 +109,7 @@ class AvatarServiceTest extends TestCase { $uid = 'john'; $this->preferences->expects($this->once()) ->method('getPreference') - ->with('external-avatars', 'true') + ->with($uid, 'external-avatars', 'true') ->willReturn('true'); $this->cache->expects($this->once()) ->method('get') @@ -119,7 +133,7 @@ class AvatarServiceTest extends TestCase { $uid = 'john'; $this->preferences->expects($this->once()) ->method('getPreference') - ->with('external-avatars', 'true') + ->with($uid, 'external-avatars', 'true') ->willReturn('true'); $this->cache->expects($this->once()) ->method('get') @@ -145,7 +159,7 @@ class AvatarServiceTest extends TestCase { $avatar = new Avatar('https://doe.com/favicon.ico', 'image/png'); $this->preferences->expects($this->once()) ->method('getPreference') - ->with('external-avatars', 'true') + ->with($uid, 'external-avatars', 'true') ->willReturn('false'); $this->cache->expects($this->once()) ->method('get') @@ -170,7 +184,7 @@ class AvatarServiceTest extends TestCase { $avatar = new Avatar('https://doe.com/favicon.ico', 'image/png'); $this->preferences->expects($this->once()) ->method('getPreference') - ->with('external-avatars', 'true') + ->with($uid, 'external-avatars', 'true') ->willReturn('true'); $this->cache->expects($this->once()) ->method('get') diff --git a/tests/Unit/Service/UserPreferenceServiceTest.php b/tests/Unit/Service/UserPreferenceServiceTest.php index 1b1d6434b..d2d5f1255 100644 --- a/tests/Unit/Service/UserPreferenceServiceTest.php +++ b/tests/Unit/Service/UserPreferenceServiceTest.php @@ -24,7 +24,7 @@ namespace OCA\Mail\Tests\Unit\Service; -use OCA\Mail\Service\UserPreferenceSevice; +use OCA\Mail\Service\UserPreferenceService; use ChristophWurst\Nextcloud\Testing\TestCase; use OCP\IConfig; @@ -36,14 +36,14 @@ class UserPreferenceServiceTest extends TestCase { /** @var string */ private $userId = 'claire'; - /** @var UserPreferenceSevice */ + /** @var UserPreferenceService */ private $service; protected function setUp(): void { parent::setUp(); $this->config = $this->createMock(IConfig::class); - $this->service = new UserPreferenceSevice($this->config, $this->userId); + $this->service = new UserPreferenceService($this->config, $this->userId); } public function testGetPreference() { @@ -53,7 +53,7 @@ class UserPreferenceServiceTest extends TestCase { ->willReturn('123'); $expected = '123'; - $actual = $this->service->getPreference('test'); + $actual = $this->service->getPreference($this->userId, 'test'); $this->assertEquals($expected, $actual); } @@ -64,6 +64,6 @@ class UserPreferenceServiceTest extends TestCase { ->with($this->userId, 'mail', 'test', '123') ->willReturn('123'); - $this->service->setPreference('test', '123'); + $this->service->setPreference($this->userId, 'test', '123'); } } |