ServerTest.php 7.5 KB

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