1
0

SetUserTimezoneCommandTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\SetUserTimezoneCommand;
  25. use OCP\IConfig;
  26. use OCP\ISession;
  27. use PHPUnit\Framework\MockObject\MockObject;
  28. class SetUserTimezoneCommandTest extends ALoginCommandTest {
  29. /** @var IConfig|MockObject */
  30. private $config;
  31. /** @var ISession|MockObject */
  32. private $session;
  33. protected function setUp(): void {
  34. parent::setUp();
  35. $this->config = $this->createMock(IConfig::class);
  36. $this->session = $this->createMock(ISession::class);
  37. $this->cmd = new SetUserTimezoneCommand(
  38. $this->config,
  39. $this->session
  40. );
  41. }
  42. public function testProcessNoTimezoneSet() {
  43. $data = $this->getLoggedInLoginData();
  44. $this->config->expects($this->never())
  45. ->method('setUserValue');
  46. $this->session->expects($this->never())
  47. ->method('set');
  48. $result = $this->cmd->process($data);
  49. $this->assertTrue($result->isSuccess());
  50. }
  51. public function testProcess() {
  52. $data = $this->getLoggedInLoginDataWithTimezone();
  53. $this->user->expects($this->once())
  54. ->method('getUID')
  55. ->willReturn($this->username);
  56. $this->config->expects($this->once())
  57. ->method('setUserValue')
  58. ->with(
  59. $this->username,
  60. 'core',
  61. 'timezone',
  62. $this->timezone
  63. );
  64. $this->session->expects($this->once())
  65. ->method('set')
  66. ->with(
  67. 'timezone',
  68. $this->timeZoneOffset
  69. );
  70. $result = $this->cmd->process($data);
  71. $this->assertTrue($result->isSuccess());
  72. }
  73. }