summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/appinfo/info.xml1
-rw-r--r--apps/dav/l10n/bg_BG.js49
-rw-r--r--apps/dav/l10n/bg_BG.json47
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesReportPlugin.php12
-rw-r--r--apps/dav/lib/Files/RootCollection.php1
-rw-r--r--apps/dav/lib/Migration/ValueFix.php71
-rw-r--r--apps/dav/lib/Migration/ValueFixInsert.php63
-rw-r--r--apps/dav/lib/Server.php40
-rw-r--r--apps/dav/tests/unit/Migration/ValueFixInsertTest.php117
-rw-r--r--apps/dav/tests/unit/Migration/ValueFixTest.php200
10 files changed, 576 insertions, 25 deletions
diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml
index 31341a80a0b..4cd606007c3 100644
--- a/apps/dav/appinfo/info.xml
+++ b/apps/dav/appinfo/info.xml
@@ -23,6 +23,7 @@
<repair-steps>
<post-migration>
<step>OCA\DAV\Migration\FixBirthdayCalendarComponent</step>
+ <step>OCA\DAV\Migration\ValueFixInsert</step>
</post-migration>
</repair-steps>
<commands>
diff --git a/apps/dav/l10n/bg_BG.js b/apps/dav/l10n/bg_BG.js
new file mode 100644
index 00000000000..3f55af78124
--- /dev/null
+++ b/apps/dav/l10n/bg_BG.js
@@ -0,0 +1,49 @@
+OC.L10N.register(
+ "dav",
+ {
+ "Calendar" : "Календар",
+ "Todos" : "Задачи",
+ "{actor} created calendar {calendar}" : "{actor} направи календар {calendar}",
+ "You created calendar {calendar}" : "Направихте календар {calendar}",
+ "{actor} deleted calendar {calendar}" : "{actor} изтри календар {calendar}",
+ "You deleted calendar {calendar}" : "Изтрихте календар {calendar}",
+ "{actor} updated calendar {calendar}" : "{actor} обнови календар {calendar}",
+ "You updated calendar {calendar}" : "Обновихте календар {calendar}",
+ "{actor} shared calendar {calendar} with you" : "{actor} сподели календар {calendar} с теб",
+ "You shared calendar {calendar} with {user}" : "Споделихте календар {calendar} с {user}",
+ "{actor} shared calendar {calendar} with {user}" : "{actor} сподели календар {calendar} с {user}",
+ "{actor} unshared calendar {calendar} from you" : "{actor} отказа споделяне на календар {calendar} с теб",
+ "You unshared calendar {calendar} from {user}" : "Отказахте споделяне на календар {calendar} от {user}",
+ "{actor} unshared calendar {calendar} from {user}" : "{actor} отказа споделяне на календар {calendar} от {user}",
+ "{actor} unshared calendar {calendar} from themselves" : "{actor} отказа споделяне на календар {calendar} от себеси",
+ "You shared calendar {calendar} with group {group}" : "Споделихте календар {calendar} с група {group}",
+ "{actor} shared calendar {calendar} with group {group}" : "{actor} сподели календар {calendar} с група {group}",
+ "You unshared calendar {calendar} from group {group}" : "Отказахте споделяне на календар {calendar} от група {group}",
+ "{actor} unshared calendar {calendar} from group {group}" : "{actor} отказа споделяне с календар {calendar} от група {group}",
+ "{actor} created event {event} in calendar {calendar}" : "{actor} създаде събитие {event} в календар {calendar}",
+ "You created event {event} in calendar {calendar}" : "Създадохте събитие {event} в календар {calendar}",
+ "{actor} deleted event {event} from calendar {calendar}" : "{actor} изтри събитие {event} от календар {calendar}",
+ "You deleted event {event} from calendar {calendar}" : "Изтрихте събитие {event} от календар {calendar}",
+ "{actor} updated event {event} in calendar {calendar}" : "{actor} обнови събитие {event} в календар {calendar}",
+ "You updated event {event} in calendar {calendar}" : "Обновихте събитие {event} в календар {calendar}",
+ "{actor} created todo {todo} in list {calendar}" : "{actor} създаде задача {todo} в списък {calendar}",
+ "You created todo {todo} in list {calendar}" : "Създадохте задача {todo} в списък {calendar}",
+ "{actor} deleted todo {todo} from list {calendar}" : "{actor} изтри задача {todo} от списък {calendar}",
+ "You deleted todo {todo} from list {calendar}" : "Изтрихте задача {todo} от лист {calendar}",
+ "{actor} updated todo {todo} in list {calendar}" : "{actor} актуализира задача {todo} в списък {calendar}",
+ "You updated todo {todo} in list {calendar}" : "Променихте задача {todo} в списък {calendar}",
+ "{actor} solved todo {todo} in list {calendar}" : "{actor} реши задача {todo} в списък {calendar}",
+ "You solved todo {todo} in list {calendar}" : "Решихте задача {todo} в списък {calendar}",
+ "{actor} reopened todo {todo} in list {calendar}" : "{actor} възобнови задача {todo} в списък {calendar}",
+ "You reopened todo {todo} in list {calendar}" : "Възобновихте задача {todo} в списък {calendar}",
+ "A <strong>calendar</strong> was modified" : "<strong>Календар</strong> беше променен",
+ "A calendar <strong>event</strong> was modified" : "Календарно <strong>събитие</strong> беше променено",
+ "A calendar <strong>todo</strong> was modified" : "Календарна <strong>задача</strong> беше променена",
+ "Contact birthdays" : "Рождени дни на контакти",
+ "Personal" : "Личен",
+ "Contacts" : "Контакти",
+ "Technical details" : "Технически детайли",
+ "Remote Address: %s" : "Отдалечен адрес: %s",
+ "Request ID: %s" : "ID на заявка: %s"
+},
+"nplurals=2; plural=(n != 1);");
diff --git a/apps/dav/l10n/bg_BG.json b/apps/dav/l10n/bg_BG.json
new file mode 100644
index 00000000000..03238418d18
--- /dev/null
+++ b/apps/dav/l10n/bg_BG.json
@@ -0,0 +1,47 @@
+{ "translations": {
+ "Calendar" : "Календар",
+ "Todos" : "Задачи",
+ "{actor} created calendar {calendar}" : "{actor} направи календар {calendar}",
+ "You created calendar {calendar}" : "Направихте календар {calendar}",
+ "{actor} deleted calendar {calendar}" : "{actor} изтри календар {calendar}",
+ "You deleted calendar {calendar}" : "Изтрихте календар {calendar}",
+ "{actor} updated calendar {calendar}" : "{actor} обнови календар {calendar}",
+ "You updated calendar {calendar}" : "Обновихте календар {calendar}",
+ "{actor} shared calendar {calendar} with you" : "{actor} сподели календар {calendar} с теб",
+ "You shared calendar {calendar} with {user}" : "Споделихте календар {calendar} с {user}",
+ "{actor} shared calendar {calendar} with {user}" : "{actor} сподели календар {calendar} с {user}",
+ "{actor} unshared calendar {calendar} from you" : "{actor} отказа споделяне на календар {calendar} с теб",
+ "You unshared calendar {calendar} from {user}" : "Отказахте споделяне на календар {calendar} от {user}",
+ "{actor} unshared calendar {calendar} from {user}" : "{actor} отказа споделяне на календар {calendar} от {user}",
+ "{actor} unshared calendar {calendar} from themselves" : "{actor} отказа споделяне на календар {calendar} от себеси",
+ "You shared calendar {calendar} with group {group}" : "Споделихте календар {calendar} с група {group}",
+ "{actor} shared calendar {calendar} with group {group}" : "{actor} сподели календар {calendar} с група {group}",
+ "You unshared calendar {calendar} from group {group}" : "Отказахте споделяне на календар {calendar} от група {group}",
+ "{actor} unshared calendar {calendar} from group {group}" : "{actor} отказа споделяне с календар {calendar} от група {group}",
+ "{actor} created event {event} in calendar {calendar}" : "{actor} създаде събитие {event} в календар {calendar}",
+ "You created event {event} in calendar {calendar}" : "Създадохте събитие {event} в календар {calendar}",
+ "{actor} deleted event {event} from calendar {calendar}" : "{actor} изтри събитие {event} от календар {calendar}",
+ "You deleted event {event} from calendar {calendar}" : "Изтрихте събитие {event} от календар {calendar}",
+ "{actor} updated event {event} in calendar {calendar}" : "{actor} обнови събитие {event} в календар {calendar}",
+ "You updated event {event} in calendar {calendar}" : "Обновихте събитие {event} в календар {calendar}",
+ "{actor} created todo {todo} in list {calendar}" : "{actor} създаде задача {todo} в списък {calendar}",
+ "You created todo {todo} in list {calendar}" : "Създадохте задача {todo} в списък {calendar}",
+ "{actor} deleted todo {todo} from list {calendar}" : "{actor} изтри задача {todo} от списък {calendar}",
+ "You deleted todo {todo} from list {calendar}" : "Изтрихте задача {todo} от лист {calendar}",
+ "{actor} updated todo {todo} in list {calendar}" : "{actor} актуализира задача {todo} в списък {calendar}",
+ "You updated todo {todo} in list {calendar}" : "Променихте задача {todo} в списък {calendar}",
+ "{actor} solved todo {todo} in list {calendar}" : "{actor} реши задача {todo} в списък {calendar}",
+ "You solved todo {todo} in list {calendar}" : "Решихте задача {todo} в списък {calendar}",
+ "{actor} reopened todo {todo} in list {calendar}" : "{actor} възобнови задача {todo} в списък {calendar}",
+ "You reopened todo {todo} in list {calendar}" : "Възобновихте задача {todo} в списък {calendar}",
+ "A <strong>calendar</strong> was modified" : "<strong>Календар</strong> беше променен",
+ "A calendar <strong>event</strong> was modified" : "Календарно <strong>събитие</strong> беше променено",
+ "A calendar <strong>todo</strong> was modified" : "Календарна <strong>задача</strong> беше променена",
+ "Contact birthdays" : "Рождени дни на контакти",
+ "Personal" : "Личен",
+ "Contacts" : "Контакти",
+ "Technical details" : "Технически детайли",
+ "Remote Address: %s" : "Отдалечен адрес: %s",
+ "Request ID: %s" : "ID на заявка: %s"
+},"pluralForm" :"nplurals=2; plural=(n != 1);"
+} \ No newline at end of file
diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
index bc0c1c2f603..81c082b9105 100644
--- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
@@ -24,9 +24,7 @@
namespace OCA\DAV\Connector\Sabre;
use OC\Files\View;
-use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\PreconditionFailed;
-use Sabre\DAV\Exception\ReportNotSupported;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\ServerPlugin;
use Sabre\DAV\Tree;
@@ -105,7 +103,7 @@ class FilesReportPlugin extends ServerPlugin {
* @param ITagManager $fileTagger manager for private tags
* @param IUserSession $userSession
* @param IGroupManager $groupManager
- * @param Folder $userfolder
+ * @param Folder $userFolder
*/
public function __construct(Tree $tree,
View $view,
@@ -161,11 +159,12 @@ class FilesReportPlugin extends ServerPlugin {
* REPORT operations to look for files
*
* @param string $reportName
- * @param [] $report
+ * @param $report
* @param string $uri
* @return bool
- * @throws NotFound
- * @throws ReportNotSupported
+ * @throws BadRequest
+ * @throws PreconditionFailed
+ * @internal param $ [] $report
*/
public function onReport($reportName, $report, $uri) {
$reportTargetNode = $this->server->tree->getNodeForPath($uri);
@@ -232,7 +231,6 @@ class FilesReportPlugin extends ServerPlugin {
private function getFilesBaseUri($uri, $subPath) {
$uri = trim($uri, '/');
$subPath = trim($subPath, '/');
- $filesUri = '';
if (empty($subPath)) {
$filesUri = $uri;
} else {
diff --git a/apps/dav/lib/Files/RootCollection.php b/apps/dav/lib/Files/RootCollection.php
index 345015530e2..c73d7c175ce 100644
--- a/apps/dav/lib/Files/RootCollection.php
+++ b/apps/dav/lib/Files/RootCollection.php
@@ -21,6 +21,7 @@
*/
namespace OCA\DAV\Files;
+use Sabre\DAV\INode;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\HTTP\URLUtil;
use Sabre\DAV\SimpleCollection;
diff --git a/apps/dav/lib/Migration/ValueFix.php b/apps/dav/lib/Migration/ValueFix.php
new file mode 100644
index 00000000000..2ad043b409d
--- /dev/null
+++ b/apps/dav/lib/Migration/ValueFix.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * @copyright 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\Migration;
+
+use OC\BackgroundJob\QueuedJob;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCP\ILogger;
+use Sabre\VObject\InvalidDataException;
+
+class ValueFix extends QueuedJob {
+
+ /** @var CalDavBackend */
+ private $calDavBackend;
+
+ /** @var ILogger */
+ private $logger;
+
+ public function __construct(CalDavBackend $calDavBackend, ILogger $logger) {
+ $this->calDavBackend = $calDavBackend;
+ $this->logger = $logger;
+ }
+
+ public function run($argument) {
+ $user = $argument['user'];
+
+ $pattern = '/;VALUE=:/';
+ $principal = 'principals/users/' . $user;
+ $calendars = $this->calDavBackend->getCalendarsForUser($principal);
+ foreach ($calendars as $calendar) {
+ $objects = $this->calDavBackend->getCalendarObjects($calendar['id']);
+ foreach ($objects as $object) {
+ $calObject = $this->calDavBackend->getCalendarObject($calendar['id'], $object['uri']);
+ $data = preg_replace($pattern, ':', $calObject['calendardata']);
+ if ($data !== $calObject['calendardata']) {
+ try {
+ $this->calDavBackend->getDenormalizedData($data);
+ } catch (InvalidDataException $e) {
+ $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [
+ 'app'=> 'dav',
+ 'cal' => $calendar['id'],
+ 'uri' => $object['uri'],
+ ]);
+ continue;
+ }
+ $this->calDavBackend->updateCalendarObject($calendar['id'], $object['uri'], $data);
+ }
+ }
+ }
+ }
+
+}
diff --git a/apps/dav/lib/Migration/ValueFixInsert.php b/apps/dav/lib/Migration/ValueFixInsert.php
new file mode 100644
index 00000000000..25917691b20
--- /dev/null
+++ b/apps/dav/lib/Migration/ValueFixInsert.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * @copyright 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\Migration;
+
+use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class ValueFixInsert implements IRepairStep {
+
+ /** @var IUserManager */
+ private $userManager;
+
+ /** @var IJobList */
+ private $jobList;
+
+ /** @var IConfig */
+ private $config;
+
+ public function __construct(IUserManager $userManager,
+ IJobList $jobList,
+ IConfig $config) {
+ $this->userManager = $userManager;
+ $this->jobList = $jobList;
+ $this->config = $config;
+ }
+
+ public function getName() {
+ return 'Insert ValueFix background job for each user';
+ }
+
+ public function run(IOutput $output) {
+ if ($this->config->getAppValue('dav', self::class . '_ran', 'false') !== 'true') {
+ $this->userManager->callForSeenUsers(function (IUser $user) {
+ $this->jobList->add(ValueFix::class, ['user' => $user->getUID()]);
+ });
+ $this->config->setAppValue('dav', self::class . '_ran', 'true');
+ }
+ }
+}
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 1205d018241..79c4301a8d8 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -33,11 +33,14 @@ 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;
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
use OCA\DAV\Connector\Sabre\DavAclPlugin;
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
use OCA\DAV\Connector\Sabre\FakeLockerPlugin;
use OCA\DAV\Connector\Sabre\FilesPlugin;
+use OCA\DAV\Connector\Sabre\FilesReportPlugin;
+use OCA\DAV\Connector\Sabre\SharesPlugin;
use OCA\DAV\DAV\PublicAuth;
use OCA\DAV\Connector\Sabre\QuotaPlugin;
use OCA\DAV\Files\BrowserErrorPagePlugin;
@@ -85,7 +88,6 @@ class Server {
$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
$authPlugin = new Plugin();
- $authPlugin->addBackend($authBackend);
$authPlugin->addBackend(new PublicAuth());
$this->server->addPlugin($authPlugin);
@@ -166,7 +168,7 @@ class Server {
// custom properties plugin must be the last one
$userSession = \OC::$server->getUserSession();
$user = $userSession->getUser();
- if (!is_null($user)) {
+ if ($user !== null) {
$view = \OC\Files\Filesystem::getView();
$this->server->addPlugin(
new FilesPlugin(
@@ -188,9 +190,10 @@ class Server {
)
)
);
- $this->server->addPlugin(
- new QuotaPlugin($view)
- );
+ if ($view !== null) {
+ $this->server->addPlugin(
+ new QuotaPlugin($view));
+ }
$this->server->addPlugin(
new TagsPlugin(
$this->server->tree, \OC::$server->getTagManager()
@@ -198,28 +201,29 @@ class Server {
);
// TODO: switch to LazyUserFolder
$userFolder = \OC::$server->getUserFolder();
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin(
+ $this->server->addPlugin(new SharesPlugin(
$this->server->tree,
$userSession,
$userFolder,
\OC::$server->getShareManager()
));
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(
+ $this->server->addPlugin(new CommentPropertiesPlugin(
\OC::$server->getCommentsManager(),
$userSession
));
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin(
- $this->server->tree,
- $view,
- \OC::$server->getSystemTagManager(),
- \OC::$server->getSystemTagObjectMapper(),
- \OC::$server->getTagManager(),
- $userSession,
- \OC::$server->getGroupManager(),
- $userFolder
- ));
+ if ($view !== null) {
+ $this->server->addPlugin(new FilesReportPlugin(
+ $this->server->tree,
+ $view,
+ \OC::$server->getSystemTagManager(),
+ \OC::$server->getSystemTagObjectMapper(),
+ \OC::$server->getTagManager(),
+ $userSession,
+ \OC::$server->getGroupManager(),
+ $userFolder
+ ));
+ }
}
- $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin());
});
}
diff --git a/apps/dav/tests/unit/Migration/ValueFixInsertTest.php b/apps/dav/tests/unit/Migration/ValueFixInsertTest.php
new file mode 100644
index 00000000000..26152e7d01d
--- /dev/null
+++ b/apps/dav/tests/unit/Migration/ValueFixInsertTest.php
@@ -0,0 +1,117 @@
+<?php
+/**
+ * @copyright 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\Unit\DAV\Migration;
+
+use OCA\DAV\Migration\ValueFix;
+use OCA\DAV\Migration\ValueFixInsert;
+use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\IUserManager;
+use OCP\Migration\IOutput;
+use Test\TestCase;
+
+class ValueFixInsertTest extends TestCase {
+ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
+
+ /** @var IJobList|\PHPUnit_Framework_MockObject_MockObject */
+ private $jobList;
+
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
+ /** @var ValueFixInsert */
+ private $job;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->jobList = $this->createMock(IJobList::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->job = new ValueFixInsert(
+ $this->userManager,
+ $this->jobList,
+ $this->config
+ );
+ }
+
+ public function testGetName() {
+ $this->assertSame('Insert ValueFix background job for each user', $this->job->getName());
+ }
+
+ public function testRun() {
+ $user1 = $this->createMock(IUser::class);
+ $user1->method('getUID')->willReturn('user1');
+ $user2 = $this->createMock(IUser::class);
+ $user2->method('getUID')->willReturn('user2');
+
+ $this->config->method('getAppValue')
+ ->with(
+ $this->equalTo('dav'),
+ $this->equalTo(ValueFixInsert::class.'_ran'),
+ $this->anything()
+ )->will($this->returnCallback(function($app, $key, $value) {
+ return $value;
+ }));
+
+ $this->userManager->method('callForSeenUsers')
+ ->will($this->returnCallback(function(\Closure $function) use ($user1, $user2) {
+ $function($user1);
+ $function($user2);
+ }));
+
+ $this->jobList->expects($this->at(0))
+ ->method('add')
+ ->with(
+ $this->equalTo(ValueFix::class),
+ $this->equalTo(['user' => 'user1'])
+ );
+ $this->jobList->expects($this->at(1))
+ ->method('add')
+ ->with(
+ $this->equalTo(ValueFix::class),
+ $this->equalTo(['user' => 'user2'])
+ );
+
+ $this->job->run($this->createMock(IOutput::class));
+ }
+
+ public function testRunOnlyOnce() {
+ $this->config->method('getAppValue')
+ ->with(
+ $this->equalTo('dav'),
+ $this->equalTo(ValueFixInsert::class.'_ran'),
+ $this->anything()
+ )->willReturn('true');
+
+ $this->userManager->expects($this->never())
+ ->method($this->anything());;
+
+ $this->jobList->expects($this->never())
+ ->method($this->anything());
+
+ $this->job->run($this->createMock(IOutput::class));
+ }
+}
diff --git a/apps/dav/tests/unit/Migration/ValueFixTest.php b/apps/dav/tests/unit/Migration/ValueFixTest.php
new file mode 100644
index 00000000000..58b6f79621f
--- /dev/null
+++ b/apps/dav/tests/unit/Migration/ValueFixTest.php
@@ -0,0 +1,200 @@
+<?php
+/**
+ * @copyright 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\Unit\DAV\Migration;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\Migration\ValueFix;
+use OCP\ILogger;
+use Sabre\VObject\InvalidDataException;
+use Test\TestCase;
+
+class ValueFixTest extends TestCase {
+
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ private $logger;
+
+ /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject */
+ private $backend;
+
+ /** @var string */
+ private $invalid = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//Mac OS X 10.11.2//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+TRANSP:OPAQUE
+DTEND;VALUE=:20151223T223000Z
+LAST-MODIFIED:20151214T091032Z
+ORGANIZER;CN="User 1":mailto:user1@example.com
+UID:1234567890@example.com
+DTSTAMP:20151214T091032Z
+STATUS:CONFIRMED
+SEQUENCE:0
+SUMMARY:Ein Geburtstag
+DTSTART;VALUE=:20151223T173000Z
+X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
+CREATED;VALUE=:20151214T091032Z
+END:VEVENT
+END:VCALENDAR';
+
+ /** @var string */
+ private $valid = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//Mac OS X 10.11.2//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+TRANSP:OPAQUE
+DTEND:20151223T223000Z
+LAST-MODIFIED:20151214T091032Z
+ORGANIZER;CN="User 1":mailto:user1@example.com
+UID:1234567890@example.com
+DTSTAMP:20151214T091032Z
+STATUS:CONFIRMED
+SEQUENCE:0
+SUMMARY:Ein Geburtstag
+DTSTART:20151223T173000Z
+X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC
+CREATED:20151214T091032Z
+END:VEVENT
+END:VCALENDAR';
+
+ /** @var ValueFix */
+ private $job;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->logger = $this->createMock(ILogger::class);
+ $this->backend = $this->createMock(CalDavBackend::class);
+ $this->job = new ValueFix(
+ $this->backend,
+ $this->logger
+ );
+ }
+
+ public function testRunInvalid() {
+ $calendars = [['id' => 42]];
+ $objects = [['uri' => 'myuri']];
+
+ $this->backend->method('getCalendarsForUser')
+ ->with($this->equalTo('principals/users/u1'))
+ ->willReturn($calendars);
+
+ $this->backend->method('getCalendarObjects')
+ ->with($this->equalTo(42))
+ ->willReturn($objects);
+
+ $this->backend->method('getCalendarObject')
+ ->with(
+ $this->equalTo(42),
+ $this->equalTo('myuri')
+ )->willReturn([
+ 'calendardata' => $this->invalid
+ ]);
+
+ $this->backend->expects($this->once())
+ ->method('getDenormalizedData')
+ ->with($this->valid);
+
+ $this->backend->expects($this->once())
+ ->method('updateCalendarObject')
+ ->with(
+ $this->equalTo(42),
+ $this->equalTo('myuri'),
+ $this->equalTo($this->valid)
+ );
+
+ $this->job->run(['user' => 'u1']);
+ }
+
+ public function testRunValid() {
+ $calendars = [['id' => 42]];
+ $objects = [['uri' => 'myuri']];
+
+ $this->backend->method('getCalendarsForUser')
+ ->with($this->equalTo('principals/users/u1'))
+ ->willReturn($calendars);
+
+ $this->backend->method('getCalendarObjects')
+ ->with($this->equalTo(42))
+ ->willReturn($objects);
+
+ $this->backend->method('getCalendarObject')
+ ->with(
+ $this->equalTo(42),
+ $this->equalTo('myuri')
+ )->willReturn([
+ 'calendardata' => $this->valid
+ ]);
+
+ $this->backend->expects($this->never())
+ ->method('getDenormalizedData');
+
+ $this->backend->expects($this->never())
+ ->method('updateCalendarObject');
+
+ $this->job->run(['user' => 'u1']);
+ }
+
+ public function testRunStillInvalid() {
+ $calendars = [['id' => 42]];
+ $objects = [['uri' => 'myuri']];
+
+ $this->backend->method('getCalendarsForUser')
+ ->with($this->equalTo('principals/users/u1'))
+ ->willReturn($calendars);
+
+ $this->backend->method('getCalendarObjects')
+ ->with($this->equalTo(42))
+ ->willReturn($objects);
+
+ $this->backend->method('getCalendarObject')
+ ->with(
+ $this->equalTo(42),
+ $this->equalTo('myuri')
+ )->willReturn([
+ 'calendardata' => $this->invalid
+ ]);
+
+ $this->backend->expects($this->once())
+ ->method('getDenormalizedData')
+ ->with($this->valid)
+ ->willThrowException(new InvalidDataException());
+
+ $this->logger->expects($this->once())
+ ->method('info')
+ ->with(
+ $this->equalTo('Calendar object for calendar {cal} with uri {uri} still invalid'),
+ $this->equalTo([
+ 'app'=> 'dav',
+ 'cal' => 42,
+ 'uri' => 'myuri',
+ ])
+ );
+
+ $this->backend->expects($this->never())
+ ->method('updateCalendarObject');
+
+ $this->job->run(['user' => 'u1']);
+ }
+}