1
0

ResetTokenBackgroundJobTest.php 2.5 KB

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