1
0

AdminControllerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\Controller;
  27. use OCA\UpdateNotification\Controller\AdminController;
  28. use OCA\UpdateNotification\ResetTokenBackgroundJob;
  29. use OCP\AppFramework\Http\DataResponse;
  30. use OCP\AppFramework\Utility\ITimeFactory;
  31. use OCP\BackgroundJob\IJobList;
  32. use OCP\IConfig;
  33. use OCP\IL10N;
  34. use OCP\IRequest;
  35. use OCP\Security\ISecureRandom;
  36. use Test\TestCase;
  37. class AdminControllerTest extends TestCase {
  38. /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
  39. private $request;
  40. /** @var IJobList|\PHPUnit\Framework\MockObject\MockObject */
  41. private $jobList;
  42. /** @var ISecureRandom|\PHPUnit\Framework\MockObject\MockObject */
  43. private $secureRandom;
  44. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  45. private $config;
  46. /** @var AdminController */
  47. private $adminController;
  48. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  49. private $timeFactory;
  50. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
  51. private $l10n;
  52. protected function setUp(): void {
  53. parent::setUp();
  54. $this->request = $this->createMock(IRequest::class);
  55. $this->jobList = $this->createMock(IJobList::class);
  56. $this->secureRandom = $this->createMock(ISecureRandom::class);
  57. $this->config = $this->createMock(IConfig::class);
  58. $this->timeFactory = $this->createMock(ITimeFactory::class);
  59. $this->l10n = $this->createMock(IL10N::class);
  60. $this->adminController = new AdminController(
  61. 'updatenotification',
  62. $this->request,
  63. $this->jobList,
  64. $this->secureRandom,
  65. $this->config,
  66. $this->timeFactory,
  67. $this->l10n
  68. );
  69. }
  70. public function testCreateCredentials() {
  71. $this->jobList
  72. ->expects($this->once())
  73. ->method('add')
  74. ->with(ResetTokenBackgroundJob::class);
  75. $this->secureRandom
  76. ->expects($this->once())
  77. ->method('generate')
  78. ->with(64)
  79. ->willReturn('MyGeneratedToken');
  80. $this->config
  81. ->expects($this->once())
  82. ->method('setSystemValue')
  83. ->with('updater.secret');
  84. $this->timeFactory
  85. ->expects($this->once())
  86. ->method('getTime')
  87. ->willReturn(12345);
  88. $this->config
  89. ->expects($this->once())
  90. ->method('setAppValue')
  91. ->with('core', 'updater.secret.created', 12345);
  92. $expected = new DataResponse('MyGeneratedToken');
  93. $this->assertEquals($expected, $this->adminController->createCredentials());
  94. }
  95. }