summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r--apps/dav/tests/unit/caldav/caldavbackendtest.php13
-rw-r--r--apps/dav/tests/unit/caldav/calendartest.php24
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesplugin.php92
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesreportplugin.php10
-rw-r--r--apps/dav/tests/unit/connector/sabre/node.php36
-rw-r--r--apps/dav/tests/unit/dav/HookManagerTest.php71
-rw-r--r--apps/dav/tests/unit/migration/addressbookadaptertest.php129
-rw-r--r--apps/dav/tests/unit/migration/calendar_schema.xml191
-rw-r--r--apps/dav/tests/unit/migration/calendaradaptertest.php131
-rw-r--r--apps/dav/tests/unit/migration/contacts_schema.xml151
-rw-r--r--apps/dav/tests/unit/migration/migrateaddressbooktest.php81
-rw-r--r--apps/dav/tests/unit/migration/migratecalendartest.php85
-rw-r--r--apps/dav/tests/unit/upload/assemblystreamtest.php47
-rw-r--r--apps/dav/tests/unit/upload/futurefiletest.php89
14 files changed, 337 insertions, 813 deletions
diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php
index 87a700a473d..a4a19f5bd3e 100644
--- a/apps/dav/tests/unit/caldav/caldavbackendtest.php
+++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php
@@ -136,14 +136,23 @@ class CalDavBackendTest extends TestCase {
*/
public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) {
+ $l10n = $this->getMockBuilder('\OCP\IL10N')
+ ->disableOriginalConstructor()->getMock();
+ $l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function ($text, $parameters = array()) {
+ return vsprintf($text, $parameters);
+ }));
+
$calendarId = $this->createTestCalendar();
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));
- $calendar = new Calendar($this->backend, $books[0]);
+ $calendar = new Calendar($this->backend, $books[0], $l10n);
$this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books));
- $calendar = new Calendar($this->backend, $books[0]);
+ $calendar = new Calendar($this->backend, $books[0], $l10n);
$acl = $calendar->getACL();
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
diff --git a/apps/dav/tests/unit/caldav/calendartest.php b/apps/dav/tests/unit/caldav/calendartest.php
index 9e0c3c6c7e4..812e0074d15 100644
--- a/apps/dav/tests/unit/caldav/calendartest.php
+++ b/apps/dav/tests/unit/caldav/calendartest.php
@@ -23,11 +23,27 @@ namespace OCA\DAV\Tests\Unit\CalDAV;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Calendar;
+use OCP\IL10N;
use Sabre\DAV\PropPatch;
use Test\TestCase;
class CalendarTest extends TestCase {
+ /** @var IL10N */
+ private $l10n;
+
+ public function setUp() {
+ parent::setUp();
+ $this->l10n = $this->getMockBuilder('\OCP\IL10N')
+ ->disableOriginalConstructor()->getMock();
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->will($this->returnCallback(function ($text, $parameters = array()) {
+ return vsprintf($text, $parameters);
+ }));
+ }
+
public function testDelete() {
/** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
@@ -41,7 +57,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete();
}
@@ -61,7 +77,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n);
$c->delete();
}
@@ -93,7 +109,7 @@ class CalendarTest extends TestCase {
'id' => 666,
'uri' => 'default'
];
- $c = new Calendar($backend, $calendarInfo);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n);
if ($throws) {
$this->setExpectedException('\Sabre\DAV\Exception\Forbidden');
@@ -122,7 +138,7 @@ class CalendarTest extends TestCase {
if ($hasOwnerSet) {
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
}
- $c = new Calendar($backend, $calendarInfo);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n);
$acl = $c->getACL();
$childAcl = $c->getChildACL();
diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php
index fb08ee170c4..fb5d658b39c 100644
--- a/apps/dav/tests/unit/connector/sabre/filesplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php
@@ -23,6 +23,9 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
use OCP\Files\StorageNotAvailableException;
+use Sabre\DAV\PropFind;
+use Sabre\DAV\PropPatch;
+use Test\TestCase;
/**
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
@@ -30,7 +33,7 @@ use OCP\Files\StorageNotAvailableException;
* later.
* See the COPYING-README file.
*/
-class FilesPlugin extends \Test\TestCase {
+class FilesPlugin extends TestCase {
const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME;
const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME;
const INTERNAL_FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::INTERNAL_FILEID_PROPERTYNAME;
@@ -40,14 +43,15 @@ class FilesPlugin extends \Test\TestCase {
const DOWNLOADURL_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME;
const OWNER_ID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_ID_PROPERTYNAME;
const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
+ const DATA_FINGERPRINT_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME;
/**
- * @var \Sabre\DAV\Server
+ * @var \Sabre\DAV\Server | \PHPUnit_Framework_MockObject_MockObject
*/
private $server;
/**
- * @var \Sabre\DAV\Tree
+ * @var \Sabre\DAV\Tree | \PHPUnit_Framework_MockObject_MockObject
*/
private $tree;
@@ -57,10 +61,15 @@ class FilesPlugin extends \Test\TestCase {
private $plugin;
/**
- * @var \OC\Files\View
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject
*/
private $view;
+ /**
+ * @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $config;
+
public function setUp() {
parent::setUp();
$this->server = $this->getMockBuilder('\Sabre\DAV\Server')
@@ -72,13 +81,22 @@ class FilesPlugin extends \Test\TestCase {
$this->view = $this->getMockBuilder('\OC\Files\View')
->disableOriginalConstructor()
->getMock();
-
- $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view);
+ $this->config = $this->getMock('\OCP\IConfig');
+ $this->config->method('getSystemValue')
+ ->with($this->equalTo('data-fingerprint'), $this->equalTo(''))
+ ->willReturn('my_fingerprint');
+
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $this->config
+ );
$this->plugin->initialize($this->server);
}
/**
* @param string $class
+ * @return \PHPUnit_Framework_MockObject_MockObject
*/
private function createTestNode($class) {
$node = $this->getMockBuilder($class)
@@ -111,9 +129,10 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesForFile() {
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -123,7 +142,8 @@ class FilesPlugin extends \Test\TestCase {
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
self::OWNER_ID_PROPERTYNAME,
- self::OWNER_DISPLAY_NAME_PROPERTYNAME
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -161,15 +181,16 @@ class FilesPlugin extends \Test\TestCase {
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
$this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
$this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
- $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
+ $this->assertEquals([self::SIZE_PROPERTYNAME, self::DATA_FINGERPRINT_PROPERTYNAME], $propFind->get404Properties());
}
public function testGetPropertiesForFileHome() {
+ /** @var \OCA\DAV\Files\FilesHome | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->getMockBuilder('\OCA\DAV\Files\FilesHome')
->disableOriginalConstructor()
->getMock();
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -179,7 +200,8 @@ class FilesPlugin extends \Test\TestCase {
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
self::OWNER_ID_PROPERTYNAME,
- self::OWNER_DISPLAY_NAME_PROPERTYNAME
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -211,12 +233,14 @@ class FilesPlugin extends \Test\TestCase {
'{http://owncloud.org/ns}owner-id',
'{http://owncloud.org/ns}owner-display-name'
], $propFind->get404Properties());
+ $this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
}
public function testGetPropertiesStorageNotAvailable() {
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::DOWNLOADURL_PROPERTYNAME,
@@ -237,10 +261,14 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPublicPermissions() {
- $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $this->config,
+ true);
$this->plugin->initialize($this->server);
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
[
self::PERMISSIONS_PROPERTYNAME,
@@ -248,6 +276,7 @@ class FilesPlugin extends \Test\TestCase {
0
);
+ /** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
$node->expects($this->any())
->method('getDavPermissions')
@@ -262,9 +291,10 @@ class FilesPlugin extends \Test\TestCase {
}
public function testGetPropertiesForDirectory() {
+ /** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
$node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
- $propFind = new \Sabre\DAV\PropFind(
+ $propFind = new PropFind(
'/dummyPath',
array(
self::GETETAG_PROPERTYNAME,
@@ -272,6 +302,7 @@ class FilesPlugin extends \Test\TestCase {
self::SIZE_PROPERTYNAME,
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
+ self::DATA_FINGERPRINT_PROPERTYNAME,
),
0
);
@@ -290,7 +321,30 @@ class FilesPlugin extends \Test\TestCase {
$this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME));
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
$this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
- $this->assertEquals(array(self::DOWNLOADURL_PROPERTYNAME), $propFind->get404Properties());
+ $this->assertEquals([self::DOWNLOADURL_PROPERTYNAME, self::DATA_FINGERPRINT_PROPERTYNAME], $propFind->get404Properties());
+ }
+
+ public function testGetPropertiesForRootDirectory() {
+ /** @var \OCA\DAV\Connector\Sabre\Directory | \PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->method('getPath')->willReturn('/');
+
+ $propFind = new PropFind(
+ '/',
+ [
+ self::DATA_FINGERPRINT_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('my_fingerprint', $propFind->get(self::DATA_FINGERPRINT_PROPERTYNAME));
}
public function testUpdateProps() {
@@ -308,7 +362,7 @@ class FilesPlugin extends \Test\TestCase {
->will($this->returnValue(true));
// properties to set
- $propPatch = new \Sabre\DAV\PropPatch(array(
+ $propPatch = new PropPatch(array(
self::GETETAG_PROPERTYNAME => 'newetag',
self::LASTMODIFIED_PROPERTYNAME => $testDate
));
@@ -328,9 +382,7 @@ class FilesPlugin extends \Test\TestCase {
}
public function testUpdatePropsForbidden() {
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
-
- $propPatch = new \Sabre\DAV\PropPatch(array(
+ $propPatch = new PropPatch(array(
self::OWNER_ID_PROPERTYNAME => 'user2',
self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
self::FILEID_PROPERTYNAME => 12345,
diff --git a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
index 87973ef0071..ffe1a19ee56 100644
--- a/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesreportplugin.php
@@ -336,7 +336,15 @@ class FilesReportPlugin extends \Test\TestCase {
->method('getSize')
->will($this->returnValue(1024));
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view));
+ $config = $this->getMock('\OCP\IConfig');
+
+ $this->server->addPlugin(
+ new \OCA\DAV\Connector\Sabre\FilesPlugin(
+ $this->tree,
+ $this->view,
+ $config
+ )
+ );
$this->plugin->initialize($this->server);
$responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]);
diff --git a/apps/dav/tests/unit/connector/sabre/node.php b/apps/dav/tests/unit/connector/sabre/node.php
index cde8e746dc3..6fdf77adc21 100644
--- a/apps/dav/tests/unit/connector/sabre/node.php
+++ b/apps/dav/tests/unit/connector/sabre/node.php
@@ -66,14 +66,14 @@ class Node extends \Test\TestCase {
public function sharePermissionsProvider() {
return [
- [\OCP\Files\FileInfo::TYPE_FILE, 1, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 3, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 5, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 7, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 9, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 11, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 13, 0],
- [\OCP\Files\FileInfo::TYPE_FILE, 15, 0],
+ [\OCP\Files\FileInfo::TYPE_FILE, 1, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, 3, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, 5, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, 7, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, 9, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, 11, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, 13, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, 15, 3],
[\OCP\Files\FileInfo::TYPE_FILE, 17, 17],
[\OCP\Files\FileInfo::TYPE_FILE, 19, 19],
[\OCP\Files\FileInfo::TYPE_FILE, 21, 17],
@@ -81,16 +81,16 @@ class Node extends \Test\TestCase {
[\OCP\Files\FileInfo::TYPE_FILE, 25, 17],
[\OCP\Files\FileInfo::TYPE_FILE, 27, 19],
[\OCP\Files\FileInfo::TYPE_FILE, 29, 17],
- [\OCP\Files\FileInfo::TYPE_FILE, 30, 0],
+ [\OCP\Files\FileInfo::TYPE_FILE, 30, 18],
[\OCP\Files\FileInfo::TYPE_FILE, 31, 19],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 1, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 3, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 5, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 7, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 9, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 11, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 13, 0],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 15, 0],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 1, 1],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 3, 3],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 5, 5],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 7, 7],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 9, 9],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 11, 11],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 13, 13],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 15, 15],
[\OCP\Files\FileInfo::TYPE_FOLDER, 17, 17],
[\OCP\Files\FileInfo::TYPE_FOLDER, 19, 19],
[\OCP\Files\FileInfo::TYPE_FOLDER, 21, 21],
@@ -98,7 +98,7 @@ class Node extends \Test\TestCase {
[\OCP\Files\FileInfo::TYPE_FOLDER, 25, 25],
[\OCP\Files\FileInfo::TYPE_FOLDER, 27, 27],
[\OCP\Files\FileInfo::TYPE_FOLDER, 29, 29],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 30, 0],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 30, 30],
[\OCP\Files\FileInfo::TYPE_FOLDER, 31, 31],
];
}
diff --git a/apps/dav/tests/unit/dav/HookManagerTest.php b/apps/dav/tests/unit/dav/HookManagerTest.php
new file mode 100644
index 00000000000..bec4c240ce8
--- /dev/null
+++ b/apps/dav/tests/unit/dav/HookManagerTest.php
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\DAV;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\CardDAV\SyncService;
+use OCA\DAV\HookManager;
+use OCP\IUserManager;
+use Test\TestCase;
+
+class HookManagerTest extends TestCase {
+ public function test() {
+ $user = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $user->expects($this->once())->method('getUID')->willReturn('newUser');
+
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject $userManager */
+ $userManager = $this->getMockBuilder('\OCP\IUserManager')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $userManager->expects($this->once())->method('get')->willReturn($user);
+
+ /** @var SyncService | \PHPUnit_Framework_MockObject_MockObject $syncService */
+ $syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cal */
+ $cal = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $cal->expects($this->once())->method('getCalendarsForUser')->willReturn([]);
+ $cal->expects($this->once())->method('createCalendar')->with(
+ 'principals/users/newUser',
+ 'personal', ['{DAV:}displayname' => 'Personal']);
+
+ /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $card */
+ $card = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $card->expects($this->once())->method('getAddressBooksForUser')->willReturn([]);
+ $card->expects($this->once())->method('createAddressBook')->with(
+ 'principals/users/newUser',
+ 'contacts', ['{DAV:}displayname' => 'Contacts']);
+
+ $hm = new HookManager($userManager, $syncService, $cal, $card);
+ $hm->postLogin(['uid' => 'newUser']);
+ }
+}
diff --git a/apps/dav/tests/unit/migration/addressbookadaptertest.php b/apps/dav/tests/unit/migration/addressbookadaptertest.php
deleted file mode 100644
index e6e57049a93..00000000000
--- a/apps/dav/tests/unit/migration/addressbookadaptertest.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-/**
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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\Migration;
-
-use DomainException;
-use OCA\Dav\Migration\AddressBookAdapter;
-use OCP\IDBConnection;
-use Test\TestCase;
-
-/**
- * Class AddressbookAdapterTest
- *
- * @group DB
- *
- * @package OCA\DAV\Tests\Unit\Migration
- */
-class AddressbookAdapterTest extends TestCase {
-
- /** @var IDBConnection */
- private $db;
- /** @var AddressBookAdapter */
- private $adapter;
- /** @var array */
- private $books = [];
- /** @var array */
- private $cards = [];
-
- public function setUp() {
- parent::setUp();
- $this->db = \OC::$server->getDatabaseConnection();
-
- $manager = new \OC\DB\MDB2SchemaManager($this->db);
- $manager->createDbFromStructure(__DIR__ . '/contacts_schema.xml');
-
- $this->adapter = new AddressBookAdapter($this->db);
- }
-
- public function tearDown() {
- $this->db->dropTable('contacts_addressbooks');
- $this->db->dropTable('contacts_cards');
- parent::tearDown();
- }
-
- /**
- * @expectedException DomainException
- */
- public function testOldTablesDoNotExist() {
- $adapter = new AddressBookAdapter(\OC::$server->getDatabaseConnection(), 'crazy_table_that_does_no_exist');
- $adapter->setup();
- }
-
- public function test() {
-
- // insert test data
- $builder = $this->db->getQueryBuilder();
- $builder->insert('contacts_addressbooks')
- ->values([
- 'userid' => $builder->createNamedParameter('test-user-666'),
- 'displayname' => $builder->createNamedParameter('Display Name'),
- 'uri' => $builder->createNamedParameter('contacts'),
- 'description' => $builder->createNamedParameter('An address book for testing'),
- 'ctag' => $builder->createNamedParameter('112233'),
- 'active' => $builder->createNamedParameter('1')
- ])
- ->execute();
- $builder = $this->db->getQueryBuilder();
- $builder->insert('contacts_cards')
- ->values([
- 'addressbookid' => $builder->createNamedParameter(6666),
- 'fullname' => $builder->createNamedParameter('Full Name'),
- 'carddata' => $builder->createNamedParameter('datadatadata'),
- 'uri' => $builder->createNamedParameter('some-card.vcf'),
- 'lastmodified' => $builder->createNamedParameter('112233'),
- ])
- ->execute();
- $builder = $this->db->getQueryBuilder();
- $builder->insert('share')
- ->values([
- 'share_type' => $builder->createNamedParameter(1),
- 'share_with' => $builder->createNamedParameter('user01'),
- 'uid_owner' => $builder->createNamedParameter('user02'),
- 'item_type' => $builder->createNamedParameter('addressbook'),
- 'item_source' => $builder->createNamedParameter(6666),
- 'item_target' => $builder->createNamedParameter('Contacts (user02)'),
- ])
- ->execute();
-
- // test the adapter
- $this->adapter->foreachBook('test-user-666', function($row) {
- $this->books[] = $row;
- });
- $this->assertArrayHasKey('id', $this->books[0]);
- $this->assertEquals('test-user-666', $this->books[0]['userid']);
- $this->assertEquals('Display Name', $this->books[0]['displayname']);
- $this->assertEquals('contacts', $this->books[0]['uri']);
- $this->assertEquals('An address book for testing', $this->books[0]['description']);
- $this->assertEquals('112233', $this->books[0]['ctag']);
-
- $this->adapter->foreachCard(6666, function($row) {
- $this->cards[]= $row;
- });
- $this->assertArrayHasKey('id', $this->cards[0]);
- $this->assertEquals(6666, $this->cards[0]['addressbookid']);
-
- // test getShares
- $shares = $this->adapter->getShares(6666);
- $this->assertEquals(1, count($shares));
-
- }
-
-}
diff --git a/apps/dav/tests/unit/migration/calendar_schema.xml b/apps/dav/tests/unit/migration/calendar_schema.xml
deleted file mode 100644
index 6c88b596a3f..00000000000
--- a/apps/dav/tests/unit/migration/calendar_schema.xml
+++ /dev/null
@@ -1,191 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<database>
-
- <name>*dbname*</name>
- <create>true</create>
- <overwrite>false</overwrite>
-
- <charset>utf8</charset>
-
- <table>
-
- <name>*dbprefix*clndr_objects</name>
-
- <declaration>
-
- <field>
- <name>id</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <autoincrement>1</autoincrement>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>calendarid</name>
- <type>integer</type>
- <default></default>
- <notnull>true</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>objecttype</name>
- <type>text</type>
- <default></default>
- <notnull>true</notnull>
- <length>40</length>
- </field>
-
- <field>
- <name>startdate</name>
- <type>timestamp</type>
- <default>1970-01-01 00:00:00</default>
- <notnull>false</notnull>
- </field>
-
- <field>
- <name>enddate</name>
- <type>timestamp</type>
- <default>1970-01-01 00:00:00</default>
- <notnull>false</notnull>
- </field>
-
- <field>
- <name>repeating</name>
- <type>integer</type>
- <default></default>
- <notnull>false</notnull>
- <length>4</length>
- </field>
-
- <field>
- <name>summary</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>calendardata</name>
- <type>clob</type>
- <notnull>false</notnull>
- </field>
-
- <field>
- <name>uri</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>lastmodified</name>
- <type>integer</type>
- <default></default>
- <notnull>false</notnull>
- <length>4</length>
- </field>
-
- </declaration>
-
- </table>
-
- <table>
-
- <name>*dbprefix*clndr_calendars</name>
-
- <declaration>
-
- <field>
- <name>id</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <autoincrement>1</autoincrement>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>userid</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>displayname</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>100</length>
- </field>
-
- <field>
- <name>uri</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>active</name>
- <type>integer</type>
- <default>1</default>
- <notnull>true</notnull>
- <length>4</length>
- </field>
-
- <field>
- <name>ctag</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>calendarorder</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>calendarcolor</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>10</length>
- </field>
-
- <field>
- <name>timezone</name>
- <type>clob</type>
- <notnull>false</notnull>
- </field>
-
- <field>
- <name>components</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>100</length>
- </field>
-
- </declaration>
-
- </table>
-
-</database>
diff --git a/apps/dav/tests/unit/migration/calendaradaptertest.php b/apps/dav/tests/unit/migration/calendaradaptertest.php
deleted file mode 100644
index f92774ef6ad..00000000000
--- a/apps/dav/tests/unit/migration/calendaradaptertest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/**
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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\Migration;
-
-use DomainException;
-use OCA\Dav\Migration\AddressBookAdapter;
-use OCA\Dav\Migration\CalendarAdapter;
-use OCP\IDBConnection;
-use Test\TestCase;
-
-/**
- * Class CalendarAdapterTest
- *
- * @group DB
- *
- * @package OCA\DAV\Tests\Unit\Migration
- */
-class CalendarAdapterTest extends TestCase {
-
- /** @var IDBConnection */
- private $db;
- /** @var CalendarAdapter */
- private $adapter;
- /** @var array */
- private $cals = [];
- /** @var array */
- private $calObjs = [];
-
- public function setUp() {
- parent::setUp();
- $this->db = \OC::$server->getDatabaseConnection();
-
- $manager = new \OC\DB\MDB2SchemaManager($this->db);
- $manager->createDbFromStructure(__DIR__ . '/calendar_schema.xml');
-
- $this->adapter = new CalendarAdapter($this->db);
- }
-
- public function tearDown() {
- $this->db->dropTable('clndr_calendars');
- $this->db->dropTable('clndr_objects');
- parent::tearDown();
- }
-
- /**
- * @expectedException DomainException
- */
- public function testOldTablesDoNotExist() {
- $adapter = new AddressBookAdapter(\OC::$server->getDatabaseConnection(), 'crazy_table_that_does_no_exist');
- $adapter->setup();
- }
-
- public function test() {
-
- // insert test data
- $builder = $this->db->getQueryBuilder();
- $builder->insert('clndr_calendars')
- ->values([
- 'userid' => $builder->createNamedParameter('test-user-666'),
- 'displayname' => $builder->createNamedParameter('Display Name'),
- 'uri' => $builder->createNamedParameter('events'),
- 'ctag' => $builder->createNamedParameter('112233'),
- 'active' => $builder->createNamedParameter('1')
- ])
- ->execute();
- $builder = $this->db->getQueryBuilder();
- $builder->insert('clndr_objects')
- ->values([
- 'calendarid' => $builder->createNamedParameter(6666),
- 'objecttype' => $builder->createNamedParameter('VEVENT'),
- 'startdate' => $builder->createNamedParameter(new \DateTime(), 'datetime'),
- 'enddate' => $builder->createNamedParameter(new \DateTime(), 'datetime'),
- 'repeating' => $builder->createNamedParameter(0),
- 'summary' => $builder->createNamedParameter('Something crazy will happen'),
- 'uri' => $builder->createNamedParameter('event.ics'),
- 'lastmodified' => $builder->createNamedParameter('112233'),
- ])
- ->execute();
- $builder = $this->db->getQueryBuilder();
- $builder->insert('share')
- ->values([
- 'share_type' => $builder->createNamedParameter(1),
- 'share_with' => $builder->createNamedParameter('user01'),
- 'uid_owner' => $builder->createNamedParameter('user02'),
- 'item_type' => $builder->createNamedParameter('calendar'),
- 'item_source' => $builder->createNamedParameter(6666),
- 'item_target' => $builder->createNamedParameter('Contacts (user02)'),
- ])
- ->execute();
-
- // test the adapter
- $this->adapter->foreachCalendar('test-user-666', function($row) {
- $this->cals[] = $row;
- });
- $this->assertArrayHasKey('id', $this->cals[0]);
- $this->assertEquals('test-user-666', $this->cals[0]['userid']);
- $this->assertEquals('Display Name', $this->cals[0]['displayname']);
- $this->assertEquals('events', $this->cals[0]['uri']);
- $this->assertEquals('112233', $this->cals[0]['ctag']);
-
- $this->adapter->foreachCalendarObject(6666, function($row) {
- $this->calObjs[]= $row;
- });
- $this->assertArrayHasKey('id', $this->calObjs[0]);
- $this->assertEquals(6666, $this->calObjs[0]['calendarid']);
-
- // test getShares
- $shares = $this->adapter->getShares(6666);
- $this->assertEquals(1, count($shares));
-
- }
-
-}
diff --git a/apps/dav/tests/unit/migration/contacts_schema.xml b/apps/dav/tests/unit/migration/contacts_schema.xml
deleted file mode 100644
index 51836a1e0c6..00000000000
--- a/apps/dav/tests/unit/migration/contacts_schema.xml
+++ /dev/null
@@ -1,151 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<database>
-
- <name>*dbname*</name>
- <create>true</create>
- <overwrite>false</overwrite>
- <charset>utf8</charset>
- <table>
-
- <name>*dbprefix*contacts_addressbooks</name>
-
- <declaration>
-
- <field>
- <name>id</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <autoincrement>1</autoincrement>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>userid</name>
- <type>text</type>
- <default></default>
- <notnull>true</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>displayname</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>uri</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>200</length>
- </field>
-
- <field>
- <name>description</name>
- <type>text</type>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>ctag</name>
- <type>integer</type>
- <default>1</default>
- <notnull>true</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>active</name>
- <type>integer</type>
- <default>1</default>
- <notnull>true</notnull>
- <length>4</length>
- </field>
-
- <index>
- <name>c_addressbook_userid_index</name>
- <field>
- <name>userid</name>
- <sorting>ascending</sorting>
- </field>
- </index>
- </declaration>
-
- </table>
-
- <table>
-
- <name>*dbprefix*contacts_cards</name>
-
- <declaration>
-
- <field>
- <name>id</name>
- <type>integer</type>
- <default>0</default>
- <notnull>true</notnull>
- <autoincrement>1</autoincrement>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>addressbookid</name>
- <type>integer</type>
- <default></default>
- <notnull>true</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
- <field>
- <name>fullname</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>255</length>
- </field>
-
- <field>
- <name>carddata</name>
- <type>clob</type>
- <notnull>false</notnull>
- </field>
-
- <field>
- <name>uri</name>
- <type>text</type>
- <default></default>
- <notnull>false</notnull>
- <length>200</length>
- </field>
-
- <field>
- <name>lastmodified</name>
- <type>integer</type>
- <default></default>
- <notnull>false</notnull>
- <unsigned>true</unsigned>
- <length>4</length>
- </field>
-
-
- <index>
- <name>c_addressbookid_index</name>
- <field>
- <name>addressbookid</name>
- <sorting>ascending</sorting>
- </field>
- </index>
- </declaration>
-
- </table>
-
-</database>
diff --git a/apps/dav/tests/unit/migration/migrateaddressbooktest.php b/apps/dav/tests/unit/migration/migrateaddressbooktest.php
deleted file mode 100644
index 31cb16265c0..00000000000
--- a/apps/dav/tests/unit/migration/migrateaddressbooktest.php
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-/**
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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\Migration;
-
-use OCA\DAV\CardDAV\CardDavBackend;
-use OCA\Dav\Migration\AddressBookAdapter;
-use OCP\ILogger;
-use Test\TestCase;
-
-class MigrateAddressbookTest extends TestCase {
-
- public function testMigration() {
- /** @var AddressBookAdapter | \PHPUnit_Framework_MockObject_MockObject $adapter */
- $adapter = $this->mockAdapter([
- ['share_type' => '1', 'share_with' => 'users', 'permissions' => '31'],
- ['share_type' => '2', 'share_with' => 'adam', 'permissions' => '1'],
- ]);
-
- /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $cardDav */
- $cardDav = $this->getMockBuilder('\OCA\Dav\CardDAV\CardDAVBackend')->disableOriginalConstructor()->getMock();
- $cardDav->expects($this->any())->method('createAddressBook')->willReturn(666);
- $cardDav->expects($this->any())->method('getAddressBookById')->willReturn([]);
- $cardDav->expects($this->once())->method('createAddressBook')->with('principals/users/test01', 'test_contacts');
- $cardDav->expects($this->once())->method('createCard')->with(666, '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.vcf', 'BEGIN:VCARD');
- $cardDav->expects($this->once())->method('updateShares')->with($this->anything(), [
- ['href' => 'principal:principals/groups/users', 'readOnly' => false],
- ['href' => 'principal:principals/users/adam', 'readOnly' => true]
- ]);
- /** @var ILogger $logger */
- $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock();
-
- $m = new \OCA\Dav\Migration\MigrateAddressbooks($adapter, $cardDav, $logger, null);
- $m->migrateForUser('test01');
- }
-
- /**
- * @return \PHPUnit_Framework_MockObject_MockObject
- */
- private function mockAdapter($shares = []) {
- $adapter = $this->getMockBuilder('\OCA\Dav\Migration\AddressBookAdapter')->disableOriginalConstructor()->getMock();
- $adapter->expects($this->any())->method('foreachBook')->willReturnCallback(function ($user, \Closure $callBack) {
- $callBack([
- 'id' => 0,
- 'userid' => $user,
- 'displayname' => 'Test Contacts',
- 'uri' => 'test_contacts',
- 'description' => 'Contacts to test with',
- 'ctag' => 1234567890,
- 'active' => 1
- ]);
- });
- $adapter->expects($this->any())->method('foreachCard')->willReturnCallback(function ($addressBookId, \Closure $callBack) {
- $callBack([
- 'userid' => $addressBookId,
- 'uri' => '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.vcf',
- 'carddata' => 'BEGIN:VCARD'
- ]);
- });
- $adapter->expects($this->any())->method('getShares')->willReturn($shares);
- return $adapter;
- }
-
-}
diff --git a/apps/dav/tests/unit/migration/migratecalendartest.php b/apps/dav/tests/unit/migration/migratecalendartest.php
deleted file mode 100644
index e62970aef34..00000000000
--- a/apps/dav/tests/unit/migration/migratecalendartest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/**
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- * @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\Migration;
-
-use OCA\DAV\CalDAV\CalDavBackend;
-use OCA\Dav\Migration\CalendarAdapter;
-use OCP\ILogger;
-use Test\TestCase;
-
-class MigrateCalendarTest extends TestCase {
-
- public function testMigration() {
- /** @var CalendarAdapter | \PHPUnit_Framework_MockObject_MockObject $adapter */
- $adapter = $this->mockAdapter([
- ['share_type' => '1', 'share_with' => 'users', 'permissions' => '31'],
- ['share_type' => '2', 'share_with' => 'adam', 'permissions' => '1'],
- ]);
-
- /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject $cardDav */
- $cardDav = $this->getMockBuilder('\OCA\Dav\CalDAV\CalDAVBackend')->disableOriginalConstructor()->getMock();
- $cardDav->expects($this->any())->method('createCalendar')->willReturn(666);
- $cardDav->expects($this->once())->method('createCalendar')->with('principals/users/test01', 'test_contacts');
- $cardDav->expects($this->once())->method('createCalendarObject')->with(666, '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.ics', 'BEGIN:VCARD');
- $cardDav->expects($this->once())->method('updateShares')->with($this->anything(), [
- ['href' => 'principal:principals/groups/users', 'readOnly' => false],
- ['href' => 'principal:principals/users/adam', 'readOnly' => true]
- ]);
- /** @var ILogger $logger */
- $logger = $this->getMockBuilder('\OCP\ILogger')->disableOriginalConstructor()->getMock();
-
- $m = new \OCA\Dav\Migration\MigrateCalendars($adapter, $cardDav, $logger, null);
- $m->migrateForUser('test01');
- }
-
- /**
- * @return \PHPUnit_Framework_MockObject_MockObject
- */
- private function mockAdapter($shares = [], $calData = 'BEGIN:VCARD') {
- $adapter = $this->getMockBuilder('\OCA\Dav\Migration\CalendarAdapter')
- ->disableOriginalConstructor()
- ->getMock();
- $adapter->expects($this->any())->method('foreachCalendar')->willReturnCallback(function ($user, \Closure $callBack) {
- $callBack([
- // calendarorder | calendarcolor | timezone | components
- 'id' => 0,
- 'userid' => $user,
- 'displayname' => 'Test Contacts',
- 'uri' => 'test_contacts',
- 'ctag' => 1234567890,
- 'active' => 1,
- 'calendarorder' => '0',
- 'calendarcolor' => '#b3dc6c',
- 'timezone' => null,
- 'components' => 'VEVENT,VTODO,VJOURNAL'
- ]);
- });
- $adapter->expects($this->any())->method('foreachCalendarObject')->willReturnCallback(function ($addressBookId, \Closure $callBack) use ($calData) {
- $callBack([
- 'userid' => $addressBookId,
- 'uri' => '63f0dd6c-39d5-44be-9d34-34e7a7441fc2.ics',
- 'calendardata' => $calData
- ]);
- });
- $adapter->expects($this->any())->method('getShares')->willReturn($shares);
- return $adapter;
- }
-}
diff --git a/apps/dav/tests/unit/upload/assemblystreamtest.php b/apps/dav/tests/unit/upload/assemblystreamtest.php
new file mode 100644
index 00000000000..373d525a9dd
--- /dev/null
+++ b/apps/dav/tests/unit/upload/assemblystreamtest.php
@@ -0,0 +1,47 @@
+<?php
+
+class AssemblyStreamTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @dataProvider providesNodes()
+ */
+ public function testGetContents($expected, $nodes) {
+ $stream = \OCA\DAV\Upload\AssemblyStream::wrap($nodes);
+ $content = stream_get_contents($stream);
+
+ $this->assertEquals($expected, $content);
+ }
+
+ function providesNodes() {
+ return[
+ 'one node only' => ['1234567890', [
+ $this->buildNode('0', '1234567890')
+ ]],
+ 'two nodes' => ['1234567890', [
+ $this->buildNode('1', '67890'),
+ $this->buildNode('0', '12345')
+ ]]
+ ];
+ }
+
+ private function buildNode($name, $data) {
+ $node = $this->getMockBuilder('\Sabre\DAV\File')
+ ->setMethods(['getName', 'get', 'getSize'])
+ ->getMockForAbstractClass();
+
+ $node->expects($this->any())
+ ->method('getName')
+ ->willReturn($name);
+
+ $node->expects($this->any())
+ ->method('get')
+ ->willReturn($data);
+
+ $node->expects($this->any())
+ ->method('getSize')
+ ->willReturn(strlen($data));
+
+ return $node;
+ }
+}
+
diff --git a/apps/dav/tests/unit/upload/futurefiletest.php b/apps/dav/tests/unit/upload/futurefiletest.php
new file mode 100644
index 00000000000..c0c14bf04d7
--- /dev/null
+++ b/apps/dav/tests/unit/upload/futurefiletest.php
@@ -0,0 +1,89 @@
+<?php
+
+class FutureFileTest extends \PHPUnit_Framework_TestCase {
+
+ public function testGetContentType() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('application/octet-stream', $f->getContentType());
+ }
+
+ public function testGetETag() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('1234567890', $f->getETag());
+ }
+
+ public function testGetName() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals('foo.txt', $f->getName());
+ }
+
+ public function testGetLastModified() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals(12121212, $f->getLastModified());
+ }
+
+ public function testGetSize() {
+ $f = $this->mockFutureFile();
+ $this->assertEquals(0, $f->getSize());
+ }
+
+ public function testGet() {
+ $f = $this->mockFutureFile();
+ $stream = $f->get();
+ $this->assertTrue(is_resource($stream));
+ }
+
+ public function testDelete() {
+ $d = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->setMethods(['delete'])
+ ->getMock();
+
+ $d->expects($this->once())
+ ->method('delete');
+
+ $f = new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
+ $f->delete();
+ }
+
+ /**
+ * @expectedException Sabre\DAV\Exception\Forbidden
+ */
+ public function testPut() {
+ $f = $this->mockFutureFile();
+ $f->put('');
+ }
+
+ /**
+ * @expectedException Sabre\DAV\Exception\Forbidden
+ */
+ public function testSetName() {
+ $f = $this->mockFutureFile();
+ $f->setName('');
+ }
+
+ /**
+ * @return \OCA\DAV\Upload\FutureFile
+ */
+ private function mockFutureFile() {
+ $d = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->setMethods(['getETag', 'getLastModified', 'getChildren'])
+ ->getMock();
+
+ $d->expects($this->any())
+ ->method('getETag')
+ ->willReturn('1234567890');
+
+ $d->expects($this->any())
+ ->method('getLastModified')
+ ->willReturn(12121212);
+
+ $d->expects($this->any())
+ ->method('getChildren')
+ ->willReturn([]);
+
+ return new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
+ }
+}
+