UidLoginCommandTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\UidLoginCommand;
  9. use OC\User\Manager;
  10. use PHPUnit\Framework\MockObject\MockObject;
  11. class UidLoginCommandTest extends ALoginCommandTest {
  12. /** @var Manager|MockObject */
  13. private $userManager;
  14. protected function setUp(): void {
  15. parent::setUp();
  16. $this->userManager = $this->createMock(Manager::class);
  17. $this->cmd = new UidLoginCommand(
  18. $this->userManager
  19. );
  20. }
  21. public function testProcessFailingLogin() {
  22. $data = $this->getBasicLoginData();
  23. $this->userManager->expects($this->once())
  24. ->method('checkPasswordNoLogging')
  25. ->with(
  26. $this->username,
  27. $this->password
  28. )
  29. ->willReturn(false);
  30. $result = $this->cmd->process($data);
  31. $this->assertTrue($result->isSuccess());
  32. $this->assertFalse($data->getUser());
  33. }
  34. public function testProcess() {
  35. $data = $this->getBasicLoginData();
  36. $this->userManager->expects($this->once())
  37. ->method('checkPasswordNoLogging')
  38. ->with(
  39. $this->username,
  40. $this->password
  41. )
  42. ->willReturn($this->user);
  43. $result = $this->cmd->process($data);
  44. $this->assertTrue($result->isSuccess());
  45. $this->assertEquals($this->user, $data->getUser());
  46. }
  47. }