CleanupTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Core\Command\TwoFactorAuth;
  8. use OC\Core\Command\TwoFactorAuth\Cleanup;
  9. use OCP\Authentication\TwoFactorAuth\IRegistry;
  10. use OCP\IUserManager;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use Test\TestCase;
  14. class CleanupTest extends TestCase {
  15. /** @var IRegistry|MockObject */
  16. private $registry;
  17. /** @var IUserManager|MockObject */
  18. private $userManager;
  19. /** @var CommandTester */
  20. private $cmd;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $this->registry = $this->createMock(IRegistry::class);
  24. $this->userManager = $this->createMock(IUserManager::class);
  25. $cmd = new Cleanup($this->registry, $this->userManager);
  26. $this->cmd = new CommandTester($cmd);
  27. }
  28. public function testCleanup(): void {
  29. $this->registry->expects($this->once())
  30. ->method('cleanUp')
  31. ->with('u2f');
  32. $rc = $this->cmd->execute([
  33. 'provider-id' => 'u2f',
  34. ]);
  35. $this->assertEquals(0, $rc);
  36. $output = $this->cmd->getDisplay();
  37. $this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output);
  38. }
  39. }