ServerTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. *
  14. * @license GNU AGPL version 3 or any later version
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as
  18. * published by the Free Software Foundation, either version 3 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. */
  30. namespace OCA\Settings\Tests\Settings\Admin;
  31. use OC\Profile\ProfileManager;
  32. use OCA\Settings\Settings\Admin\Server;
  33. use OCP\AppFramework\Http\TemplateResponse;
  34. use OCP\AppFramework\Services\IInitialState;
  35. use OCP\AppFramework\Utility\ITimeFactory;
  36. use OCP\IAppConfig;
  37. use OCP\IConfig;
  38. use OCP\IDBConnection;
  39. use OCP\IL10N;
  40. use OCP\IUrlGenerator;
  41. use PHPUnit\Framework\MockObject\MockObject;
  42. use Test\TestCase;
  43. /**
  44. * @group DB
  45. */
  46. class ServerTest extends TestCase {
  47. /** @var Server */
  48. private $admin;
  49. /** @var IDBConnection */
  50. private $connection;
  51. /** @var IInitialState */
  52. private $initialStateService;
  53. /** @var ProfileManager */
  54. private $profileManager;
  55. /** @var ITimeFactory|MockObject */
  56. private $timeFactory;
  57. /** @var IConfig|MockObject */
  58. private $config;
  59. /** @var IAppConfig|MockObject */
  60. private $appConfig;
  61. /** @var IL10N|MockObject */
  62. private $l10n;
  63. /** @var IUrlGenerator|MockObject */
  64. private $urlGenerator;
  65. protected function setUp(): void {
  66. parent::setUp();
  67. $this->connection = \OC::$server->getDatabaseConnection();
  68. $this->initialStateService = $this->createMock(IInitialState::class);
  69. $this->profileManager = $this->createMock(ProfileManager::class);
  70. $this->timeFactory = $this->createMock(ITimeFactory::class);
  71. $this->config = $this->createMock(IConfig::class);
  72. $this->appConfig = $this->createMock(IAppConfig::class);
  73. $this->l10n = $this->createMock(IL10N::class);
  74. $this->urlGenerator = $this->createMock(IUrlGenerator::class);
  75. $this->admin = $this->getMockBuilder(Server::class)
  76. ->onlyMethods(['cronMaxAge'])
  77. ->setConstructorArgs([
  78. $this->connection,
  79. $this->initialStateService,
  80. $this->profileManager,
  81. $this->timeFactory,
  82. $this->urlGenerator,
  83. $this->config,
  84. $this->appConfig,
  85. $this->l10n,
  86. ])
  87. ->getMock();
  88. }
  89. public function testGetForm(): void {
  90. $this->admin->expects($this->once())
  91. ->method('cronMaxAge')
  92. ->willReturn(1337);
  93. $this->config
  94. ->expects($this->any())
  95. ->method('getAppValue')
  96. ->willReturnMap([
  97. ['core', 'backgroundjobs_mode', 'ajax', 'ajax'],
  98. ['core', 'lastcron', '0', '0'],
  99. ['core', 'cronErrors', ''],
  100. ]);
  101. $this->profileManager
  102. ->expects($this->exactly(2))
  103. ->method('isProfileEnabled')
  104. ->willReturn(true);
  105. $expected = new TemplateResponse(
  106. 'settings',
  107. 'settings/admin/server',
  108. [
  109. 'profileEnabledGlobally' => true,
  110. ],
  111. ''
  112. );
  113. $this->assertEquals($expected, $this->admin->getForm());
  114. }
  115. public function testGetSection(): void {
  116. $this->assertSame('server', $this->admin->getSection());
  117. }
  118. public function testGetPriority(): void {
  119. $this->assertSame(0, $this->admin->getPriority());
  120. }
  121. }