ALoginCommandTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\ALoginCommand;
  9. use OC\Authentication\Login\LoginData;
  10. use OCP\IRequest;
  11. use OCP\IUser;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. use Test\TestCase;
  14. abstract class ALoginCommandTest extends TestCase {
  15. /** @var IRequest|MockObject */
  16. protected $request;
  17. /** @var string */
  18. protected $username = 'user123';
  19. /** @var string */
  20. protected $password = '123456';
  21. /** @var string */
  22. protected $redirectUrl = '/apps/contacts';
  23. /** @var string */
  24. protected $timezone = 'Europe/Vienna';
  25. protected $timeZoneOffset = '2';
  26. /** @var IUser|MockObject */
  27. protected $user;
  28. /** @var ALoginCommand */
  29. protected $cmd;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->request = $this->createMock(IRequest::class);
  33. $this->user = $this->createMock(IUser::class);
  34. }
  35. protected function getBasicLoginData(): LoginData {
  36. return new LoginData(
  37. $this->request,
  38. $this->username,
  39. $this->password
  40. );
  41. }
  42. protected function getInvalidLoginData(): LoginData {
  43. return new LoginData(
  44. $this->request,
  45. $this->username,
  46. $this->password
  47. );
  48. }
  49. protected function getFailedLoginData(): LoginData {
  50. $data = new LoginData(
  51. $this->request,
  52. $this->username,
  53. $this->password
  54. );
  55. $data->setUser(false);
  56. return $data;
  57. }
  58. protected function getLoggedInLoginData(): LoginData {
  59. $basic = $this->getBasicLoginData();
  60. $basic->setUser($this->user);
  61. return $basic;
  62. }
  63. protected function getLoggedInLoginDataWithRedirectUrl(): LoginData {
  64. $data = new LoginData(
  65. $this->request,
  66. $this->username,
  67. $this->password,
  68. $this->redirectUrl
  69. );
  70. $data->setUser($this->user);
  71. return $data;
  72. }
  73. protected function getLoggedInLoginDataWithTimezone(): LoginData {
  74. $data = new LoginData(
  75. $this->request,
  76. $this->username,
  77. $this->password,
  78. null,
  79. $this->timezone,
  80. $this->timeZoneOffset
  81. );
  82. $data->setUser($this->user);
  83. return $data;
  84. }
  85. }