ResetTokenBackgroundJobTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\UpdateNotification\Tests;
  27. use OCA\UpdateNotification\ResetTokenBackgroundJob;
  28. use OCP\AppFramework\Utility\ITimeFactory;
  29. use OCP\IConfig;
  30. use Test\TestCase;
  31. class ResetTokenBackgroundJobTest extends TestCase {
  32. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  33. private $config;
  34. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  35. private $timeFactory;
  36. /** @var ResetTokenBackgroundJob */
  37. private $resetTokenBackgroundJob;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->config = $this->createMock(IConfig::class);
  41. $this->timeFactory = $this->createMock(ITimeFactory::class);
  42. $this->resetTokenBackgroundJob = new ResetTokenBackgroundJob($this->config, $this->timeFactory);
  43. }
  44. public function testRunWithNotExpiredToken() {
  45. $this->timeFactory
  46. ->expects($this->atLeastOnce())
  47. ->method('getTime')
  48. ->willReturn(123);
  49. $this->config
  50. ->expects($this->once())
  51. ->method('getAppValue')
  52. ->with('core', 'updater.secret.created', 123);
  53. $this->config
  54. ->expects($this->never())
  55. ->method('deleteSystemValue');
  56. static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
  57. }
  58. public function testRunWithExpiredToken() {
  59. $this->timeFactory
  60. ->expects($this->at(0))
  61. ->method('getTime')
  62. ->willReturn(1455131633);
  63. $this->timeFactory
  64. ->expects($this->at(1))
  65. ->method('getTime')
  66. ->willReturn(1455045234);
  67. $this->config
  68. ->expects($this->once())
  69. ->method('getAppValue')
  70. ->with('core', 'updater.secret.created', 1455045234);
  71. $this->config
  72. ->expects($this->once())
  73. ->method('deleteSystemValue')
  74. ->with('updater.secret');
  75. static::invokePrivate($this->resetTokenBackgroundJob, 'run', [null]);
  76. }
  77. }