diff options
author | Anna Larch <anna@nextcloud.com> | 2022-10-01 18:40:58 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2022-10-02 19:35:45 +0300 |
commit | f4fe3048beab88833cde8d9280dae482ffb62328 (patch) | |
tree | f5d790b4f163a83c6be55bd9e6d706dbbd23a2d7 /tests | |
parent | b5502a66ca2667f5dbed42ca826bcd669918b838 (diff) |
Add the option to disable the new account button
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Controller/AccountsControllerTest.php | 37 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 13 | ||||
-rw-r--r-- | tests/Unit/Settings/AdminSettingsTest.php | 9 |
3 files changed, 51 insertions, 8 deletions
diff --git a/tests/Unit/Controller/AccountsControllerTest.php b/tests/Unit/Controller/AccountsControllerTest.php index c5ba2e0b7..1fad762d5 100644 --- a/tests/Unit/Controller/AccountsControllerTest.php +++ b/tests/Unit/Controller/AccountsControllerTest.php @@ -38,6 +38,7 @@ use OCA\Mail\Service\Sync\SyncService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; +use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; @@ -100,6 +101,7 @@ class AccountsControllerTest extends TestCase { $this->setupService = $this->createMock(SetupService::class); $this->mailManager = $this->createMock(IMailManager::class); $this->syncService = $this->createMock(SyncService::class); + $this->config = $this->createMock(IConfig::class); $this->controller = new AccountsController( $this->appName, @@ -112,7 +114,8 @@ class AccountsControllerTest extends TestCase { $this->transmission, $this->setupService, $this->mailManager, - $this->syncService + $this->syncService, + $this->config ); $this->account = $this->createMock(Account::class); $this->accountId = 123; @@ -213,6 +216,9 @@ class AccountsControllerTest extends TestCase { } public function testCreateManualSuccess(): void { + $this->config->expects(self::once()) + ->method('getAppValue') + ->willReturn('yes'); $autoDetect = false; $email = 'user@domain.tld'; $accountName = 'Mail'; @@ -239,6 +245,35 @@ class AccountsControllerTest extends TestCase { self::assertEquals($expectedResponse, $response); } + public function testCreateManualNotAllowed(): void { + $autoDetect = false; + $email = 'user@domain.tld'; + $accountName = 'Mail'; + $imapHost = 'localhost'; + $imapPort = 993; + $imapSslMode = 'ssl'; + $imapUser = 'user@domain.tld'; + $imapPassword = 'mypassword'; + $smtpHost = 'localhost'; + $smtpPort = 465; + $smtpSslMode = 'none'; + $smtpUser = 'user@domain.tld'; + $smtpPassword = 'mypassword'; + $this->config->expects(self::once()) + ->method('getAppValue') + ->willReturn('no'); + $this->logger->expects(self::once()) + ->method('info'); + $this->setupService->expects(self::never()) + ->method('createNewAccount'); + + $expectedResponse = \OCA\Mail\Http\JsonResponse::error('Could not create account'); + $response = $this->controller->create($accountName, $email, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $autoDetect); + + self::assertEquals($expectedResponse, $response); + } + + public function testCreateManualFailure(): void { $autoDetect = false; $email = 'user@domain.tld'; diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php index a33542880..156a59b40 100644 --- a/tests/Unit/Controller/PageControllerTest.php +++ b/tests/Unit/Controller/PageControllerTest.php @@ -217,14 +217,16 @@ class PageControllerTest extends TestCase { ['debug', false, true], ['app.mail.attachment-size-limit', 0, 123], ]); - $this->config->expects($this->exactly(2)) + $this->config->expects($this->exactly(3)) ->method('getAppValue') ->withConsecutive( [ 'mail', 'installed_version' ], - ['core', 'backgroundjobs_mode', 'ajax' ] + ['core', 'backgroundjobs_mode', 'ajax' ], + ['mail', 'allow_new_mail_accounts', 'yes'] )->willReturnOnConsecutiveCalls( $this->returnValue('1.2.3'), - $this->returnValue('cron') + $this->returnValue('cron'), + $this->returnValue('yes') ); $user->expects($this->once()) ->method('getDisplayName') @@ -236,7 +238,7 @@ class PageControllerTest extends TestCase { ->with($this->equalTo('jane'), $this->equalTo('settings'), $this->equalTo('email'), $this->equalTo('')) ->will($this->returnValue('jane@doe.cz')); - $this->initialState->expects($this->exactly(8)) + $this->initialState->expects($this->exactly(9)) ->method('provideInitialState') ->withConsecutive( ['debug', true], @@ -246,7 +248,8 @@ class PageControllerTest extends TestCase { ['prefill_displayName', 'Jane Doe'], ['prefill_email', 'jane@doe.cz'], ['outbox-messages', []], - ['disable-scheduled-send', false] + ['disable-scheduled-send', false], + ['allow_new_mail_accounts', true] ); $expected = new TemplateResponse($this->appName, 'index', diff --git a/tests/Unit/Settings/AdminSettingsTest.php b/tests/Unit/Settings/AdminSettingsTest.php index fa97faaff..cad07025e 100644 --- a/tests/Unit/Settings/AdminSettingsTest.php +++ b/tests/Unit/Settings/AdminSettingsTest.php @@ -53,7 +53,7 @@ class AdminSettingsTest extends TestCase { } public function testGetForm() { - $this->serviceMock->getParameter('initialStateService')->expects($this->exactly(2)) + $this->serviceMock->getParameter('initialStateService')->expects($this->exactly(3)) ->method('provideInitialState') ->withConsecutive( [ @@ -65,7 +65,12 @@ class AdminSettingsTest extends TestCase { Application::APP_ID, 'antispam_setting', $this->anything() - ] + ], + [ + Application::APP_ID, + 'allow_new_mail_accounts', + $this->anything() + ], ); $expected = new TemplateResponse(Application::APP_ID, 'settings-admin'); |