ServerTest.php 7.3 KB

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