1
0

ServerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Settings\Admin;
  24. use Doctrine\DBAL\Platforms\SqlitePlatform;
  25. use OC\Settings\Admin\Server;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\IConfig;
  28. use OCP\IDBConnection;
  29. use OCP\IL10N;
  30. use OCP\IRequest;
  31. use OCP\Lock\ILockingProvider;
  32. use Test\TestCase;
  33. class ServerTest extends TestCase {
  34. /** @var Server */
  35. private $admin;
  36. /** @var IDBConnection */
  37. private $dbConnection;
  38. /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
  39. private $request;
  40. /** @var IConfig */
  41. private $config;
  42. /** @var ILockingProvider */
  43. private $lockingProvider;
  44. /** @var IL10N */
  45. private $l10n;
  46. public function setUp() {
  47. parent::setUp();
  48. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  49. $this->request = $this->createMock(IRequest::class);
  50. $this->dbConnection = $this->getMockBuilder('\OCP\IDBConnection')->getMock();
  51. $this->lockingProvider = $this->getMockBuilder('\OCP\Lock\ILockingProvider')->getMock();
  52. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  53. $this->admin = new Server(
  54. $this->dbConnection,
  55. $this->request,
  56. $this->config,
  57. $this->lockingProvider,
  58. $this->l10n
  59. );
  60. }
  61. public function testGetForm() {
  62. $this->config
  63. ->expects($this->at(0))
  64. ->method('getAppValue')
  65. ->with('core', 'backgroundjobs_mode', 'ajax')
  66. ->willReturn('ajax');
  67. $this->config
  68. ->expects($this->at(1))
  69. ->method('getAppValue')
  70. ->with('core', 'lastcron', false)
  71. ->willReturn(false);
  72. $this->config
  73. ->expects($this->at(2))
  74. ->method('getAppValue')
  75. ->with('core', 'cronErrors')
  76. ->willReturn('');
  77. $expected = new TemplateResponse(
  78. 'settings',
  79. 'settings/admin/server',
  80. [
  81. 'backgroundjobs_mode' => 'ajax',
  82. 'lastcron' => false,
  83. 'cronErrors' => '',
  84. 'cli_based_cron_possible' => true,
  85. '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
  86. ],
  87. ''
  88. );
  89. $this->assertEquals($expected, $this->admin->getForm());
  90. }
  91. public function testGetSection() {
  92. $this->assertSame('server', $this->admin->getSection());
  93. }
  94. public function testGetPriority() {
  95. $this->assertSame(0, $this->admin->getPriority());
  96. }
  97. }