PluginManagerTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 ownCloud GmbH.
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OCA\DAV\Tests\unit\AppInfo;
  7. use OC\App\AppManager;
  8. use OC\ServerContainer;
  9. use OCA\DAV\AppInfo\PluginManager;
  10. use OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin;
  11. use OCA\DAV\CalDAV\Integration\ICalendarProvider;
  12. use Sabre\DAV\Collection;
  13. use Sabre\DAV\ServerPlugin;
  14. use Test\TestCase;
  15. /**
  16. * Class PluginManagerTest
  17. *
  18. * @package OCA\DAV\Tests\Unit\AppInfo
  19. */
  20. class PluginManagerTest extends TestCase {
  21. public function test(): void {
  22. $server = $this->createMock(ServerContainer::class);
  23. $appManager = $this->createMock(AppManager::class);
  24. $appManager->method('getInstalledApps')
  25. ->willReturn(['adavapp', 'adavapp2']);
  26. $appInfo1 = [
  27. 'types' => ['dav'],
  28. 'sabre' => [
  29. 'plugins' => [
  30. 'plugin' => [
  31. '\OCA\DAV\ADavApp\PluginOne',
  32. '\OCA\DAV\ADavApp\PluginTwo',
  33. ],
  34. ],
  35. 'calendar-plugins' => [
  36. 'plugin' => [
  37. '\OCA\DAV\ADavApp\CalendarPluginOne',
  38. '\OCA\DAV\ADavApp\CalendarPluginTwo',
  39. ],
  40. ],
  41. 'collections' => [
  42. 'collection' => [
  43. '\OCA\DAV\ADavApp\CollectionOne',
  44. '\OCA\DAV\ADavApp\CollectionTwo',
  45. ]
  46. ],
  47. ],
  48. ];
  49. $appInfo2 = [
  50. 'types' => ['logging', 'dav'],
  51. 'sabre' => [
  52. 'plugins' => [
  53. 'plugin' => '\OCA\DAV\ADavApp2\PluginOne',
  54. ],
  55. 'calendar-plugins' => [
  56. 'plugin' => '\OCA\DAV\ADavApp2\CalendarPluginOne',
  57. ],
  58. 'collections' => [
  59. 'collection' => '\OCA\DAV\ADavApp2\CollectionOne',
  60. ],
  61. ],
  62. ];
  63. $appManager->method('getAppInfo')
  64. ->willReturnMap([
  65. ['adavapp', false, null, $appInfo1],
  66. ['adavapp2', false, null, $appInfo2],
  67. ]);
  68. $pluginManager = new PluginManager($server, $appManager);
  69. $appCalendarPlugin = $this->createMock(AppCalendarPlugin::class);
  70. $calendarPlugin1 = $this->createMock(ICalendarProvider::class);
  71. $calendarPlugin2 = $this->createMock(ICalendarProvider::class);
  72. $calendarPlugin3 = $this->createMock(ICalendarProvider::class);
  73. $dummyPlugin1 = $this->createMock(ServerPlugin::class);
  74. $dummyPlugin2 = $this->createMock(ServerPlugin::class);
  75. $dummy2Plugin1 = $this->createMock(ServerPlugin::class);
  76. $dummyCollection1 = $this->createMock(Collection::class);
  77. $dummyCollection2 = $this->createMock(Collection::class);
  78. $dummy2Collection1 = $this->createMock(Collection::class);
  79. $server->method('get')
  80. ->willReturnMap([
  81. [AppCalendarPlugin::class, $appCalendarPlugin],
  82. ['\OCA\DAV\ADavApp\PluginOne', $dummyPlugin1],
  83. ['\OCA\DAV\ADavApp\PluginTwo', $dummyPlugin2],
  84. ['\OCA\DAV\ADavApp\CalendarPluginOne', $calendarPlugin1],
  85. ['\OCA\DAV\ADavApp\CalendarPluginTwo', $calendarPlugin2],
  86. ['\OCA\DAV\ADavApp\CollectionOne', $dummyCollection1],
  87. ['\OCA\DAV\ADavApp\CollectionTwo', $dummyCollection2],
  88. ['\OCA\DAV\ADavApp2\PluginOne', $dummy2Plugin1],
  89. ['\OCA\DAV\ADavApp2\CalendarPluginOne', $calendarPlugin3],
  90. ['\OCA\DAV\ADavApp2\CollectionOne', $dummy2Collection1],
  91. ]);
  92. $expectedPlugins = [
  93. $dummyPlugin1,
  94. $dummyPlugin2,
  95. $dummy2Plugin1,
  96. ];
  97. $expectedCalendarPlugins = [
  98. $appCalendarPlugin,
  99. $calendarPlugin1,
  100. $calendarPlugin2,
  101. $calendarPlugin3,
  102. ];
  103. $expectedCollections = [
  104. $dummyCollection1,
  105. $dummyCollection2,
  106. $dummy2Collection1,
  107. ];
  108. $this->assertEquals($expectedPlugins, $pluginManager->getAppPlugins());
  109. $this->assertEquals($expectedCalendarPlugins, $pluginManager->getCalendarPlugins());
  110. $this->assertEquals($expectedCollections, $pluginManager->getAppCollections());
  111. }
  112. }