ServerTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test;
  8. use OC\App\AppStore\Fetcher\AppFetcher;
  9. use OC\App\AppStore\Fetcher\CategoryFetcher;
  10. use OCP\Comments\ICommentsManager;
  11. /**
  12. * Class Server
  13. *
  14. * @group DB
  15. *
  16. * @package Test
  17. */
  18. class ServerTest extends \Test\TestCase {
  19. /** @var \OC\Server */
  20. protected $server;
  21. protected function setUp(): void {
  22. parent::setUp();
  23. $config = new \OC\Config(\OC::$configDir);
  24. $this->server = new \OC\Server('', $config);
  25. }
  26. public function dataTestQuery() {
  27. return [
  28. ['ActivityManager', '\OC\Activity\Manager'],
  29. ['ActivityManager', '\OCP\Activity\IManager'],
  30. ['AllConfig', '\OC\AllConfig'],
  31. ['AllConfig', '\OCP\IConfig'],
  32. ['AppConfig', '\OC\AppConfig'],
  33. ['AppConfig', '\OCP\IAppConfig'],
  34. ['AppFetcher', AppFetcher::class],
  35. ['AppManager', '\OC\App\AppManager'],
  36. ['AppManager', '\OCP\App\IAppManager'],
  37. ['AsyncCommandBus', '\OC\Command\AsyncBus'],
  38. ['AsyncCommandBus', '\OCP\Command\IBus'],
  39. ['AvatarManager', '\OC\Avatar\AvatarManager'],
  40. ['AvatarManager', '\OCP\IAvatarManager'],
  41. ['CategoryFetcher', CategoryFetcher::class],
  42. ['CapabilitiesManager', '\OC\CapabilitiesManager'],
  43. ['ContactsManager', '\OC\ContactsManager'],
  44. ['ContactsManager', '\OCP\Contacts\IManager'],
  45. ['ContentSecurityPolicyManager', '\OC\Security\CSP\ContentSecurityPolicyManager'],
  46. ['CommentsManager', '\OCP\Comments\ICommentsManager'],
  47. ['Crypto', '\OC\Security\Crypto'],
  48. ['Crypto', '\OCP\Security\ICrypto'],
  49. ['CryptoWrapper', '\OC\Session\CryptoWrapper'],
  50. ['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'],
  51. ['DatabaseConnection', '\OC\DB\ConnectionAdapter'],
  52. ['DatabaseConnection', '\OCP\IDBConnection'],
  53. ['DateTimeFormatter', '\OC\DateTimeFormatter'],
  54. ['DateTimeFormatter', '\OCP\IDateTimeFormatter'],
  55. ['DateTimeZone', '\OC\DateTimeZone'],
  56. ['DateTimeZone', '\OCP\IDateTimeZone'],
  57. ['EncryptionFileHelper', '\OC\Encryption\File'],
  58. ['EncryptionFileHelper', '\OCP\Encryption\IFile'],
  59. ['EncryptionKeyStorage', '\OC\Encryption\Keys\Storage'],
  60. ['EncryptionKeyStorage', '\OCP\Encryption\Keys\IStorage'],
  61. ['EncryptionManager', '\OC\Encryption\Manager'],
  62. ['EncryptionManager', '\OCP\Encryption\IManager'],
  63. ['EventLogger', '\OCP\Diagnostics\IEventLogger'],
  64. ['GroupManager', '\OC\Group\Manager'],
  65. ['GroupManager', '\OCP\IGroupManager'],
  66. ['Hasher', '\OC\Security\Hasher'],
  67. ['Hasher', '\OCP\Security\IHasher'],
  68. ['HttpClientService', '\OC\Http\Client\ClientService'],
  69. ['HttpClientService', '\OCP\Http\Client\IClientService'],
  70. ['IniWrapper', '\bantu\IniGetWrapper\IniGetWrapper'],
  71. ['MimeTypeDetector', '\OCP\Files\IMimeTypeDetector'],
  72. ['MimeTypeDetector', '\OC\Files\Type\Detection'],
  73. ['JobList', '\OC\BackgroundJob\JobList'],
  74. ['JobList', '\OCP\BackgroundJob\IJobList'],
  75. ['L10NFactory', '\OC\L10N\Factory'],
  76. ['L10NFactory', '\OCP\L10N\IFactory'],
  77. ['LockingProvider', '\OCP\Lock\ILockingProvider'],
  78. ['Logger', '\OC\Log'],
  79. ['Logger', '\OCP\ILogger'],
  80. ['Mailer', '\OC\Mail\Mailer'],
  81. ['Mailer', '\OCP\Mail\IMailer'],
  82. ['MemCacheFactory', '\OC\Memcache\Factory'],
  83. ['MemCacheFactory', '\OCP\ICacheFactory'],
  84. ['MountConfigManager', '\OC\Files\Config\MountProviderCollection'],
  85. ['MountConfigManager', '\OCP\Files\Config\IMountProviderCollection'],
  86. ['NavigationManager', '\OC\NavigationManager'],
  87. ['NavigationManager', '\OCP\INavigationManager'],
  88. ['NotificationManager', '\OC\Notification\Manager'],
  89. ['NotificationManager', '\OCP\Notification\IManager'],
  90. ['UserCache', '\OC\Cache\File'],
  91. ['UserCache', '\OCP\ICache'],
  92. ['PreviewManager', '\OC\PreviewManager'],
  93. ['PreviewManager', '\OCP\IPreview'],
  94. ['QueryLogger', '\OCP\Diagnostics\IQueryLogger'],
  95. ['Request', '\OC\AppFramework\Http\Request'],
  96. ['Request', '\OCP\IRequest'],
  97. ['RootFolder', '\OC\Files\Node\Root'],
  98. ['RootFolder', '\OC\Files\Node\Folder'],
  99. ['RootFolder', '\OCP\Files\IRootFolder'],
  100. ['RootFolder', '\OCP\Files\Folder'],
  101. ['Router', '\OCP\Route\IRouter'],
  102. ['Search', '\OC\Search'],
  103. ['Search', '\OCP\ISearch'],
  104. ['SecureRandom', '\OC\Security\SecureRandom'],
  105. ['SecureRandom', '\OCP\Security\ISecureRandom'],
  106. ['ShareManager', '\OC\Share20\Manager'],
  107. ['ShareManager', '\OCP\Share\IManager'],
  108. ['SystemConfig', '\OC\SystemConfig'],
  109. ['URLGenerator', '\OC\URLGenerator'],
  110. ['URLGenerator', '\OCP\IURLGenerator'],
  111. ['UserManager', '\OC\User\Manager'],
  112. ['UserManager', '\OCP\IUserManager'],
  113. ['UserSession', '\OC\User\Session'],
  114. ['UserSession', '\OCP\IUserSession'],
  115. ['TagMapper', '\OC\Tagging\TagMapper'],
  116. ['TagMapper', '\OCP\AppFramework\Db\QBMapper'],
  117. ['TagManager', '\OC\TagManager'],
  118. ['TagManager', '\OCP\ITagManager'],
  119. ['TempManager', '\OC\TempManager'],
  120. ['TempManager', '\OCP\ITempManager'],
  121. ['ThemingDefaults', '\OCA\Theming\ThemingDefaults'],
  122. ['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
  123. ['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
  124. ['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
  125. ];
  126. }
  127. /**
  128. * @dataProvider dataTestQuery
  129. *
  130. * @param string $serviceName
  131. * @param string $instanceOf
  132. */
  133. public function testQuery($serviceName, $instanceOf) {
  134. $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
  135. }
  136. public function testGetCertificateManager() {
  137. $this->assertInstanceOf('\OC\Security\CertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  138. $this->assertInstanceOf('\OCP\ICertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  139. }
  140. public function testOverwriteDefaultCommentsManager() {
  141. $config = $this->server->getConfig();
  142. $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  143. $config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
  144. $manager = $this->server->get(ICommentsManager::class);
  145. $this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
  146. $config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
  147. }
  148. }