diff options
Diffstat (limited to 'apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php')
-rw-r--r-- | apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php | 86 |
1 files changed, 34 insertions, 52 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php index bb4d7f662cb..512374fca8c 100644 --- a/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php +++ b/apps/twofactor_backupcodes/tests/Unit/Provider/BackupCodesProviderTest.php @@ -3,76 +3,58 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @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/>. - * + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\TwoFactorBackupCodes\Tests\Unit\Provider; use OC\App\AppManager; use OCA\TwoFactorBackupCodes\Provider\BackupCodesProvider; use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage; -use OCP\IInitialStateService; +use OCP\AppFramework\Services\IInitialState; use OCP\IL10N; use OCP\IUser; -use OCP\Template; +use OCP\Server; +use OCP\Template\ITemplateManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class BackupCodesProviderTest extends TestCase { + private string $appName; - /** @var string */ - private $appName; + private BackupCodeStorage&MockObject $storage; + private IL10N&MockObject $l10n; + private AppManager&MockObject $appManager; + private IInitialState&MockObject $initialState; - /** @var BackupCodeStorage|\PHPUnit\Framework\MockObject\MockObject */ - private $storage; - - /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ - private $l10n; - - /** @var AppManager|\PHPUnit\Framework\MockObject\MockObject */ - private $appManager; - - /** @var IInitialStateService|\PHPUnit\Framework\MockObject\MockObject */ - private $initialState; - - /** @var BackupCodesProvider */ - private $provider; + private ITemplateManager $templateManager; + private BackupCodesProvider $provider; protected function setUp(): void { parent::setUp(); - $this->appName = "twofactor_backupcodes"; + $this->appName = 'twofactor_backupcodes'; $this->storage = $this->createMock(BackupCodeStorage::class); $this->l10n = $this->createMock(IL10N::class); $this->appManager = $this->createMock(AppManager::class); - $this->initialState = $this->createMock(IInitialStateService::class); - - $this->provider = new BackupCodesProvider($this->appName, $this->storage, $this->l10n, $this->appManager, $this->initialState); + $this->initialState = $this->createMock(IInitialState::class); + $this->templateManager = Server::get(ITemplateManager::class); + + $this->provider = new BackupCodesProvider( + $this->appName, + $this->storage, + $this->l10n, + $this->appManager, + $this->initialState, + $this->templateManager, + ); } - public function testGetId() { + public function testGetId(): void { $this->assertEquals('backup_codes', $this->provider->getId()); } - public function testGetDisplayName() { + public function testGetDisplayName(): void { $this->l10n->expects($this->once()) ->method('t') ->with('Backup code') @@ -80,7 +62,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertSame('l10n backup code', $this->provider->getDisplayName()); } - public function testGetDescription() { + public function testGetDescription(): void { $this->l10n->expects($this->once()) ->method('t') ->with('Use backup code') @@ -88,14 +70,14 @@ class BackupCodesProviderTest extends TestCase { $this->assertSame('l10n use backup code', $this->provider->getDescription()); } - public function testGetTempalte() { + public function testGetTempalte(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); - $expected = new Template('twofactor_backupcodes', 'challenge'); + $expected = $this->templateManager->getTemplate('twofactor_backupcodes', 'challenge'); $this->assertEquals($expected, $this->provider->getTemplate($user)); } - public function testVerfiyChallenge() { + public function testVerfiyChallenge(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $challenge = 'xyz'; @@ -107,7 +89,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertFalse($this->provider->verifyChallenge($user, $challenge)); } - public function testIsTwoFactorEnabledForUser() { + public function testIsTwoFactorEnabledForUser(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->storage->expects($this->once()) @@ -118,7 +100,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertTrue($this->provider->isTwoFactorAuthEnabledForUser($user)); } - public function testIsActiveNoProviders() { + public function testIsActiveNoProviders(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->appManager->expects($this->once()) @@ -138,7 +120,7 @@ class BackupCodesProviderTest extends TestCase { $this->assertFalse($this->provider->isActive($user)); } - public function testIsActiveWithProviders() { + public function testIsActiveWithProviders(): void { $user = $this->getMockBuilder(IUser::class)->getMock(); $this->appManager->expects($this->once()) |