You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerTest.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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('\OCP\IConfig')->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('\OCP\IL10N')->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->dbConnection
  63. ->expects($this->once())
  64. ->method('getDatabasePlatform')
  65. ->willReturn(new SqlitePlatform());
  66. $this->config
  67. ->expects($this->at(0))
  68. ->method('getSystemValue')
  69. ->with('overwrite.cli.url', '')
  70. ->willReturn(true);
  71. $this->config
  72. ->expects($this->at(2))
  73. ->method('getAppValue')
  74. ->with('core', 'backgroundjobs_mode', 'ajax')
  75. ->willReturn('ajax');
  76. $this->config
  77. ->expects($this->at(3))
  78. ->method('getAppValue')
  79. ->with('core', 'lastcron', false)
  80. ->willReturn(false);
  81. $this->config
  82. ->expects($this->at(4))
  83. ->method('getAppValue')
  84. ->with('core', 'cronErrors')
  85. ->willReturn('');
  86. $this->config
  87. ->expects($this->at(1))
  88. ->method('getSystemValue')
  89. ->with('check_for_working_wellknown_setup', true)
  90. ->willReturn(true);
  91. $this->l10n
  92. ->expects($this->at(0))
  93. ->method('t')
  94. ->with('APCu')
  95. ->willReturn('APCu');
  96. $this->l10n
  97. ->expects($this->at(1))
  98. ->method('t')
  99. ->with('Redis')
  100. ->willReturn('Redis');
  101. $outdatedCaches = [];
  102. $caches = [
  103. 'apcu' => ['name' => 'APCu', 'version' => '4.0.6'],
  104. 'redis' => ['name' => 'Redis', 'version' => '2.2.5'],
  105. ];
  106. foreach ($caches as $php_module => $data) {
  107. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  108. if ($isOutdated) {
  109. $outdatedCaches[$php_module] = $data;
  110. }
  111. }
  112. $envPath = getenv('PATH');
  113. $expected = new TemplateResponse(
  114. 'settings',
  115. 'settings/admin/server',
  116. [
  117. // Diagnosis
  118. 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
  119. 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
  120. 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
  121. 'checkForWorkingWellKnownSetup' => true,
  122. 'has_fileinfo' => \OC_Util::fileInfoLoaded(),
  123. 'invalidTransactionIsolationLevel' => false,
  124. 'getenvServerNotWorking' => empty($envPath),
  125. 'OutdatedCacheWarning' => $outdatedCaches,
  126. 'fileLockingType' => 'cache',
  127. 'suggestedOverwriteCliUrl' => '',
  128. // Background jobs
  129. 'backgroundjobs_mode' => 'ajax',
  130. 'lastcron' => false,
  131. 'cronErrors' => '',
  132. 'cli_based_cron_possible' => true,
  133. '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
  134. ],
  135. ''
  136. );
  137. $this->assertEquals($expected, $this->admin->getForm());
  138. }
  139. public function testGetSection() {
  140. $this->assertSame('server', $this->admin->getSection());
  141. }
  142. public function testGetPriority() {
  143. $this->assertSame(0, $this->admin->getPriority());
  144. }
  145. }