ServerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 OCP\Comments\ICommentsManager;
  10. /**
  11. * Class Server
  12. *
  13. * @group DB
  14. *
  15. * @package Test
  16. */
  17. class ServerTest extends \Test\TestCase {
  18. /** @var \OC\Server */
  19. protected $server;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. $config = new \OC\Config(\OC::$configDir);
  23. $this->server = new \OC\Server('', $config);
  24. }
  25. public function dataTestQuery() {
  26. return [
  27. ['\OCP\Activity\IManager', '\OC\Activity\Manager'],
  28. ['\OCP\IConfig', '\OC\AllConfig'],
  29. ['\OCP\IAppConfig', '\OC\AppConfig'],
  30. [AppFetcher::class, AppFetcher::class],
  31. ['\OCP\App\IAppManager', '\OC\App\AppManager'],
  32. ['\OCP\Command\IBus', '\OC\Command\AsyncBus'],
  33. ['\OCP\IAvatarManager', '\OC\Avatar\AvatarManager'],
  34. ];
  35. }
  36. /**
  37. * @dataProvider dataTestQuery
  38. *
  39. * @param string $serviceName
  40. * @param string $instanceOf
  41. */
  42. public function testQuery($serviceName, $instanceOf): void {
  43. $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
  44. }
  45. public function testGetCertificateManager(): void {
  46. $this->assertInstanceOf('\OC\Security\CertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  47. $this->assertInstanceOf('\OCP\ICertificateManager', $this->server->getCertificateManager(), 'service returned by "getCertificateManager" did not return the right class');
  48. }
  49. public function testOverwriteDefaultCommentsManager(): void {
  50. $config = $this->server->getConfig();
  51. $defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
  52. $config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
  53. $manager = $this->server->get(ICommentsManager::class);
  54. $this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
  55. $config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
  56. }
  57. }