aboutsummaryrefslogtreecommitdiffstats
path: root/tests/Core/Command/TwoFactorAuth/CleanupTest.php
blob: 1d4731ff0c2b8b9f268157fa55e6241fca9db77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace Core\Command\TwoFactorAuth;

use OC\Core\Command\TwoFactorAuth\Cleanup;
use OCP\Authentication\TwoFactorAuth\IRegistry;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;

class CleanupTest extends TestCase {
	/** @var IRegistry|MockObject */
	private $registry;

	/** @var IUserManager|MockObject */
	private $userManager;

	/** @var CommandTester */
	private $cmd;

	protected function setUp(): void {
		parent::setUp();

		$this->registry = $this->createMock(IRegistry::class);
		$this->userManager = $this->createMock(IUserManager::class);

		$cmd = new Cleanup($this->registry, $this->userManager);
		$this->cmd = new CommandTester($cmd);
	}

	public function testCleanup(): void {
		$this->registry->expects($this->once())
			->method('cleanUp')
			->with('u2f');

		$rc = $this->cmd->execute([
			'provider-id' => 'u2f',
		]);

		$this->assertEquals(0, $rc);
		$output = $this->cmd->getDisplay();
		$this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output);
	}
}