1
0

ServerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 OCA\Settings\Settings\Admin\Server;
  32. use OCP\AppFramework\Http\TemplateResponse;
  33. use OCP\AppFramework\Utility\ITimeFactory;
  34. use OCP\IConfig;
  35. use OCP\IDBConnection;
  36. use PHPUnit\Framework\MockObject\MockObject;
  37. use Test\TestCase;
  38. /**
  39. * @group DB
  40. */
  41. class ServerTest extends TestCase {
  42. /** @var Server */
  43. private $admin;
  44. /** @var IDBConnection */
  45. private $connection;
  46. /** @var ITimeFactory|MockObject */
  47. private $timeFactory;
  48. /** @var IConfig|MockObject */
  49. private $config;
  50. protected function setUp(): void {
  51. parent::setUp();
  52. $this->connection = \OC::$server->getDatabaseConnection();
  53. $this->timeFactory = $this->createMock(ITimeFactory::class);
  54. $this->config = $this->createMock(IConfig::class);
  55. $this->admin = $this->getMockBuilder(Server::class)
  56. ->onlyMethods(['cronMaxAge'])
  57. ->setConstructorArgs([
  58. $this->connection,
  59. $this->timeFactory,
  60. $this->config,
  61. ])
  62. ->getMock();
  63. }
  64. public function testGetForm(): void {
  65. $this->admin->expects($this->once())
  66. ->method('cronMaxAge')
  67. ->willReturn(1337);
  68. $this->config
  69. ->expects($this->at(0))
  70. ->method('getAppValue')
  71. ->with('core', 'backgroundjobs_mode', 'ajax')
  72. ->willReturn('ajax');
  73. $this->config
  74. ->expects($this->at(1))
  75. ->method('getAppValue')
  76. ->with('core', 'lastcron', false)
  77. ->willReturn(false);
  78. $this->config
  79. ->expects($this->at(2))
  80. ->method('getAppValue')
  81. ->with('core', 'cronErrors')
  82. ->willReturn('');
  83. $expected = new TemplateResponse(
  84. 'settings',
  85. 'settings/admin/server',
  86. [
  87. 'backgroundjobs_mode' => 'ajax',
  88. 'lastcron' => false,
  89. 'cronErrors' => '',
  90. 'cronMaxAge' => 1337,
  91. 'cli_based_cron_possible' => true,
  92. 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '', // to not explode here because of posix extension not being disabled - which is already checked in the line above
  93. ],
  94. ''
  95. );
  96. $this->assertEquals($expected, $this->admin->getForm());
  97. }
  98. public function testGetSection(): void {
  99. $this->assertSame('server', $this->admin->getSection());
  100. }
  101. public function testGetPriority(): void {
  102. $this->assertSame(0, $this->admin->getPriority());
  103. }
  104. }