summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php9
-rw-r--r--apps/dav/tests/unit/CardDAV/CardDavBackendTest.php9
-rw-r--r--apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php71
-rw-r--r--apps/dav/tests/unit/ServerTest.php22
4 files changed, 104 insertions, 7 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index 310433f0913..681a159d833 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -30,7 +30,9 @@ use OCA\DAV\Connector\Sabre\Principal;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserManager;
+use OCP\IUserSession;
use OCP\Security\ISecureRandom;
+use OCP\Share\IManager as ShareManager;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
@@ -73,7 +75,12 @@ abstract class AbstractCalDavBackend extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->principal = $this->getMockBuilder(Principal::class)
- ->disableOriginalConstructor()
+ ->setConstructorArgs([
+ $this->userManager,
+ $this->groupManager,
+ $this->createMock(ShareManager::class),
+ $this->createMock(IUserSession::class),
+ ])
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
->getMock();
$this->principal->expects($this->any())->method('getPrincipalByPath')
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
index 63e090873bb..920e5a4ec1f 100644
--- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
+++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
@@ -40,6 +40,8 @@ use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUserManager;
+use OCP\IUserSession;
+use OCP\Share\IManager as ShareManager;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
@@ -90,7 +92,12 @@ class CardDavBackendTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->principal = $this->getMockBuilder(Principal::class)
- ->disableOriginalConstructor()
+ ->setConstructorArgs([
+ $this->userManager,
+ $this->groupManager,
+ $this->createMock(ShareManager::class),
+ $this->createMock(IUserSession::class),
+ ])
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
->getMock();
$this->principal->method('getPrincipalByPath')
diff --git a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
new file mode 100644
index 00000000000..2574e4d0aec
--- /dev/null
+++ b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2018, 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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCA\DAV\Tests\Unit\Command;
+
+
+use OCA\DAV\Connector\Sabre\Principal;
+use OCA\DAV\Command\RemoveInvalidShares;
+use OCP\Migration\IOutput;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+/**
+ * Class RemoveInvalidSharesTest
+ *
+ * @package OCA\DAV\Tests\Unit\Repair
+ * @group DB
+ */
+class RemoveInvalidSharesTest extends TestCase {
+
+ public function setUp() {
+ parent::setUp();
+ $db = \OC::$server->getDatabaseConnection();
+
+ $db->insertIfNotExist('*PREFIX*dav_shares', [
+ 'principaluri' => 'principal:unknown',
+ 'type' => 'calendar',
+ 'access' => 2,
+ 'resourceid' => 666,
+ ]);
+ }
+
+ public function test() {
+ $db = \OC::$server->getDatabaseConnection();
+ /** @var Principal | \PHPUnit_Framework_MockObject_MockObject $principal */
+ $principal = $this->createMock(Principal::class);
+
+ /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $output */
+ $output = $this->createMock(IOutput::class);
+
+ $repair = new RemoveInvalidShares($db, $principal);
+ $this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
+
+ $query = $db->getQueryBuilder();
+ $result = $query->select('*')->from('dav_shares')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
+ $data = $result->fetchAll();
+ $result->closeCursor();
+ $this->assertEquals(0, count($data));
+ }
+}
diff --git a/apps/dav/tests/unit/ServerTest.php b/apps/dav/tests/unit/ServerTest.php
index 58c77c1b0ec..986899a2107 100644
--- a/apps/dav/tests/unit/ServerTest.php
+++ b/apps/dav/tests/unit/ServerTest.php
@@ -38,12 +38,24 @@ use OCA\DAV\AppInfo\PluginManager;
*/
class ServerTest extends \Test\TestCase {
- public function test() {
- /** @var IRequest $r */
+ /**
+ * @dataProvider providesUris
+ */
+ public function test($uri, array $plugins) {
+ /** @var IRequest | \PHPUnit_Framework_MockObject_MockObject $r */
$r = $this->createMock(IRequest::class);
- $r->method('getRequestUri')
- ->willReturn('/');
+ $r->expects($this->any())->method('getRequestUri')->willReturn($uri);
$s = new Server($r, '/');
- $this->assertInstanceOf('OCA\DAV\Server', $s);
+ $this->assertNotNull($s->server);
+ foreach ($plugins as $plugin) {
+ $this->assertNotNull($s->server->getPlugin($plugin));
+ }
+ }
+ public function providesUris() {
+ return [
+ 'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']],
+ 'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']],
+ 'addressbooks' => ['addressbooks/admin', ['carddav', 'oc-resource-sharing']],
+ ];
}
}