1
0

ALoginCommandTest.php 2.8 KB

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