1
0

PluginManagerTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud GmbH.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\DAV\Tests\unit\AppInfo;
  28. use OC\App\AppManager;
  29. use OC\ServerContainer;
  30. use OCA\DAV\AppInfo\PluginManager;
  31. use OCA\DAV\CalDAV\AppCalendar\AppCalendarPlugin;
  32. use OCA\DAV\CalDAV\Integration\ICalendarProvider;
  33. use Sabre\DAV\Collection;
  34. use Sabre\DAV\ServerPlugin;
  35. use Test\TestCase;
  36. /**
  37. * Class PluginManagerTest
  38. *
  39. * @package OCA\DAV\Tests\Unit\AppInfo
  40. */
  41. class PluginManagerTest extends TestCase {
  42. public function test(): void {
  43. $server = $this->createMock(ServerContainer::class);
  44. $appManager = $this->createMock(AppManager::class);
  45. $appManager->method('getInstalledApps')
  46. ->willReturn(['adavapp', 'adavapp2']);
  47. $appInfo1 = [
  48. 'types' => ['dav'],
  49. 'sabre' => [
  50. 'plugins' => [
  51. 'plugin' => [
  52. '\OCA\DAV\ADavApp\PluginOne',
  53. '\OCA\DAV\ADavApp\PluginTwo',
  54. ],
  55. ],
  56. 'calendar-plugins' => [
  57. 'plugin' => [
  58. '\OCA\DAV\ADavApp\CalendarPluginOne',
  59. '\OCA\DAV\ADavApp\CalendarPluginTwo',
  60. ],
  61. ],
  62. 'collections' => [
  63. 'collection' => [
  64. '\OCA\DAV\ADavApp\CollectionOne',
  65. '\OCA\DAV\ADavApp\CollectionTwo',
  66. ]
  67. ],
  68. ],
  69. ];
  70. $appInfo2 = [
  71. 'types' => ['logging', 'dav'],
  72. 'sabre' => [
  73. 'plugins' => [
  74. 'plugin' => '\OCA\DAV\ADavApp2\PluginOne',
  75. ],
  76. 'calendar-plugins' => [
  77. 'plugin' => '\OCA\DAV\ADavApp2\CalendarPluginOne',
  78. ],
  79. 'collections' => [
  80. 'collection' => '\OCA\DAV\ADavApp2\CollectionOne',
  81. ],
  82. ],
  83. ];
  84. $appManager->method('getAppInfo')
  85. ->willReturnMap([
  86. ['adavapp', false, null, $appInfo1],
  87. ['adavapp2', false, null, $appInfo2],
  88. ]);
  89. $pluginManager = new PluginManager($server, $appManager);
  90. $appCalendarPlugin = $this->createMock(AppCalendarPlugin::class);
  91. $calendarPlugin1 = $this->createMock(ICalendarProvider::class);
  92. $calendarPlugin2 = $this->createMock(ICalendarProvider::class);
  93. $calendarPlugin3 = $this->createMock(ICalendarProvider::class);
  94. $dummyPlugin1 = $this->createMock(ServerPlugin::class);
  95. $dummyPlugin2 = $this->createMock(ServerPlugin::class);
  96. $dummy2Plugin1 = $this->createMock(ServerPlugin::class);
  97. $dummyCollection1 = $this->createMock(Collection::class);
  98. $dummyCollection2 = $this->createMock(Collection::class);
  99. $dummy2Collection1 = $this->createMock(Collection::class);
  100. $server->method('get')
  101. ->willReturnMap([
  102. [AppCalendarPlugin::class, $appCalendarPlugin],
  103. ['\OCA\DAV\ADavApp\PluginOne', $dummyPlugin1],
  104. ['\OCA\DAV\ADavApp\PluginTwo', $dummyPlugin2],
  105. ['\OCA\DAV\ADavApp\CalendarPluginOne', $calendarPlugin1],
  106. ['\OCA\DAV\ADavApp\CalendarPluginTwo', $calendarPlugin2],
  107. ['\OCA\DAV\ADavApp\CollectionOne', $dummyCollection1],
  108. ['\OCA\DAV\ADavApp\CollectionTwo', $dummyCollection2],
  109. ['\OCA\DAV\ADavApp2\PluginOne', $dummy2Plugin1],
  110. ['\OCA\DAV\ADavApp2\CalendarPluginOne', $calendarPlugin3],
  111. ['\OCA\DAV\ADavApp2\CollectionOne', $dummy2Collection1],
  112. ]);
  113. $expectedPlugins = [
  114. $dummyPlugin1,
  115. $dummyPlugin2,
  116. $dummy2Plugin1,
  117. ];
  118. $expectedCalendarPlugins = [
  119. $appCalendarPlugin,
  120. $calendarPlugin1,
  121. $calendarPlugin2,
  122. $calendarPlugin3,
  123. ];
  124. $expectedCollections = [
  125. $dummyCollection1,
  126. $dummyCollection2,
  127. $dummy2Collection1,
  128. ];
  129. $this->assertEquals($expectedPlugins, $pluginManager->getAppPlugins());
  130. $this->assertEquals($expectedCalendarPlugins, $pluginManager->getCalendarPlugins());
  131. $this->assertEquals($expectedCollections, $pluginManager->getAppCollections());
  132. }
  133. }