1
0

AdminControllerTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\UpdateNotification\Tests\Controller;
  8. use OCA\UpdateNotification\BackgroundJob\ResetToken;
  9. use OCA\UpdateNotification\Controller\AdminController;
  10. use OCP\AppFramework\Http\DataResponse;
  11. use OCP\AppFramework\Utility\ITimeFactory;
  12. use OCP\BackgroundJob\IJobList;
  13. use OCP\IAppConfig;
  14. use OCP\IConfig;
  15. use OCP\IL10N;
  16. use OCP\IRequest;
  17. use OCP\Security\ISecureRandom;
  18. use PHPUnit\Framework\MockObject\MockObject;
  19. use Test\TestCase;
  20. class AdminControllerTest extends TestCase {
  21. private IRequest|MockObject $request;
  22. private IJobList|MockObject $jobList;
  23. private ISecureRandom|MockObject $secureRandom;
  24. private IConfig|MockObject $config;
  25. private ITimeFactory|MockObject $timeFactory;
  26. private IL10N|MockObject $l10n;
  27. private IAppConfig|MockObject $appConfig;
  28. private AdminController $adminController;
  29. protected function setUp(): void {
  30. parent::setUp();
  31. $this->request = $this->createMock(IRequest::class);
  32. $this->jobList = $this->createMock(IJobList::class);
  33. $this->secureRandom = $this->createMock(ISecureRandom::class);
  34. $this->config = $this->createMock(IConfig::class);
  35. $this->appConfig = $this->createMock(IAppConfig::class);
  36. $this->timeFactory = $this->createMock(ITimeFactory::class);
  37. $this->l10n = $this->createMock(IL10N::class);
  38. $this->adminController = new AdminController(
  39. 'updatenotification',
  40. $this->request,
  41. $this->jobList,
  42. $this->secureRandom,
  43. $this->config,
  44. $this->appConfig,
  45. $this->timeFactory,
  46. $this->l10n
  47. );
  48. }
  49. public function testCreateCredentials(): void {
  50. $this->jobList
  51. ->expects($this->once())
  52. ->method('add')
  53. ->with(ResetToken::class);
  54. $this->secureRandom
  55. ->expects($this->once())
  56. ->method('generate')
  57. ->with(64)
  58. ->willReturn('MyGeneratedToken');
  59. $this->config
  60. ->expects($this->once())
  61. ->method('setSystemValue')
  62. ->with('updater.secret');
  63. $this->timeFactory
  64. ->expects($this->once())
  65. ->method('getTime')
  66. ->willReturn(12345);
  67. $this->appConfig
  68. ->expects($this->once())
  69. ->method('setValueInt')
  70. ->with('core', 'updater.secret.created', 12345);
  71. $expected = new DataResponse('MyGeneratedToken');
  72. $this->assertEquals($expected, $this->adminController->createCredentials());
  73. }
  74. }