1
0

ServerTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\IConfig;
  37. use OCP\IDBConnection;
  38. use OCP\IUrlGenerator;
  39. use OCP\IL10N;
  40. use PHPUnit\Framework\MockObject\MockObject;
  41. use Test\TestCase;
  42. /**
  43. * @group DB
  44. */
  45. class ServerTest extends TestCase {
  46. /** @var Server */
  47. private $admin;
  48. /** @var IDBConnection */
  49. private $connection;
  50. /** @var IInitialState */
  51. private $initialStateService;
  52. /** @var ProfileManager */
  53. private $profileManager;
  54. /** @var ITimeFactory|MockObject */
  55. private $timeFactory;
  56. /** @var IConfig|MockObject */
  57. private $config;
  58. /** @var IL10N|MockObject */
  59. private $l10n;
  60. /** @var IUrlGenerator|MockObject */
  61. private $urlGenerator;
  62. protected function setUp(): void {
  63. parent::setUp();
  64. $this->connection = \OC::$server->getDatabaseConnection();
  65. $this->initialStateService = $this->createMock(IInitialState::class);
  66. $this->profileManager = $this->createMock(ProfileManager::class);
  67. $this->timeFactory = $this->createMock(ITimeFactory::class);
  68. $this->config = $this->createMock(IConfig::class);
  69. $this->l10n = $this->createMock(IL10N::class);
  70. $this->urlGenerator = $this->createMock(IUrlGenerator::class);
  71. $this->admin = $this->getMockBuilder(Server::class)
  72. ->onlyMethods(['cronMaxAge'])
  73. ->setConstructorArgs([
  74. $this->connection,
  75. $this->initialStateService,
  76. $this->profileManager,
  77. $this->timeFactory,
  78. $this->urlGenerator,
  79. $this->config,
  80. $this->l10n,
  81. ])
  82. ->getMock();
  83. }
  84. public function testGetForm(): void {
  85. $this->admin->expects($this->once())
  86. ->method('cronMaxAge')
  87. ->willReturn(1337);
  88. $this->config
  89. ->expects($this->any())
  90. ->method('getAppValue')
  91. ->willReturnMap([
  92. ['core', 'backgroundjobs_mode', 'ajax', 'ajax'],
  93. ['core', 'lastcron', '0', '0'],
  94. ['core', 'cronErrors', ''],
  95. ]);
  96. $this->profileManager
  97. ->expects($this->exactly(2))
  98. ->method('isProfileEnabled')
  99. ->willReturn(true);
  100. $expected = new TemplateResponse(
  101. 'settings',
  102. 'settings/admin/server',
  103. [
  104. 'profileEnabledGlobally' => true,
  105. ],
  106. ''
  107. );
  108. $this->assertEquals($expected, $this->admin->getForm());
  109. }
  110. public function testGetSection(): void {
  111. $this->assertSame('server', $this->admin->getSection());
  112. }
  113. public function testGetPriority(): void {
  114. $this->assertSame(0, $this->admin->getPriority());
  115. }
  116. }