SetUserTimezoneCommandTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\SetUserTimezoneCommand;
  9. use OCP\IConfig;
  10. use OCP\ISession;
  11. use PHPUnit\Framework\MockObject\MockObject;
  12. class SetUserTimezoneCommandTest extends ALoginCommandTest {
  13. /** @var IConfig|MockObject */
  14. private $config;
  15. /** @var ISession|MockObject */
  16. private $session;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->config = $this->createMock(IConfig::class);
  20. $this->session = $this->createMock(ISession::class);
  21. $this->cmd = new SetUserTimezoneCommand(
  22. $this->config,
  23. $this->session
  24. );
  25. }
  26. public function testProcessNoTimezoneSet(): void {
  27. $data = $this->getLoggedInLoginData();
  28. $this->config->expects($this->never())
  29. ->method('setUserValue');
  30. $this->session->expects($this->never())
  31. ->method('set');
  32. $result = $this->cmd->process($data);
  33. $this->assertTrue($result->isSuccess());
  34. }
  35. public function testProcess(): void {
  36. $data = $this->getLoggedInLoginDataWithTimezone();
  37. $this->user->expects($this->once())
  38. ->method('getUID')
  39. ->willReturn($this->username);
  40. $this->config->expects($this->once())
  41. ->method('setUserValue')
  42. ->with(
  43. $this->username,
  44. 'core',
  45. 'timezone',
  46. $this->timezone
  47. );
  48. $this->session->expects($this->once())
  49. ->method('set')
  50. ->with(
  51. 'timezone',
  52. $this->timeZoneOffset
  53. );
  54. $result = $this->cmd->process($data);
  55. $this->assertTrue($result->isSuccess());
  56. }
  57. }