ServerTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /**
  26. * Class Server
  27. *
  28. * @group DB
  29. *
  30. * @package Test
  31. */
  32. class ServerTest extends \Test\TestCase {
  33. /** @var \OC\Server */
  34. protected $server;
  35. public function setUp() {
  36. parent::setUp();
  37. $config = new \OC\Config(\OC::$configDir);
  38. $this->server = new \OC\Server('', $config);
  39. }
  40. public function dataTestQuery() {
  41. return [
  42. ['ActivityManager', '\OC\Activity\Manager'],
  43. ['ActivityManager', '\OCP\Activity\IManager'],
  44. ['AllConfig', '\OC\AllConfig'],
  45. ['AllConfig', '\OCP\IConfig'],
  46. ['AppConfig', '\OC\AppConfig'],
  47. ['AppConfig', '\OCP\IAppConfig'],
  48. ['AppHelper', '\OC\AppHelper'],
  49. ['AppHelper', '\OCP\IHelper'],
  50. ['AppManager', '\OC\App\AppManager'],
  51. ['AppManager', '\OCP\App\IAppManager'],
  52. ['AsyncCommandBus', '\OC\Command\AsyncBus'],
  53. ['AsyncCommandBus', '\OCP\Command\IBus'],
  54. ['AvatarManager', '\OC\AvatarManager'],
  55. ['AvatarManager', '\OCP\IAvatarManager'],
  56. ['CapabilitiesManager', '\OC\CapabilitiesManager'],
  57. ['ContactsManager', '\OC\ContactsManager'],
  58. ['ContactsManager', '\OCP\Contacts\IManager'],
  59. ['ContentSecurityPolicyManager', '\OC\Security\CSP\ContentSecurityPolicyManager'],
  60. ['CommentsManager', '\OCP\Comments\ICommentsManager'],
  61. ['Crypto', '\OC\Security\Crypto'],
  62. ['Crypto', '\OCP\Security\ICrypto'],
  63. ['CryptoWrapper', '\OC\Session\CryptoWrapper'],
  64. ['CsrfTokenManager', '\OC\Security\CSRF\CsrfTokenManager'],
  65. ['DatabaseConnection', '\OC\DB\Connection'],
  66. ['DatabaseConnection', '\OCP\IDBConnection'],
  67. ['DateTimeFormatter', '\OC\DateTimeFormatter'],
  68. ['DateTimeFormatter', '\OCP\IDateTimeFormatter'],
  69. ['DateTimeZone', '\OC\DateTimeZone'],
  70. ['DateTimeZone', '\OCP\IDateTimeZone'],
  71. ['Db', '\OC\AppFramework\Db\Db'],
  72. ['Db', '\OCP\IDb'],
  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. ['HTTPHelper', '\OC\HTTPHelper'],
  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. ['OcsClient', '\OC\OCSClient'],
  110. ['PreviewManager', '\OC\PreviewManager'],
  111. ['PreviewManager', '\OCP\IPreview'],
  112. ['QueryLogger', '\OCP\Diagnostics\IQueryLogger'],
  113. ['Request', '\OC\AppFramework\Http\Request'],
  114. ['Request', '\OCP\IRequest'],
  115. ['RootFolder', '\OC\Files\Node\Root'],
  116. ['RootFolder', '\OC\Files\Node\Folder'],
  117. ['RootFolder', '\OCP\Files\IRootFolder'],
  118. ['RootFolder', '\OCP\Files\Folder'],
  119. ['Router', '\OCP\Route\IRouter'],
  120. ['Search', '\OC\Search'],
  121. ['Search', '\OCP\ISearch'],
  122. ['SecureRandom', '\OC\Security\SecureRandom'],
  123. ['SecureRandom', '\OCP\Security\ISecureRandom'],
  124. ['ShareManager', '\OC\Share20\Manager'],
  125. ['ShareManager', '\OCP\Share\IManager'],
  126. ['SystemConfig', '\OC\SystemConfig'],
  127. ['URLGenerator', '\OC\URLGenerator'],
  128. ['URLGenerator', '\OCP\IURLGenerator'],
  129. ['UserManager', '\OC\User\Manager'],
  130. ['UserManager', '\OCP\IUserManager'],
  131. ['UserSession', '\OC\User\Session'],
  132. ['UserSession', '\OCP\IUserSession'],
  133. ['TagMapper', '\OC\Tagging\TagMapper'],
  134. ['TagMapper', '\OCP\AppFramework\Db\Mapper'],
  135. ['TagManager', '\OC\TagManager'],
  136. ['TagManager', '\OCP\ITagManager'],
  137. ['TempManager', '\OC\TempManager'],
  138. ['TempManager', '\OCP\ITempManager'],
  139. ['ThemingDefaults', '\OCA\Theming\ThemingDefaults'],
  140. ['TrustedDomainHelper', '\OC\Security\TrustedDomainHelper'],
  141. ['SystemTagManager', '\OCP\SystemTag\ISystemTagManager'],
  142. ['SystemTagObjectMapper', '\OCP\SystemTag\ISystemTagObjectMapper'],
  143. ];
  144. }
  145. /**
  146. * @dataProvider dataTestQuery
  147. *
  148. * @param string $serviceName
  149. * @param string $instanceOf
  150. */
  151. public function testQuery($serviceName, $instanceOf) {
  152. $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
  153. }
  154. public function testGetCertificateManager() {
  155. $this->assertInstanceOf('\OC\Security\CertificateManager', $this->server->getCertificateManager('test'), 'service returned by "getCertificateManager" did not return the right class');
  156. $this->assertInstanceOf('\OCP\ICertificateManager', $this->server->getCertificateManager('test'), 'service returned by "getCertificateManager" did not return the right class');
  157. }
  158. public function testCreateEventSource() {
  159. $this->assertInstanceOf('\OC_EventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class');
  160. $this->assertInstanceOf('\OCP\IEventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class');
  161. }
  162. public function testOverwriteDefaultCommentsManager() {
  163. $config = $this->server->getConfig();
  164. $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  165. $config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
  166. $manager = $this->server->getCommentsManager();
  167. $this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
  168. $config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
  169. }
  170. }