ServerTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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(4))
  78. ->method('getAppValue')
  79. ->with('core', 'lastcron', false)
  80. ->willReturn(false);
  81. $this->config
  82. ->expects($this->at(5))
  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->config
  92. ->expects($this->at(3))
  93. ->method('getSystemValue')
  94. ->with('cron_log', true)
  95. ->willReturn(true);
  96. $this->l10n
  97. ->expects($this->at(0))
  98. ->method('t')
  99. ->with('APCu')
  100. ->willReturn('APCu');
  101. $this->l10n
  102. ->expects($this->at(1))
  103. ->method('t')
  104. ->with('Redis')
  105. ->willReturn('Redis');
  106. $outdatedCaches = [];
  107. $caches = [
  108. 'apcu' => ['name' => 'APCu', 'version' => '4.0.6'],
  109. 'redis' => ['name' => 'Redis', 'version' => '2.2.5'],
  110. ];
  111. foreach ($caches as $php_module => $data) {
  112. $isOutdated = extension_loaded($php_module) && version_compare(phpversion($php_module), $data['version'], '<');
  113. if ($isOutdated) {
  114. $outdatedCaches[$php_module] = $data;
  115. }
  116. }
  117. $envPath = getenv('PATH');
  118. $expected = new TemplateResponse(
  119. 'settings',
  120. 'admin/server',
  121. [
  122. // Diagnosis
  123. 'readOnlyConfigEnabled' => \OC_Helper::isReadOnlyConfigEnabled(),
  124. 'isLocaleWorking' => \OC_Util::isSetLocaleWorking(),
  125. 'isAnnotationsWorking' => \OC_Util::isAnnotationsWorking(),
  126. 'checkForWorkingWellKnownSetup' => true,
  127. 'has_fileinfo' => \OC_Util::fileInfoLoaded(),
  128. 'invalidTransactionIsolationLevel' => false,
  129. 'getenvServerNotWorking' => empty($envPath),
  130. 'OutdatedCacheWarning' => $outdatedCaches,
  131. 'fileLockingType' => 'cache',
  132. 'suggestedOverwriteCliUrl' => '',
  133. // Background jobs
  134. 'backgroundjobs_mode' => 'ajax',
  135. 'cron_log' => true,
  136. 'lastcron' => false,
  137. 'cronErrors' => '',
  138. 'cli_based_cron_possible' => true,
  139. '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
  140. ],
  141. ''
  142. );
  143. $this->assertEquals($expected, $this->admin->getForm());
  144. }
  145. public function testGetSection() {
  146. $this->assertSame('server', $this->admin->getSection());
  147. }
  148. public function testGetPriority() {
  149. $this->assertSame(0, $this->admin->getPriority());
  150. }
  151. }