ServerTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace Test;
  25. use OC\App\AppStore\Fetcher\AppFetcher;
  26. use OC\App\AppStore\Fetcher\CategoryFetcher;
  27. use OCP\Comments\ICommentsManager;
  28. /**
  29. * Class Server
  30. *
  31. * @group DB
  32. *
  33. * @package Test
  34. */
  35. class ServerTest extends \Test\TestCase {
  36. /** @var \OC\Server */
  37. protected $server;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $config = new \OC\Config(\OC::$configDir);
  41. $this->server = new \OC\Server('', $config);
  42. }
  43. public function dataTestQuery() {
  44. return [
  45. ['ActivityManager', '\OC\Activity\Manager'],
  46. ['ActivityManager', '\OCP\Activity\IManager'],
  47. ['AllConfig', '\OC\AllConfig'],
  48. ['AllConfig', '\OCP\IConfig'],
  49. ['AppConfig', '\OC\AppConfig'],
  50. ['AppConfig', '\OCP\IAppConfig'],
  51. ['AppFetcher', AppFetcher::class],
  52. ['AppManager', '\OC\App\AppManager'],
  53. ['AppManager', '\OCP\App\IAppManager'],
  54. ['AsyncCommandBus', '\OC\Command\AsyncBus'],
  55. ['AsyncCommandBus', '\OCP\Command\IBus'],
  56. ['AvatarManager', '\OC\Avatar\AvatarManager'],
  57. ['AvatarManager', '\OCP\IAvatarManager'],
  58. ['CategoryFetcher', CategoryFetcher::class],
  59. ['CapabilitiesManager', '\OC\CapabilitiesManager'],
  60. ['ContactsManager', '\OC\ContactsManager'],
  61. ['ContactsManager', '\OCP\Contacts\IManager'],
  62. ['ContentSecurityPolicyManager', '\OC\Security\CSP\ContentSecurityPolicyManager'],
  63. ['CommentsManager', '\OCP\Comments\ICommentsManager'],
  64. ['Crypto', '\OC\Security\Crypto'],
  65. ['Crypto', '\OCP\Security\ICrypto'],
  66. ['CryptoWrapper', '\OC\Session\CryptoWrapper'],
  67. ['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'],
  68. ['DatabaseConnection', '\OC\DB\ConnectionAdapter'],
  69. ['DatabaseConnection', '\OCP\IDBConnection'],
  70. ['DateTimeFormatter', '\OC\DateTimeFormatter'],
  71. ['DateTimeFormatter', '\OCP\IDateTimeFormatter'],
  72. ['DateTimeZone', '\OC\DateTimeZone'],
  73. ['DateTimeZone', '\OCP\IDateTimeZone'],
  74. ['EncryptionFileHelper', '\OC\Encryption\File'],
  75. ['EncryptionFileHelper', '\OCP\Encryption\IFile'],
  76. ['EncryptionKeyStorage', '\OC\Encryption\Keys\Storage'],
  77. ['EncryptionKeyStorage', '\OCP\Encryption\Keys\IStorage'],
  78. ['EncryptionManager', '\OC\Encryption\Manager'],
  79. ['EncryptionManager', '\OCP\Encryption\IManager'],
  80. ['EventLogger', '\OCP\Diagnostics\IEventLogger'],
  81. ['GroupManager', '\OC\Group\Manager'],
  82. ['GroupManager', '\OCP\IGroupManager'],
  83. ['Hasher', '\OC\Security\Hasher'],
  84. ['Hasher', '\OCP\Security\IHasher'],
  85. ['HttpClientService', '\OC\Http\Client\ClientService'],
  86. ['HttpClientService', '\OCP\Http\Client\IClientService'],
  87. ['IniWrapper', '\bantu\IniGetWrapper\IniGetWrapper'],
  88. ['MimeTypeDetector', '\OCP\Files\IMimeTypeDetector'],
  89. ['MimeTypeDetector', '\OC\Files\Type\Detection'],
  90. ['JobList', '\OC\BackgroundJob\JobList'],
  91. ['JobList', '\OCP\BackgroundJob\IJobList'],
  92. ['L10NFactory', '\OC\L10N\Factory'],
  93. ['L10NFactory', '\OCP\L10N\IFactory'],
  94. ['LockingProvider', '\OCP\Lock\ILockingProvider'],
  95. ['Logger', '\OC\Log'],
  96. ['Logger', '\OCP\ILogger'],
  97. ['Mailer', '\OC\Mail\Mailer'],
  98. ['Mailer', '\OCP\Mail\IMailer'],
  99. ['MemCacheFactory', '\OC\Memcache\Factory'],
  100. ['MemCacheFactory', '\OCP\ICacheFactory'],
  101. ['MountConfigManager', '\OC\Files\Config\MountProviderCollection'],
  102. ['MountConfigManager', '\OCP\Files\Config\IMountProviderCollection'],
  103. ['NavigationManager', '\OC\NavigationManager'],
  104. ['NavigationManager', '\OCP\INavigationManager'],
  105. ['NotificationManager', '\OC\Notification\Manager'],
  106. ['NotificationManager', '\OCP\Notification\IManager'],
  107. ['UserCache', '\OC\Cache\File'],
  108. ['UserCache', '\OCP\ICache'],
  109. ['PreviewManager', '\OC\PreviewManager'],
  110. ['PreviewManager', '\OCP\IPreview'],
  111. ['QueryLogger', '\OCP\Diagnostics\IQueryLogger'],
  112. ['Request', '\OC\AppFramework\Http\Request'],
  113. ['Request', '\OCP\IRequest'],
  114. ['RootFolder', '\OC\Files\Node\Root'],
  115. ['RootFolder', '\OC\Files\Node\Folder'],
  116. ['RootFolder', '\OCP\Files\IRootFolder'],
  117. ['RootFolder', '\OCP\Files\Folder'],
  118. ['Router', '\OCP\Route\IRouter'],
  119. ['Search', '\OC\Search'],
  120. ['Search', '\OCP\ISearch'],
  121. ['SecureRandom', '\OC\Security\SecureRandom'],
  122. ['SecureRandom', '\OCP\Security\ISecureRandom'],
  123. ['ShareManager', '\OC\Share20\Manager'],
  124. ['ShareManager', '\OCP\Share\IManager'],
  125. ['SystemConfig', '\OC\SystemConfig'],
  126. ['URLGenerator', '\OC\URLGenerator'],
  127. ['URLGenerator', '\OCP\IURLGenerator'],
  128. ['UserManager', '\OC\User\Manager'],
  129. ['UserManager', '\OCP\IUserManager'],
  130. ['UserSession', '\OC\User\Session'],
  131. ['UserSession', '\OCP\IUserSession'],
  132. ['TagMapper', '\OC\Tagging\TagMapper'],
  133. ['TagMapper', '\OCP\AppFramework\Db\QBMapper'],
  134. ['TagManager', '\OC\TagManager'],
  135. ['TagManager', '\OCP\ITagManager'],
  136. ['TempManager', '\OC\TempManager'],
  137. ['TempManager', '\OCP\ITempManager'],
  138. ['ThemingDefaults', '\OCA\Theming\ThemingDefaults'],
  139. ['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
  140. ['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
  141. ['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
  142. ];
  143. }
  144. /**
  145. * @dataProvider dataTestQuery
  146. *
  147. * @param string $serviceName
  148. * @param string $instanceOf
  149. */
  150. public function testQuery($serviceName, $instanceOf) {
  151. $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
  152. }
  153. public function testGetCertificateManager() {
  154. $this->assertInstanceOf('\OC\Security\CertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  155. $this->assertInstanceOf('\OCP\ICertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  156. }
  157. public function testOverwriteDefaultCommentsManager() {
  158. $config = $this->server->getConfig();
  159. $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  160. $config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
  161. $manager = $this->server->get(ICommentsManager::class);
  162. $this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
  163. $config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
  164. }
  165. }