diff --git a/apps/comments/appinfo/info.xml b/apps/comments/appinfo/info.xml index eb711c4b56908..ff4689574a46f 100644 --- a/apps/comments/appinfo/info.xml +++ b/apps/comments/appinfo/info.xml @@ -12,8 +12,8 @@ + - OCA\Comments\Activity\Setting @@ -27,4 +27,12 @@ OCA\Comments\Activity\Provider + + + OCA\Comments\Dav\CommentsPlugin + + + OCA\Comments\Dav\RootCollection + + diff --git a/apps/dav/lib/Comments/CommentNode.php b/apps/comments/lib/Dav/CommentNode.php similarity index 99% rename from apps/dav/lib/Comments/CommentNode.php rename to apps/comments/lib/Dav/CommentNode.php index 1fa8e057b99ef..ce69600021ddb 100644 --- a/apps/dav/lib/Comments/CommentNode.php +++ b/apps/comments/lib/Dav/CommentNode.php @@ -21,7 +21,7 @@ * */ -namespace OCA\DAV\Comments; +namespace OCA\Comments\Dav; use OCP\Comments\IComment; diff --git a/apps/dav/lib/Comments/CommentsPlugin.php b/apps/comments/lib/Dav/CommentsPlugin.php similarity index 98% rename from apps/dav/lib/Comments/CommentsPlugin.php rename to apps/comments/lib/Dav/CommentsPlugin.php index 9b496ccf6e5a4..96e7e3e29b805 100644 --- a/apps/dav/lib/Comments/CommentsPlugin.php +++ b/apps/comments/lib/Dav/CommentsPlugin.php @@ -22,7 +22,7 @@ * */ -namespace OCA\DAV\Comments; +namespace OCA\Comments\Dav; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; @@ -88,6 +88,10 @@ function initialize(Server $server) { return; } + if ($this->userSession === null || $this->userSession->getUser() === null) { + return; + } + $this->server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; $this->server->xml->classMap['DateTime'] = function(Writer $writer, \DateTime $value) { diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/comments/lib/Dav/EntityCollection.php similarity index 98% rename from apps/dav/lib/Comments/EntityCollection.php rename to apps/comments/lib/Dav/EntityCollection.php index e84fbb50566bd..80d3692adf252 100644 --- a/apps/dav/lib/Comments/EntityCollection.php +++ b/apps/comments/lib/Dav/EntityCollection.php @@ -21,7 +21,7 @@ * */ -namespace OCA\DAV\Comments; +namespace OCA\Comments\Dav; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; @@ -38,7 +38,7 @@ * this represents a specific holder of comments, identified by an entity type * (class member $name) and an entity id (class member $id). * - * @package OCA\DAV\Comments + * @package OCA\Comments\Dav */ class EntityCollection extends RootCollection implements IProperties { const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; diff --git a/apps/dav/lib/Comments/EntityTypeCollection.php b/apps/comments/lib/Dav/EntityTypeCollection.php similarity index 98% rename from apps/dav/lib/Comments/EntityTypeCollection.php rename to apps/comments/lib/Dav/EntityTypeCollection.php index 1f7f36dffab22..9697080f20b2b 100644 --- a/apps/dav/lib/Comments/EntityTypeCollection.php +++ b/apps/comments/lib/Dav/EntityTypeCollection.php @@ -21,7 +21,7 @@ * */ -namespace OCA\DAV\Comments; +namespace OCA\Comments\Dav; use OCP\Comments\ICommentsManager; use OCP\ILogger; @@ -39,7 +39,7 @@ * Its children are instances of EntityCollection (representing a specific * object, for example the file by id). * - * @package OCA\DAV\Comments + * @package OCA\Comments\Dav */ class EntityTypeCollection extends RootCollection { diff --git a/apps/dav/lib/Comments/RootCollection.php b/apps/comments/lib/Dav/RootCollection.php similarity index 98% rename from apps/dav/lib/Comments/RootCollection.php rename to apps/comments/lib/Dav/RootCollection.php index 839eb34aa9096..388c971e7acfb 100644 --- a/apps/dav/lib/Comments/RootCollection.php +++ b/apps/comments/lib/Dav/RootCollection.php @@ -21,7 +21,7 @@ * */ -namespace OCA\DAV\Comments; +namespace OCA\Comments\Dav; use OCP\Comments\CommentsEntityEvent; use OCP\Comments\ICommentsManager; @@ -89,6 +89,9 @@ protected function initCollections() { if($this->entityTypeCollections !== null) { return; } + if(is_null($this->userSession)) { + throw new NotAuthenticated(); + } $user = $this->userSession->getUser(); if(is_null($user)) { throw new NotAuthenticated(); diff --git a/apps/dav/tests/unit/Comments/CommentsNodeTest.php b/apps/comments/tests/unit/Dav/CommentsNodeTest.php similarity index 99% rename from apps/dav/tests/unit/Comments/CommentsNodeTest.php rename to apps/comments/tests/unit/Dav/CommentsNodeTest.php index 94eaea01d56bd..f5ecefd2f0373 100644 --- a/apps/dav/tests/unit/Comments/CommentsNodeTest.php +++ b/apps/comments/tests/unit/Dav/CommentsNodeTest.php @@ -25,9 +25,8 @@ namespace OCA\DAV\Tests\unit\Comments; -use OCA\DAV\Comments\CommentNode; -use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; +use OCA\Comments\Dav\CommentNode; use OCP\Comments\MessageTooLongException; class CommentsNodeTest extends \Test\TestCase { diff --git a/apps/dav/tests/unit/Comments/CommentsPluginTest.php b/apps/comments/tests/unit/Dav/CommentsPluginTest.php similarity index 96% rename from apps/dav/tests/unit/Comments/CommentsPluginTest.php rename to apps/comments/tests/unit/Dav/CommentsPluginTest.php index bb512465a8931..27b79afcfb8b8 100644 --- a/apps/dav/tests/unit/Comments/CommentsPluginTest.php +++ b/apps/comments/tests/unit/Dav/CommentsPluginTest.php @@ -26,7 +26,7 @@ namespace OCA\DAV\Tests\unit\Comments; use OC\Comments\Comment; -use OCA\DAV\Comments\CommentsPlugin as CommentsPluginImplementation; +use OCA\Comments\Dav\CommentsPlugin as CommentsPluginImplementation; use OCP\Comments\IComment; use Sabre\DAV\Exception\NotFound; @@ -93,7 +93,7 @@ public function testCreateComment() { ->method('getUID') ->will($this->returnValue('alice')); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -112,7 +112,7 @@ public function testCreateComment() { ->with('users', 'alice', 'files', '42') ->will($this->returnValue($comment)); - $this->userSession->expects($this->once()) + $this->userSession->expects($this->any()) ->method('getUser') ->will($this->returnValue($user)); @@ -188,7 +188,7 @@ public function testCreateCommentInvalidObject() { $user->expects($this->never()) ->method('getUID'); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->never()) @@ -199,7 +199,7 @@ public function testCreateCommentInvalidObject() { $this->commentsManager->expects($this->never()) ->method('create'); - $this->userSession->expects($this->never()) + $this->userSession->expects($this->once()) ->method('getUser'); // technically, this is a shortcut. Inbetween EntityTypeCollection would @@ -272,7 +272,7 @@ public function testCreateCommentInvalidActor() { $user->expects($this->never()) ->method('getUID'); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -285,7 +285,7 @@ public function testCreateCommentInvalidActor() { $this->commentsManager->expects($this->never()) ->method('create'); - $this->userSession->expects($this->never()) + $this->userSession->expects($this->once()) ->method('getUser'); // technically, this is a shortcut. Inbetween EntityTypeCollection would @@ -360,7 +360,7 @@ public function testCreateCommentUnsupportedMediaType() { $user->expects($this->never()) ->method('getUID'); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -373,7 +373,7 @@ public function testCreateCommentUnsupportedMediaType() { $this->commentsManager->expects($this->never()) ->method('create'); - $this->userSession->expects($this->never()) + $this->userSession->expects($this->once()) ->method('getUser'); // technically, this is a shortcut. Inbetween EntityTypeCollection would @@ -451,7 +451,7 @@ public function testCreateCommentInvalidPayload() { ->method('getUID') ->will($this->returnValue('alice')); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -466,7 +466,7 @@ public function testCreateCommentInvalidPayload() { ->with('users', 'alice', 'files', '42') ->will($this->returnValue($comment)); - $this->userSession->expects($this->once()) + $this->userSession->expects($this->any()) ->method('getUser') ->will($this->returnValue($user)); @@ -545,7 +545,7 @@ public function testCreateCommentMessageTooLong() { ->method('getUID') ->will($this->returnValue('alice')); - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -563,7 +563,7 @@ public function testCreateCommentMessageTooLong() { ->with('users', 'alice', 'files', '42') ->will($this->returnValue($comment)); - $this->userSession->expects($this->once()) + $this->userSession->expects($this->any()) ->method('getUser') ->will($this->returnValue($user)); @@ -672,7 +672,7 @@ public function testOnReportDateTimeEmpty() { ] ]; - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) @@ -727,7 +727,7 @@ public function testOnReport() { ] ]; - $node = $this->getMockBuilder('\OCA\DAV\Comments\EntityCollection') + $node = $this->getMockBuilder('\OCA\Comments\Dav\EntityCollection') ->disableOriginalConstructor() ->getMock(); $node->expects($this->once()) diff --git a/apps/dav/tests/unit/Comments/EntityCollectionTest.php b/apps/comments/tests/unit/Dav/EntityCollectionTest.php similarity index 92% rename from apps/dav/tests/unit/Comments/EntityCollectionTest.php rename to apps/comments/tests/unit/Dav/EntityCollectionTest.php index c4e343d49d418..e4b6cd8455074 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/comments/tests/unit/Dav/EntityCollectionTest.php @@ -32,7 +32,7 @@ class EntityCollectionTest extends \Test\TestCase { protected $userManager; /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; - /** @var \OCA\DAV\Comments\EntityCollection */ + /** @var \OCA\Comments\Dav\EntityCollection */ protected $collection; /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; @@ -53,7 +53,7 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); - $this->collection = new \OCA\DAV\Comments\EntityCollection( + $this->collection = new \OCA\Comments\Dav\EntityCollection( '19', 'files', $this->commentsManager, @@ -78,7 +78,7 @@ public function testGetChild() { )); $node = $this->collection->getChild('55'); - $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode); + $this->assertTrue($node instanceof \OCA\Comments\Dav\CommentNode); } /** @@ -106,7 +106,7 @@ public function testGetChildren() { $result = $this->collection->getChildren(); $this->assertSame(count($result), 1); - $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode); + $this->assertTrue($result[0] instanceof \OCA\Comments\Dav\CommentNode); } public function testFindChildren() { @@ -123,7 +123,7 @@ public function testFindChildren() { $result = $this->collection->findChildren(5, 15, $dt); $this->assertSame(count($result), 1); - $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode); + $this->assertTrue($result[0] instanceof \OCA\Comments\Dav\CommentNode); } public function testChildExistsTrue() { diff --git a/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php b/apps/comments/tests/unit/Dav/EntityTypeCollectionTest.php similarity index 94% rename from apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php rename to apps/comments/tests/unit/Dav/EntityTypeCollectionTest.php index 17c4f70fa7f9f..09efceb7db636 100644 --- a/apps/dav/tests/unit/Comments/EntityTypeCollectionTest.php +++ b/apps/comments/tests/unit/Dav/EntityTypeCollectionTest.php @@ -24,7 +24,7 @@ namespace OCA\DAV\Tests\unit\Comments; -use OCA\DAV\Comments\EntityCollection as EntityCollectionImplemantation; +use OCA\Comments\Dav\EntityCollection as EntityCollectionImplemantation; class EntityTypeCollectionTest extends \Test\TestCase { @@ -34,7 +34,7 @@ class EntityTypeCollectionTest extends \Test\TestCase { protected $userManager; /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; - /** @var \OCA\DAV\Comments\EntityTypeCollection */ + /** @var \OCA\Comments\Dav\EntityTypeCollection */ protected $collection; /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; @@ -59,7 +59,7 @@ public function setUp() { $instance = $this; - $this->collection = new \OCA\DAV\Comments\EntityTypeCollection( + $this->collection = new \OCA\Comments\Dav\EntityTypeCollection( 'files', $this->commentsManager, $this->userManager, diff --git a/apps/dav/tests/unit/Comments/RootCollectionTest.php b/apps/comments/tests/unit/Dav/RootCollectionTest.php similarity index 96% rename from apps/dav/tests/unit/Comments/RootCollectionTest.php rename to apps/comments/tests/unit/Dav/RootCollectionTest.php index 95afc42a912f5..ba424985a4b6f 100644 --- a/apps/dav/tests/unit/Comments/RootCollectionTest.php +++ b/apps/comments/tests/unit/Dav/RootCollectionTest.php @@ -24,7 +24,7 @@ namespace OCA\DAV\Tests\unit\Comments; -use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation; +use OCA\Comments\Dav\EntityTypeCollection as EntityTypeCollectionImplementation; use OCP\Comments\CommentsEntityEvent; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -36,7 +36,7 @@ class RootCollectionTest extends \Test\TestCase { protected $userManager; /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; - /** @var \OCA\DAV\Comments\RootCollection */ + /** @var \OCA\Comments\Dav\RootCollection */ protected $collection; /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; @@ -66,7 +66,7 @@ public function setUp() { ->disableOriginalConstructor() ->getMock(); - $this->collection = new \OCA\DAV\Comments\RootCollection( + $this->collection = new \OCA\Comments\Dav\RootCollection( $this->commentsManager, $this->userManager, $this->userSession, diff --git a/apps/dav/appinfo/v2/remote.php b/apps/dav/appinfo/v2/remote.php index ab05e376503d9..97f6ff1dd4d92 100644 --- a/apps/dav/appinfo/v2/remote.php +++ b/apps/dav/appinfo/v2/remote.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Thomas Müller + * @author Vincent Petry * * @license AGPL-3.0 * diff --git a/apps/dav/lib/AppInfo/PluginManager.php b/apps/dav/lib/AppInfo/PluginManager.php new file mode 100644 index 0000000000000..411cf73e81577 --- /dev/null +++ b/apps/dav/lib/AppInfo/PluginManager.php @@ -0,0 +1,170 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\AppInfo; + +use OCP\App\IAppManager; +use OC\ServerContainer; +use OCP\AppFramework\QueryException; + +/** + * Manager for DAV plugins from apps, used to register them + * to the Sabre server. + */ +class PluginManager { + + /** + * @var ServerContainer + */ + private $container; + + /** + * @var IAppManager + */ + private $appManager; + + /** + * App plugins + * + * @var array + */ + private $plugins = null; + + /** + * App collections + * + * @var array + */ + private $collections = null; + + /** + * Contstruct a PluginManager + * + * @param ServerContainer $container server container for resolving plugin classes + * @param IAppManager $appManager app manager to loading apps and their info + */ + public function __construct(ServerContainer $container, IAppManager $appManager) { + $this->container = $container; + $this->appManager = $appManager; + } + + /** + * Returns an array of app-registered plugins + * + * @return array + */ + public function getAppPlugins() { + if (is_null($this->plugins)) { + $this->populate(); + } + return $this->plugins; + } + + /** + * Returns an array of app-registered collections + * + * @return array + */ + public function getAppCollections() { + if (is_null($this->collections)) { + $this->populate(); + } + return $this->collections; + } + + /** + * Retrieve plugin and collection list and populate attributes + */ + private function populate() { + $this->plugins = []; + $this->collections = []; + foreach ($this->appManager->getInstalledApps() as $app) { + // load plugins and collections from info.xml + $info = $this->appManager->getAppInfo($app); + if (!isset($info['types']) || !in_array('dav', $info['types'])) { + continue; + } + // FIXME: switch to public API once available + // load app to make sure its classes are available + \OC_App::loadApp($app); + $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); + $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); + } + } + + private function extractPluginList($array) { + if (isset($array['sabre']) && is_array($array['sabre'])) { + if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { + if (isset($array['sabre']['plugins']['plugin'])) { + $items = $array['sabre']['plugins']['plugin']; + if (!is_array($items)) { + $items = [$items]; + } + return $items; + } + } + } + return []; + } + + private function extractCollectionList($array) { + if (isset($array['sabre']) && is_array($array['sabre'])) { + if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { + if (isset($array['sabre']['collections']['collection'])) { + $items = $array['sabre']['collections']['collection']; + if (!is_array($items)) { + $items = [$items]; + } + return $items; + } + } + } + return []; + } + + private function loadSabrePluginsFromInfoXml($plugins) { + foreach ($plugins as $plugin) { + try { + $this->plugins[] = $this->container->query($plugin); + } catch (QueryException $e) { + if (class_exists($plugin)) { + $this->plugins[] = new $plugin(); + } else { + throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); + } + } + } + } + + private function loadSabreCollectionsFromInfoXml($collections) { + foreach ($collections as $collection) { + try { + $this->collections[] = $this->container->query($collection); + } catch (QueryException $e) { + if (class_exists($collection)) { + $this->collections[] = new $collection(); + } else { + throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); + } + } + }; + } + +} diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php index 478f0929c2014..4dc142ed260c4 100644 --- a/apps/dav/lib/RootCollection.php +++ b/apps/dav/lib/RootCollection.php @@ -80,13 +80,6 @@ public function __construct() { \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher() ); - $commentsCollection = new Comments\RootCollection( - \OC::$server->getCommentsManager(), - \OC::$server->getUserManager(), - \OC::$server->getUserSession(), - \OC::$server->getEventDispatcher(), - \OC::$server->getLogger() - ); $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); @@ -112,7 +105,6 @@ public function __construct() { $systemAddressBookRoot]), $systemTagCollection, $systemTagRelationsCollection, - $commentsCollection, $uploadCollection, ]; diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 79c4301a8d8d5..1cff1dacb7c59 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -30,7 +30,6 @@ use OCA\DAV\CalDAV\Schedule\IMipPlugin; use OCA\DAV\CardDAV\ImageExportPlugin; -use OCA\DAV\Comments\CommentsPlugin; use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; use OCA\DAV\Connector\Sabre\CommentPropertiesPlugin; @@ -51,6 +50,7 @@ use Sabre\CardDAV\VCFExportPlugin; use Sabre\DAV\Auth\Plugin; use OCA\DAV\Connector\Sabre\TagsPlugin; +use OCA\DAV\AppInfo\PluginManager; class Server { @@ -142,12 +142,6 @@ public function __construct(IRequest $request, $baseUri) { \OC::$server->getUserSession() )); - // comments plugin - $this->server->addPlugin(new CommentsPlugin( - \OC::$server->getCommentsManager(), - \OC::$server->getUserSession() - )); - $this->server->addPlugin(new CopyEtagHeaderPlugin()); // Some WebDAV clients do require Class 2 WebDAV support (locking), since @@ -164,7 +158,7 @@ public function __construct(IRequest $request, $baseUri) { } // wait with registering these until auth is handled and the filesystem is setup - $this->server->on('beforeMethod', function () { + $this->server->on('beforeMethod', function () use ($root) { // custom properties plugin must be the last one $userSession = \OC::$server->getUserSession(); $user = $userSession->getUser(); @@ -224,6 +218,18 @@ public function __construct(IRequest $request, $baseUri) { )); } } + + // register plugins from apps + $pluginManager = new PluginManager( + \OC::$server, + \OC::$server->getAppManager() + ); + foreach ($pluginManager->getAppPlugins() as $appPlugin) { + $this->server->addPlugin($appPlugin); + } + foreach ($pluginManager->getAppCollections() as $appCollection) { + $root->addChild($appCollection); + } }); } diff --git a/apps/dav/tests/unit/AppInfo/PluginManagerTest.php b/apps/dav/tests/unit/AppInfo/PluginManagerTest.php new file mode 100644 index 0000000000000..5776b93912377 --- /dev/null +++ b/apps/dav/tests/unit/AppInfo/PluginManagerTest.php @@ -0,0 +1,104 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\DAV\Tests\unit\AppInfo; + +use Test\TestCase; +use OCP\App\IAppManager; +use OC\ServerContainer; +use OCA\DAV\AppInfo\PluginManager; + +/** + * Class PluginManagerTest + * + * @package OCA\DAV\Tests\Unit\AppInfo + */ +class PluginManagerTest extends TestCase { + public function test() { + $server = $this->createMock(ServerContainer::class); + + + $appManager = $this->createMock(IAppManager::class); + $appManager->method('getInstalledApps') + ->willReturn(['adavapp', 'adavapp2']); + + $appInfo1 = [ + 'types' => ['dav'], + 'sabre' => [ + 'plugins' => [ + 'plugin' => [ + '\OCA\DAV\ADavApp\PluginOne', + '\OCA\DAV\ADavApp\PluginTwo', + ], + ], + 'collections' => [ + 'collection' => [ + '\OCA\DAV\ADavApp\CollectionOne', + '\OCA\DAV\ADavApp\CollectionTwo', + ] + ], + ], + ]; + $appInfo2 = [ + 'types' => ['logging', 'dav'], + 'sabre' => [ + 'plugins' => [ + 'plugin' => '\OCA\DAV\ADavApp2\PluginOne', + ], + 'collections' => [ + 'collection' => '\OCA\DAV\ADavApp2\CollectionOne', + ], + ], + ]; + + $appManager->method('getAppInfo') + ->will($this->returnValueMap([ + ['adavapp', $appInfo1], + ['adavapp2', $appInfo2], + ])); + + $pluginManager = new PluginManager($server, $appManager); + + $server->method('query') + ->will($this->returnValueMap([ + ['\OCA\DAV\ADavApp\PluginOne', 'dummyplugin1'], + ['\OCA\DAV\ADavApp\PluginTwo', 'dummyplugin2'], + ['\OCA\DAV\ADavApp\CollectionOne', 'dummycollection1'], + ['\OCA\DAV\ADavApp\CollectionTwo', 'dummycollection2'], + ['\OCA\DAV\ADavApp2\PluginOne', 'dummy2plugin1'], + ['\OCA\DAV\ADavApp2\CollectionOne', 'dummy2collection1'], + ])); + + $expectedPlugins = [ + 'dummyplugin1', + 'dummyplugin2', + 'dummy2plugin1', + ]; + $expectedCollections = [ + 'dummycollection1', + 'dummycollection2', + 'dummy2collection1', + ]; + + $this->assertEquals($expectedPlugins, $pluginManager->getAppPlugins()); + $this->assertEquals($expectedCollections, $pluginManager->getAppCollections()); + } +} diff --git a/apps/dav/tests/unit/ServerTest.php b/apps/dav/tests/unit/ServerTest.php index 19e75c7b24eef..1b430b0f198db 100644 --- a/apps/dav/tests/unit/ServerTest.php +++ b/apps/dav/tests/unit/ServerTest.php @@ -26,6 +26,7 @@ use OCA\DAV\Server; use OCP\IRequest; +use OCA\DAV\AppInfo\PluginManager; /** * Class ServerTest @@ -38,8 +39,7 @@ class ServerTest extends \Test\TestCase { public function test() { /** @var IRequest $r */ - $r = $this->getMockBuilder('\OCP\IRequest') - ->disableOriginalConstructor()->getMock(); + $r = $this->createMock(IRequest::class); $s = new Server($r, '/'); $this->assertInstanceOf('OCA\DAV\Server', $s); }