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/Activity/BackendTest.php34
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php84
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php110
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php84
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php189
-rw-r--r--apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php121
-rw-r--r--apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php179
7 files changed, 784 insertions, 17 deletions
diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
index 3585d69bad3..d8d15e8f1f7 100644
--- a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
@@ -22,7 +22,7 @@
namespace OCA\DAV\Tests\unit\CalDAV\Activity;
use OCA\DAV\CalDAV\Activity\Backend;
-use OCA\DAV\CalDAV\Activity\Extension;
+use OCA\DAV\CalDAV\Activity\Provider\Calendar;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IGroup;
@@ -74,9 +74,9 @@ class BackendTest extends TestCase {
public function dataCallTriggerCalendarActivity() {
return [
- ['onCalendarAdd', [['data']], Extension::SUBJECT_ADD, [['data'], [], []]],
- ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Extension::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
- ['onCalendarDelete', [['data'], ['shares']], Extension::SUBJECT_DELETE, [['data'], ['shares'], []]],
+ ['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]],
+ ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]],
+ ['onCalendarDelete', [['data'], ['shares']], Calendar::SUBJECT_DELETE, [['data'], ['shares'], []]],
];
}
@@ -104,51 +104,51 @@ class BackendTest extends TestCase {
public function dataTriggerCalendarActivity() {
return [
// Add calendar
- [Extension::SUBJECT_ADD, [], [], [], '', '', null, []],
- [Extension::SUBJECT_ADD, [
+ [Calendar::SUBJECT_ADD, [], [], [], '', '', null, []],
+ [Calendar::SUBJECT_ADD, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], [], [], '', 'admin', null, ['admin']],
- [Extension::SUBJECT_ADD, [
+ [Calendar::SUBJECT_ADD, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], [], [], 'test2', 'test2', null, ['admin']],
// Update calendar
- [Extension::SUBJECT_UPDATE, [], [], [], '', '', null, []],
+ [Calendar::SUBJECT_UPDATE, [], [], [], '', '', null, []],
// No visible change - owner only
- [Extension::SUBJECT_UPDATE, [
+ [Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', null, ['admin']],
// Visible change
- [Extension::SUBJECT_UPDATE, [
+ [Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], ['{DAV:}displayname' => 'Name'], '', 'admin', ['user1'], ['user1', 'admin']],
- [Extension::SUBJECT_UPDATE, [
+ [Calendar::SUBJECT_UPDATE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], ['{DAV:}displayname' => 'Name'], 'test2', 'test2', ['user1'], ['user1', 'admin']],
// Delete calendar
- [Extension::SUBJECT_DELETE, [], [], [], '', '', null, []],
- [Extension::SUBJECT_DELETE, [
+ [Calendar::SUBJECT_DELETE, [], [], [], '', '', null, []],
+ [Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', [], ['admin']],
- [Extension::SUBJECT_DELETE, [
+ [Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
], ['shares'], [], '', 'admin', ['user1'], ['user1', 'admin']],
- [Extension::SUBJECT_DELETE, [
+ [Calendar::SUBJECT_DELETE, [
'principaluri' => 'principal/user/admin',
'id' => 42,
'{DAV:}displayname' => 'Name of calendar',
@@ -202,11 +202,11 @@ class BackendTest extends TestCase {
->willReturnSelf();
$event->expects($this->once())
->method('setObject')
- ->with(Extension::CALENDAR, $data['id'])
+ ->with('calendar', $data['id'])
->willReturnSelf();
$event->expects($this->once())
->method('setType')
- ->with(Extension::CALENDAR)
+ ->with('calendar')
->willReturnSelf();
$event->expects($this->once())
->method('setAuthor')
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php
new file mode 100644
index 00000000000..895a404acf5
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity\Filter;
+
+use OCA\DAV\CalDAV\Activity\Filter\Calendar;
+use OCP\Activity\IFilter;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use Test\TestCase;
+
+class CalendarTest extends TestCase {
+
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $url;
+
+ /** @var IFilter|\PHPUnit_Framework_MockObject_MockObject */
+ protected $filter;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->url = $this->createMock(IURLGenerator::class);
+ $l = $this->createMock(IL10N::class);
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function($string, $args) {
+ return vsprintf($string, $args);
+ });
+
+ $this->filter = new Calendar(
+ $l, $this->url
+ );
+ }
+
+ public function testGetIcon() {
+ $this->url->expects($this->once())
+ ->method('imagePath')
+ ->with('core', 'places/calendar-dark.svg')
+ ->willReturn('path-to-icon');
+
+ $this->url->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('path-to-icon')
+ ->willReturn('absolute-path-to-icon');
+
+ $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon());
+ }
+
+ public function dataFilterTypes() {
+ return [
+ [[], []],
+ [['calendar', 'calendar_event'], ['calendar', 'calendar_event']],
+ [['calendar', 'calendar_event', 'calendar_todo'], ['calendar', 'calendar_event']],
+ [['calendar', 'calendar_event', 'files'], ['calendar', 'calendar_event']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataFilterTypes
+ * @param string[] $types
+ * @param string[] $expected
+ */
+ public function testFilterTypes($types, $expected) {
+ $this->assertEquals($expected, $this->filter->filterTypes($types));
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php
new file mode 100644
index 00000000000..533f88747cd
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity\Filter;
+
+use OCA\DAV\CalDAV\Activity\Filter\Calendar;
+use OCA\DAV\CalDAV\Activity\Filter\Todo;
+use OCP\Activity\IFilter;
+use Test\TestCase;
+
+class GenericTest extends TestCase {
+
+ public function dataFilters() {
+ return [
+ [Calendar::class],
+ [Todo::class],
+ ];
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testImplementsInterface($filterClass) {
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInstanceOf(IFilter::class, $filter);
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testGetIdentifier($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInternalType('string', $filter->getIdentifier());
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testGetName($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInternalType('string', $filter->getName());
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testGetPriority($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $priority = $filter->getPriority();
+ $this->assertInternalType('int', $filter->getPriority());
+ $this->assertGreaterThanOrEqual(0, $priority);
+ $this->assertLessThanOrEqual(100, $priority);
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testGetIcon($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInternalType('string', $filter->getIcon());
+ $this->assertStringStartsWith('http', $filter->getIcon());
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testFilterTypes($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInternalType('array', $filter->filterTypes([]));
+ }
+
+ /**
+ * @dataProvider dataFilters
+ * @param string $filterClass
+ */
+ public function testAllowedApps($filterClass) {
+ /** @var IFilter $filter */
+ $filter = \OC::$server->query($filterClass);
+ $this->assertInternalType('array', $filter->allowedApps());
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php
new file mode 100644
index 00000000000..3c6ac2a5c55
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity\Filter;
+
+use OCA\DAV\CalDAV\Activity\Filter\Todo;
+use OCP\Activity\IFilter;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use Test\TestCase;
+
+class TodoTest extends TestCase {
+
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $url;
+
+ /** @var IFilter|\PHPUnit_Framework_MockObject_MockObject */
+ protected $filter;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->url = $this->createMock(IURLGenerator::class);
+ $l = $this->createMock(IL10N::class);
+ $l->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function($string, $args) {
+ return vsprintf($string, $args);
+ });
+
+ $this->filter = new Todo(
+ $l, $this->url
+ );
+ }
+
+ public function testGetIcon() {
+ $this->url->expects($this->once())
+ ->method('imagePath')
+ ->with('core', 'actions/checkmark.svg')
+ ->willReturn('path-to-icon');
+
+ $this->url->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with('path-to-icon')
+ ->willReturn('absolute-path-to-icon');
+
+ $this->assertEquals('absolute-path-to-icon', $this->filter->getIcon());
+ }
+
+ public function dataFilterTypes() {
+ return [
+ [[], []],
+ [['calendar_todos'], ['calendar_todos']],
+ [['calendar', 'calendar_event', 'calendar_todos'], ['calendar_todos']],
+ [['calendar', 'calendar_todos', 'files'], ['calendar_todos']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataFilterTypes
+ * @param string[] $types
+ * @param string[] $expected
+ */
+ public function testFilterTypes($types, $expected) {
+ $this->assertEquals($expected, $this->filter->filterTypes($types));
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
new file mode 100644
index 00000000000..85eb439f100
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php
@@ -0,0 +1,189 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity\Provider;
+
+use OCA\DAV\CalDAV\Activity\Provider\Base;
+use OCP\Activity\IEvent;
+use OCP\Activity\IProvider;
+use OCP\IUser;
+use OCP\IUserManager;
+use Test\TestCase;
+
+class BaseTest extends TestCase {
+
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
+
+ /** @var IProvider|Base|\PHPUnit_Framework_MockObject_MockObject */
+ protected $provider;
+
+ protected function setUp() {
+ parent::setUp();
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->provider = $this->getMockBuilder(Base::class)
+ ->setConstructorArgs([
+ $this->userManager
+ ])
+ ->setMethods(['parse'])
+ ->getMock();
+ }
+
+ public function dataSetSubjects() {
+ return [
+ ['abc', [], 'abc'],
+ ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']], 'abc created xyz'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataSetSubjects
+ * @param string $subject
+ * @param array $parameters
+ * @param string $parsedSubject
+ */
+ public function testSetSubjects($subject, array $parameters, $parsedSubject) {
+ $event = $this->createMock(IEvent::class);
+ $event->expects($this->once())
+ ->method('setRichSubject')
+ ->with($subject, $parameters)
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setParsedSubject')
+ ->with($parsedSubject)
+ ->willReturnSelf();
+
+ $this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]);
+ }
+
+ public function dataGenerateObjectParameter() {
+ return [
+ [23, 'c1'],
+ [42, 'c2'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGenerateObjectParameter
+ * @param int $id
+ * @param string $name
+ */
+ public function testGenerateObjectParameter($id, $name) {
+ $this->assertEquals([
+ 'type' => 'calendar-event',
+ 'id' => $id,
+ 'name' => $name,
+ ], $this->invokePrivate($this->provider, 'generateObjectParameter', [['id' => $id, 'name' => $name]]));
+ }
+
+ public function dataGenerateObjectParameterThrows() {
+ return [
+ ['event'],
+ [['name' => 'event']],
+ [['id' => 42]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGenerateObjectParameterThrows
+ * @expectedException \InvalidArgumentException
+ * @param mixed $eventData
+ */
+ public function testGenerateObjectParameterThrows($eventData) {
+ $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData]);
+ }
+
+ public function dataGenerateCalendarParameter() {
+ return [
+ [23, 'c1'],
+ [42, 'c2'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGenerateCalendarParameter
+ * @param int $id
+ * @param string $name
+ */
+ public function testGenerateCalendarParameter($id, $name) {
+ $this->assertEquals([
+ 'type' => 'calendar',
+ 'id' => $id,
+ 'name' => $name,
+ ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$id, $name]));
+ }
+
+ public function dataGenerateGroupParameter() {
+ return [
+ ['g1'],
+ ['g2'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGenerateGroupParameter
+ * @param string $gid
+ */
+ public function testGenerateGroupParameter($gid) {
+ $this->assertEquals([
+ 'type' => 'group',
+ 'id' => $gid,
+ 'name' => $gid,
+ ], $this->invokePrivate($this->provider, 'generateGroupParameter', [$gid]));
+ }
+
+ public function dataGenerateUserParameter() {
+ $u1 = $this->createMock(IUser::class);
+ $u1->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('User 1');
+ return [
+ ['u1', 'User 1', $u1],
+ ['u2', 'u2', null],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGenerateUserParameter
+ * @param string $uid
+ * @param string $displayName
+ * @param IUser|null $user
+ */
+ public function testGenerateUserParameter($uid, $displayName, $user) {
+ $this->userManager->expects($this->once())
+ ->method('get')
+ ->with($uid)
+ ->willReturn($user);
+
+ $this->assertEquals([
+ 'type' => 'user',
+ 'id' => $uid,
+ 'name' => $displayName,
+ ], $this->invokePrivate($this->provider, 'generateUserParameter', [$uid]));
+
+ // Test caching (only 1 user manager invocation allowed)
+ $this->assertEquals([
+ 'type' => 'user',
+ 'id' => $uid,
+ 'name' => $displayName,
+ ], $this->invokePrivate($this->provider, 'generateUserParameter', [$uid]));
+ }
+}
diff --git a/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php
new file mode 100644
index 00000000000..54c7a54baf7
--- /dev/null
+++ b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Tests\unit\CalDAV\Activity\Setting;
+
+use OCA\DAV\CalDAV\Activity\Setting\Calendar;
+use OCA\DAV\CalDAV\Activity\Setting\Event;
+use OCA\DAV\CalDAV\Activity\Setting\Todo;
+use OCP\Activity\ISetting;
+use Test\TestCase;
+
+class GenericTest extends TestCase {
+
+ public function dataSettings() {
+ return [
+ [Calendar::class],
+ [Event::class],
+ [Todo::class],
+ ];
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testImplementsInterface($settingClass) {
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInstanceOf(ISetting::class, $setting);
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testGetIdentifier($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('string', $setting->getIdentifier());
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testGetName($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('string', $setting->getName());
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testGetPriority($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $priority = $setting->getPriority();
+ $this->assertInternalType('int', $setting->getPriority());
+ $this->assertGreaterThanOrEqual(0, $priority);
+ $this->assertLessThanOrEqual(100, $priority);
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testCanChangeStream($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('bool', $setting->canChangeStream());
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testIsDefaultEnabledStream($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('bool', $setting->isDefaultEnabledStream());
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testCanChangeMail($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('bool', $setting->canChangeMail());
+ }
+
+ /**
+ * @dataProvider dataSettings
+ * @param string $settingClass
+ */
+ public function testIsDefaultEnabledMail($settingClass) {
+ /** @var ISetting $setting */
+ $setting = \OC::$server->query($settingClass);
+ $this->assertInternalType('bool', $setting->isDefaultEnabledMail());
+ }
+}
diff --git a/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php
new file mode 100644
index 00000000000..e2990f27b60
--- /dev/null
+++ b/apps/dav/tests/unit/Files/Sharing/FilesDropPluginTest.php
@@ -0,0 +1,179 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\DAV\Tests\Files\Sharing;
+
+use OC\Files\View;
+use OCA\DAV\Files\Sharing\FilesDropPlugin;
+use Sabre\DAV\Exception\MethodNotAllowed;
+use Sabre\DAV\Server;
+use Sabre\HTTP\RequestInterface;
+use Sabre\HTTP\ResponseInterface;
+use Test\TestCase;
+
+class FilesDropPluginTest extends TestCase {
+
+ /** @var View|\PHPUnit_Framework_MockObject_MockObject */
+ private $view;
+
+ /** @var Server|\PHPUnit_Framework_MockObject_MockObject */
+ private $server;
+
+ /** @var FilesDropPlugin */
+ private $plugin;
+
+ /** @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
+ /** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
+ private $response;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->view = $this->createMock(View::class);
+ $this->server = $this->createMock(Server::class);
+ $this->plugin = new FilesDropPlugin();
+
+ $this->request = $this->createMock(RequestInterface::class);
+ $this->response = $this->createMock(ResponseInterface::class);
+
+ $this->response->expects($this->never())
+ ->method($this->anything());
+ }
+
+ public function testInitialize() {
+ $this->server->expects($this->once())
+ ->method('on')
+ ->with(
+ $this->equalTo('beforeMethod'),
+ $this->equalTo([$this->plugin, 'beforeMethod']),
+ $this->equalTo(999)
+ );
+
+ $this->plugin->initialize($this->server);
+ }
+
+ public function testNotEnabled() {
+ $this->view->expects($this->never())
+ ->method($this->anything());
+
+ $this->request->expects($this->never())
+ ->method($this->anything());
+
+ $this->plugin->beforeMethod($this->request, $this->response);
+ }
+
+ public function testValid() {
+ $this->plugin->enable();
+ $this->plugin->setView($this->view);
+
+ $this->request->method('getMethod')
+ ->willReturn('PUT');
+
+ $this->request->method('getPath')
+ ->willReturn('file.txt');
+
+ $this->request->method('getBaseUrl')
+ ->willReturn('https://example.com');
+
+ $this->view->method('file_exists')
+ ->with('/file.txt')
+ ->willReturn(false);
+
+ $this->request->expects($this->once())
+ ->method('setUrl')
+ ->with('https://example.com/file.txt');
+
+ $this->plugin->beforeMethod($this->request, $this->response);
+ }
+
+ public function testFileAlreadyExistsValid() {
+ $this->plugin->enable();
+ $this->plugin->setView($this->view);
+
+ $this->request->method('getMethod')
+ ->willReturn('PUT');
+
+ $this->request->method('getPath')
+ ->willReturn('file.txt');
+
+ $this->request->method('getBaseUrl')
+ ->willReturn('https://example.com');
+
+ $this->view->method('file_exists')
+ ->will($this->returnCallback(function($path) {
+ if ($path === 'file.txt' || $path === '/file.txt') {
+ return true;
+ } else {
+ return false;
+ }
+ }));
+
+ $this->request->expects($this->once())
+ ->method('setUrl')
+ ->with($this->equalTo('https://example.com/file (2).txt'));
+
+ $this->plugin->beforeMethod($this->request, $this->response);
+ }
+
+ public function testNoMKCOL() {
+ $this->plugin->enable();
+ $this->plugin->setView($this->view);
+
+ $this->request->method('getMethod')
+ ->willReturn('MKCOL');
+
+ $this->expectException(MethodNotAllowed::class);
+
+ $this->plugin->beforeMethod($this->request, $this->response);
+ }
+
+ public function testNoSubdirPut() {
+ $this->plugin->enable();
+ $this->plugin->setView($this->view);
+
+ $this->request->method('getMethod')
+ ->willReturn('PUT');
+
+ $this->request->method('getPath')
+ ->willReturn('folder/file.txt');
+
+ $this->request->method('getBaseUrl')
+ ->willReturn('https://example.com');
+
+ $this->view->method('file_exists')
+ ->will($this->returnCallback(function($path) {
+ if ($path === 'file.txt' || $path === '/file.txt') {
+ return true;
+ } else {
+ return false;
+ }
+ }));
+
+ $this->request->expects($this->once())
+ ->method('setUrl')
+ ->with($this->equalTo('https://example.com/file (2).txt'));
+
+ $this->plugin->beforeMethod($this->request, $this->response);
+ }
+}