ResetTokenBackgroundJobTest.php 2.4 KB

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