You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PluginManagerTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <pvince81@owncloud.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\Integration\ICalendarProvider;
  32. use Test\TestCase;
  33. /**
  34. * Class PluginManagerTest
  35. *
  36. * @package OCA\DAV\Tests\Unit\AppInfo
  37. */
  38. class PluginManagerTest extends TestCase {
  39. public function test() {
  40. $server = $this->createMock(ServerContainer::class);
  41. $appManager = $this->createMock(AppManager::class);
  42. $appManager->method('getInstalledApps')
  43. ->willReturn(['adavapp', 'adavapp2']);
  44. $appInfo1 = [
  45. 'types' => ['dav'],
  46. 'sabre' => [
  47. 'plugins' => [
  48. 'plugin' => [
  49. '\OCA\DAV\ADavApp\PluginOne',
  50. '\OCA\DAV\ADavApp\PluginTwo',
  51. ],
  52. ],
  53. 'calendar-plugins' => [
  54. 'plugin' => [
  55. '\OCA\DAV\ADavApp\CalendarPluginOne',
  56. '\OCA\DAV\ADavApp\CalendarPluginTwo',
  57. ],
  58. ],
  59. 'collections' => [
  60. 'collection' => [
  61. '\OCA\DAV\ADavApp\CollectionOne',
  62. '\OCA\DAV\ADavApp\CollectionTwo',
  63. ]
  64. ],
  65. ],
  66. ];
  67. $appInfo2 = [
  68. 'types' => ['logging', 'dav'],
  69. 'sabre' => [
  70. 'plugins' => [
  71. 'plugin' => '\OCA\DAV\ADavApp2\PluginOne',
  72. ],
  73. 'calendar-plugins' => [
  74. 'plugin' => '\OCA\DAV\ADavApp2\CalendarPluginOne',
  75. ],
  76. 'collections' => [
  77. 'collection' => '\OCA\DAV\ADavApp2\CollectionOne',
  78. ],
  79. ],
  80. ];
  81. $appManager->method('getAppInfo')
  82. ->willReturnMap([
  83. ['adavapp', false, null, $appInfo1],
  84. ['adavapp2', false, null, $appInfo2],
  85. ]);
  86. $pluginManager = new PluginManager($server, $appManager);
  87. $calendarPlugin1 = $this->createMock(ICalendarProvider::class);
  88. $calendarPlugin2 = $this->createMock(ICalendarProvider::class);
  89. $calendarPlugin3 = $this->createMock(ICalendarProvider::class);
  90. $server->method('query')
  91. ->willReturnMap([
  92. ['\OCA\DAV\ADavApp\PluginOne', true, 'dummyplugin1'],
  93. ['\OCA\DAV\ADavApp\PluginTwo', true, 'dummyplugin2'],
  94. ['\OCA\DAV\ADavApp\CalendarPluginOne', true, $calendarPlugin1],
  95. ['\OCA\DAV\ADavApp\CalendarPluginTwo', true, $calendarPlugin2],
  96. ['\OCA\DAV\ADavApp\CollectionOne', true, 'dummycollection1'],
  97. ['\OCA\DAV\ADavApp\CollectionTwo', true, 'dummycollection2'],
  98. ['\OCA\DAV\ADavApp2\PluginOne', true, 'dummy2plugin1'],
  99. ['\OCA\DAV\ADavApp2\CalendarPluginOne', true, $calendarPlugin3],
  100. ['\OCA\DAV\ADavApp2\CollectionOne', true, 'dummy2collection1'],
  101. ]);
  102. $expectedPlugins = [
  103. 'dummyplugin1',
  104. 'dummyplugin2',
  105. 'dummy2plugin1',
  106. ];
  107. $expectedCalendarPlugins = [
  108. $calendarPlugin1,
  109. $calendarPlugin2,
  110. $calendarPlugin3,
  111. ];
  112. $expectedCollections = [
  113. 'dummycollection1',
  114. 'dummycollection2',
  115. 'dummy2collection1',
  116. ];
  117. $this->assertEquals($expectedPlugins, $pluginManager->getAppPlugins());
  118. $this->assertEquals($expectedCalendarPlugins, $pluginManager->getCalendarPlugins());
  119. $this->assertEquals($expectedCollections, $pluginManager->getAppCollections());
  120. }
  121. }