1
0

FinishRememberedLoginCommandTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. declare(strict_types=1);
  23. namespace Test\Authentication\Login;
  24. use OC\Authentication\Login\FinishRememberedLoginCommand;
  25. use OC\User\Session;
  26. use OCP\IConfig;
  27. use PHPUnit\Framework\MockObject\MockObject;
  28. class FinishRememberedLoginCommandTest extends ALoginCommandTest {
  29. /** @var Session|MockObject */
  30. private $userSession;
  31. /** @var IConfig|MockObject */
  32. private $config;
  33. protected function setUp(): void {
  34. parent::setUp();
  35. $this->userSession = $this->createMock(Session::class);
  36. $this->config = $this->createMock(IConfig::class);
  37. $this->cmd = new FinishRememberedLoginCommand(
  38. $this->userSession,
  39. $this->config
  40. );
  41. }
  42. public function testProcessNotRememberedLogin() {
  43. $data = $this->getLoggedInLoginData();
  44. $data->setRememberLogin(false);
  45. $this->userSession->expects($this->never())
  46. ->method('createRememberMeToken');
  47. $result = $this->cmd->process($data);
  48. $this->assertTrue($result->isSuccess());
  49. }
  50. public function testProcess() {
  51. $data = $this->getLoggedInLoginData();
  52. $this->config->expects($this->once())
  53. ->method('getSystemValueBool')
  54. ->with('auto_logout', false)
  55. ->willReturn(false);
  56. $this->userSession->expects($this->once())
  57. ->method('createRememberMeToken')
  58. ->with($this->user);
  59. $result = $this->cmd->process($data);
  60. $this->assertTrue($result->isSuccess());
  61. }
  62. public function testProcessNotRemeberedLoginWithAutologout() {
  63. $data = $this->getLoggedInLoginData();
  64. $this->config->expects($this->once())
  65. ->method('getSystemValueBool')
  66. ->with('auto_logout', false)
  67. ->willReturn(true);
  68. $this->userSession->expects($this->never())
  69. ->method('createRememberMeToken');
  70. $result = $this->cmd->process($data);
  71. $this->assertTrue($result->isSuccess());
  72. }
  73. }