UserDisabledCheckCommandTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\UserDisabledCheckCommand;
  9. use OC\Core\Controller\LoginController;
  10. use OCP\IUserManager;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. use Psr\Log\LoggerInterface;
  13. class UserDisabledCheckCommandTest extends ALoginCommandTest {
  14. /** @var IUserManager|MockObject */
  15. private $userManager;
  16. /** @var LoggerInterface|MockObject */
  17. private $logger;
  18. protected function setUp(): void {
  19. parent::setUp();
  20. $this->userManager = $this->createMock(IUserManager::class);
  21. $this->logger = $this->createMock(LoggerInterface::class);
  22. $this->cmd = new UserDisabledCheckCommand(
  23. $this->userManager,
  24. $this->logger
  25. );
  26. }
  27. public function testProcessNonExistingUser() {
  28. $data = $this->getBasicLoginData();
  29. $this->userManager->expects($this->once())
  30. ->method('get')
  31. ->with($this->username)
  32. ->willReturn(null);
  33. $result = $this->cmd->process($data);
  34. $this->assertTrue($result->isSuccess());
  35. }
  36. public function testProcessDisabledUser() {
  37. $data = $this->getBasicLoginData();
  38. $this->userManager->expects($this->once())
  39. ->method('get')
  40. ->with($this->username)
  41. ->willReturn($this->user);
  42. $this->user->expects($this->once())
  43. ->method('isEnabled')
  44. ->willReturn(false);
  45. $result = $this->cmd->process($data);
  46. $this->assertFalse($result->isSuccess());
  47. $this->assertSame(LoginController::LOGIN_MSG_USERDISABLED, $result->getErrorMessage());
  48. }
  49. public function testProcess() {
  50. $data = $this->getBasicLoginData();
  51. $this->userManager->expects($this->once())
  52. ->method('get')
  53. ->with($this->username)
  54. ->willReturn($this->user);
  55. $this->user->expects($this->once())
  56. ->method('isEnabled')
  57. ->willReturn(true);
  58. $result = $this->cmd->process($data);
  59. $this->assertTrue($result->isSuccess());
  60. }
  61. }