ServerTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Tests\Settings\Admin;
  8. use OC\Profile\ProfileManager;
  9. use OCA\Settings\Settings\Admin\Server;
  10. use OCP\AppFramework\Http\TemplateResponse;
  11. use OCP\AppFramework\Services\IInitialState;
  12. use OCP\AppFramework\Utility\ITimeFactory;
  13. use OCP\IAppConfig;
  14. use OCP\IConfig;
  15. use OCP\IDBConnection;
  16. use OCP\IL10N;
  17. use OCP\IUrlGenerator;
  18. use PHPUnit\Framework\MockObject\MockObject;
  19. use Test\TestCase;
  20. /**
  21. * @group DB
  22. */
  23. class ServerTest extends TestCase {
  24. /** @var IDBConnection */
  25. private $connection;
  26. /** @var Server&MockObject */
  27. private $admin;
  28. /** @var IInitialState&MockObject */
  29. private $initialStateService;
  30. /** @var ProfileManager&MockObject */
  31. private $profileManager;
  32. /** @var ITimeFactory&MockObject */
  33. private $timeFactory;
  34. /** @var IConfig&MockObject */
  35. private $config;
  36. /** @var IAppConfig&MockObject */
  37. private $appConfig;
  38. /** @var IL10N&MockObject */
  39. private $l10n;
  40. /** @var IUrlGenerator&MockObject */
  41. private $urlGenerator;
  42. protected function setUp(): void {
  43. parent::setUp();
  44. $this->connection = \OC::$server->getDatabaseConnection();
  45. $this->initialStateService = $this->createMock(IInitialState::class);
  46. $this->profileManager = $this->createMock(ProfileManager::class);
  47. $this->timeFactory = $this->createMock(ITimeFactory::class);
  48. $this->config = $this->createMock(IConfig::class);
  49. $this->appConfig = $this->createMock(IAppConfig::class);
  50. $this->l10n = $this->createMock(IL10N::class);
  51. $this->urlGenerator = $this->createMock(IUrlGenerator::class);
  52. $this->admin = $this->getMockBuilder(Server::class)
  53. ->onlyMethods(['cronMaxAge'])
  54. ->setConstructorArgs([
  55. $this->connection,
  56. $this->initialStateService,
  57. $this->profileManager,
  58. $this->timeFactory,
  59. $this->urlGenerator,
  60. $this->config,
  61. $this->appConfig,
  62. $this->l10n,
  63. ])
  64. ->getMock();
  65. }
  66. public function testGetForm(): void {
  67. $this->admin->expects($this->once())
  68. ->method('cronMaxAge')
  69. ->willReturn(1337);
  70. $this->config
  71. ->expects($this->any())
  72. ->method('getAppValue')
  73. ->willReturnMap([
  74. ['core', 'lastcron', '0', '0'],
  75. ['core', 'cronErrors', ''],
  76. ]);
  77. $this->appConfig
  78. ->expects($this->any())
  79. ->method('getValueString')
  80. ->with('core', 'backgroundjobs_mode', 'ajax')
  81. ->willReturn('ajax');
  82. $this->profileManager
  83. ->expects($this->exactly(2))
  84. ->method('isProfileEnabled')
  85. ->willReturn(true);
  86. $expected = new TemplateResponse(
  87. 'settings',
  88. 'settings/admin/server',
  89. [
  90. 'profileEnabledGlobally' => true,
  91. ],
  92. ''
  93. );
  94. $this->assertEquals($expected, $this->admin->getForm());
  95. }
  96. public function testGetSection(): void {
  97. $this->assertSame('server', $this->admin->getSection());
  98. }
  99. public function testGetPriority(): void {
  100. $this->assertSame(0, $this->admin->getPriority());
  101. }
  102. }