aboutsummaryrefslogtreecommitdiffstats
path: root/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php')
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php78
1 files changed, 36 insertions, 42 deletions
diff --git a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php
index a14712e2684..87bc65e4309 100644
--- a/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/BackgroundJob/CheckBackupCodeTest.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @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: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\TwoFactorBackupCodes\Tests\Unit\BackgroundJob;
@@ -38,24 +20,12 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class CheckBackupCodeTest extends TestCase {
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var IJobList|MockObject */
- private $jobList;
-
- /** @var IRegistry|MockObject */
- private $registry;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var IUser|MockObject */
- private $user;
-
- /** @var CheckBackupCodes */
- private $checkBackupCodes;
+ private IUserManager&MockObject $userManager;
+ private IJobList&MockObject $jobList;
+ private IRegistry&MockObject $registry;
+ private Manager&MockObject $manager;
+ private IUser&MockObject $user;
+ private CheckBackupCodes $checkBackupCodes;
protected function setUp(): void {
parent::setUp();
@@ -68,7 +38,7 @@ class CheckBackupCodeTest extends TestCase {
$this->user = $this->createMock(IUser::class);
$this->userManager->method('callForSeenUsers')
- ->willReturnCallback(function (\Closure $e) {
+ ->willReturnCallback(function (\Closure $e): void {
$e($this->user);
});
@@ -81,7 +51,10 @@ class CheckBackupCodeTest extends TestCase {
);
}
- public function testRunAlreadyGenerated() {
+ public function testRunAlreadyGenerated(): void {
+ $this->user->method('isEnabled')
+ ->willReturn(true);
+
$this->registry->method('getProviderStates')
->with($this->user)
->willReturn(['backup_codes' => true]);
@@ -94,9 +67,11 @@ class CheckBackupCodeTest extends TestCase {
$this->invokePrivate($this->checkBackupCodes, 'run', [[]]);
}
- public function testRun() {
+ public function testRun(): void {
$this->user->method('getUID')
->willReturn('myUID');
+ $this->user->method('isEnabled')
+ ->willReturn(true);
$this->registry->expects($this->once())
->method('getProviderStates')
@@ -117,7 +92,26 @@ class CheckBackupCodeTest extends TestCase {
$this->invokePrivate($this->checkBackupCodes, 'run', [[]]);
}
- public function testRunNoProviders() {
+ public function testRunDisabledUser(): void {
+ $this->user->method('getUID')
+ ->willReturn('myUID');
+ $this->user->method('isEnabled')
+ ->willReturn(false);
+
+ $this->registry->expects($this->never())
+ ->method('getProviderStates')
+ ->with($this->user);
+
+ $this->jobList->expects($this->never())
+ ->method('add');
+
+ $this->invokePrivate($this->checkBackupCodes, 'run', [[]]);
+ }
+
+ public function testRunNoProviders(): void {
+ $this->user->method('isEnabled')
+ ->willReturn(true);
+
$this->registry->expects($this->once())
->method('getProviderStates')
->with($this->user)