ServerTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. ['SecureRandom', '\OC\Security\SecureRandom'],
  103. ['SecureRandom', '\OCP\Security\ISecureRandom'],
  104. ['ShareManager', '\OC\Share20\Manager'],
  105. ['ShareManager', '\OCP\Share\IManager'],
  106. ['SystemConfig', '\OC\SystemConfig'],
  107. ['URLGenerator', '\OC\URLGenerator'],
  108. ['URLGenerator', '\OCP\IURLGenerator'],
  109. ['UserManager', '\OC\User\Manager'],
  110. ['UserManager', '\OCP\IUserManager'],
  111. ['UserSession', '\OC\User\Session'],
  112. ['UserSession', '\OCP\IUserSession'],
  113. ['TagMapper', '\OC\Tagging\TagMapper'],
  114. ['TagMapper', '\OCP\AppFramework\Db\QBMapper'],
  115. ['TagManager', '\OC\TagManager'],
  116. ['TagManager', '\OCP\ITagManager'],
  117. ['TempManager', '\OC\TempManager'],
  118. ['TempManager', '\OCP\ITempManager'],
  119. ['ThemingDefaults', '\OCA\Theming\ThemingDefaults'],
  120. ['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
  121. ['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
  122. ['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
  123. ];
  124. }
  125. /**
  126. * @dataProvider dataTestQuery
  127. *
  128. * @param string $serviceName
  129. * @param string $instanceOf
  130. */
  131. public function testQuery($serviceName, $instanceOf): void {
  132. $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
  133. }
  134. public function testGetCertificateManager(): void {
  135. $this->assertInstanceOf('\OC\Security\CertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  136. $this->assertInstanceOf('\OCP\ICertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  137. }
  138. public function testOverwriteDefaultCommentsManager(): void {
  139. $config = $this->server->getConfig();
  140. $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  141. $config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
  142. $manager = $this->server->get(ICommentsManager::class);
  143. $this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
  144. $config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
  145. }
  146. }