LoggedInCheckCommandTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. declare(strict_types=1);
  7. namespace Test\Authentication\Login;
  8. use OC\Authentication\Login\LoggedInCheckCommand;
  9. use OC\Core\Controller\LoginController;
  10. use OCP\EventDispatcher\IEventDispatcher;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. use Psr\Log\LoggerInterface;
  13. class LoggedInCheckCommandTest extends ALoginCommandTest {
  14. /** @var LoggerInterface|MockObject */
  15. private $logger;
  16. /** @var IEventDispatcher|MockObject */
  17. private $dispatcher;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->logger = $this->createMock(LoggerInterface::class);
  21. $this->dispatcher = $this->createMock(IEventDispatcher::class);
  22. $this->cmd = new LoggedInCheckCommand(
  23. $this->logger,
  24. $this->dispatcher
  25. );
  26. }
  27. public function testProcessSuccessfulLogin(): void {
  28. $data = $this->getLoggedInLoginData();
  29. $result = $this->cmd->process($data);
  30. $this->assertTrue($result->isSuccess());
  31. }
  32. public function testProcessFailedLogin(): void {
  33. $data = $this->getFailedLoginData();
  34. $this->logger->expects($this->once())
  35. ->method('warning');
  36. $result = $this->cmd->process($data);
  37. $this->assertFalse($result->isSuccess());
  38. $this->assertSame(LoginController::LOGIN_MSG_INVALIDPASSWORD, $result->getErrorMessage());
  39. }
  40. }