FinishRememberedLoginCommandTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\FinishRememberedLoginCommand;
  9. use OC\User\Session;
  10. use OCP\IConfig;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. class FinishRememberedLoginCommandTest extends ALoginCommandTest {
  13. /** @var Session|MockObject */
  14. private $userSession;
  15. /** @var IConfig|MockObject */
  16. private $config;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->userSession = $this->createMock(Session::class);
  20. $this->config = $this->createMock(IConfig::class);
  21. $this->cmd = new FinishRememberedLoginCommand(
  22. $this->userSession,
  23. $this->config
  24. );
  25. }
  26. public function testProcessNotRememberedLogin(): void {
  27. $data = $this->getLoggedInLoginData();
  28. $data->setRememberLogin(false);
  29. $this->userSession->expects($this->never())
  30. ->method('createRememberMeToken');
  31. $result = $this->cmd->process($data);
  32. $this->assertTrue($result->isSuccess());
  33. }
  34. public function testProcess(): void {
  35. $data = $this->getLoggedInLoginData();
  36. $this->config->expects($this->once())
  37. ->method('getSystemValueBool')
  38. ->with('auto_logout', false)
  39. ->willReturn(false);
  40. $this->userSession->expects($this->once())
  41. ->method('createRememberMeToken')
  42. ->with($this->user);
  43. $result = $this->cmd->process($data);
  44. $this->assertTrue($result->isSuccess());
  45. }
  46. public function testProcessNotRemeberedLoginWithAutologout(): void {
  47. $data = $this->getLoggedInLoginData();
  48. $this->config->expects($this->once())
  49. ->method('getSystemValueBool')
  50. ->with('auto_logout', false)
  51. ->willReturn(true);
  52. $this->userSession->expects($this->never())
  53. ->method('createRememberMeToken');
  54. $result = $this->cmd->process($data);
  55. $this->assertTrue($result->isSuccess());
  56. }
  57. }