summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2018-06-19 21:01:14 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-06-29 10:44:44 +0200
commit4aa4e4080c27356792b6eeab1f2f2b36ad485a05 (patch)
tree07197c21582d4e74cacce3704eaa5a67b5fb89bb /apps/dav/tests
parent3ff3141a1e4c9482ddaa68e13f545eb7e62ff9b7 (diff)
downloadnextcloud-server-4aa4e4080c27356792b6eeab1f2f2b36ad485a05.tar.gz
nextcloud-server-4aa4e4080c27356792b6eeab1f2f2b36ad485a05.zip
Include accept / decline links in CalDAV invitation emails
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php100
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php86
-rw-r--r--apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php455
3 files changed, 638 insertions, 3 deletions
diff --git a/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php b/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php
new file mode 100644
index 00000000000..3e69230f441
--- /dev/null
+++ b/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php
@@ -0,0 +1,100 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.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\BackgroundJob;
+
+use OCA\DAV\BackgroundJob\CleanupInvitationTokenJob;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use Test\TestCase;
+
+class CleanupInvitationTokenJobTest extends TestCase {
+
+ /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject */
+ private $dbConnection;
+
+ /** @var ITimeFactory | \PHPUnit_Framework_MockObject_MockObject */
+ private $timeFactory;
+
+ /** @var \OCA\DAV\BackgroundJob\GenerateBirthdayCalendarBackgroundJob */
+ private $backgroundJob;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->dbConnection = $this->createMock(IDBConnection::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+
+ $this->backgroundJob = new CleanupInvitationTokenJob(
+ $this->dbConnection, $this->timeFactory);
+ }
+
+ public function testRun() {
+ $this->timeFactory->expects($this->once())
+ ->method('getTime')
+ ->with()
+ ->will($this->returnValue(1337));
+
+ $queryBuilder = $this->createMock(IQueryBuilder::class);
+ $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
+ $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
+
+ $this->dbConnection->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->method('expr')
+ ->will($this->returnValue($expr));
+ $queryBuilder->method('createNamedParameter')
+ ->will($this->returnValueMap([
+ [1337, \PDO::PARAM_STR, null, 'namedParameter1337']
+ ]));
+
+ $expr->expects($this->once())
+ ->method('lt')
+ ->with('expiration', 'namedParameter1337')
+ ->will($this->returnValue('LT STATEMENT'));
+
+ $this->dbConnection->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+
+ $queryBuilder->expects($this->at(0))
+ ->method('delete')
+ ->with('calendar_invitation_tokens')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(3))
+ ->method('where')
+ ->with('LT STATEMENT')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(4))
+ ->method('execute')
+ ->with()
+ ->will($this->returnValue($stmt));
+
+ $this->backgroundJob->run([]);
+ }
+} \ No newline at end of file
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
index 3f89002ab98..2fefe8dd06a 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php
@@ -29,8 +29,10 @@ namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
use OC\Mail\Mailer;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
@@ -39,6 +41,7 @@ use OCP\Mail\IAttachment;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
use OCP\Mail\IMessage;
+use OCP\Security\ISecureRandom;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\ITip\Message;
use Test\TestCase;
@@ -70,13 +73,38 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject $db */
+ $db = $this->createMock(IDBConnection::class);
+ /** @var ISecureRandom | \PHPUnit_Framework_MockObject_MockObject $random */
+ $random = $this->createMock(ISecureRandom::class);
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
$defaults = $this->createMock(Defaults::class);
$defaults->expects($this->once())
->method('getName')
->will($this->returnValue('Instance Name 123'));
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
+ $random->expects($this->once())
+ ->method('generate')
+ ->with(60, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
+ ->will($this->returnValue('random_token'));
+
+ $queryBuilder = $this->createMock(IQueryBuilder::class);
+
+ $db->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(0))
+ ->method('insert')
+ ->with('calendar_invitation_tokens')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(8))
+ ->method('values')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(9))
+ ->method('execute');
+
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, $random, $db, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -128,10 +156,35 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject $db */
+ $db = $this->createMock(IDBConnection::class);
+ /** @var ISecureRandom | \PHPUnit_Framework_MockObject_MockObject $random */
+ $random = $this->createMock(ISecureRandom::class);
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
$defaults = $this->createMock(Defaults::class);
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
+ $random->expects($this->once())
+ ->method('generate')
+ ->with(60, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
+ ->will($this->returnValue('random_token'));
+
+ $queryBuilder = $this->createMock(IQueryBuilder::class);
+
+ $db->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(0))
+ ->method('insert')
+ ->with('calendar_invitation_tokens')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(8))
+ ->method('values')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(9))
+ ->method('execute');
+
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, $random, $db, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
@@ -190,10 +243,37 @@ class IMipPluginTest extends TestCase {
$l10nFactory->method('get')->willReturn($l10n);
/** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */
$urlGenerator = $this->createMock(IURLGenerator::class);
+ /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject $db */
+ $db = $this->createMock(IDBConnection::class);
+ /** @var ISecureRandom | \PHPUnit_Framework_MockObject_MockObject $random */
+ $random = $this->createMock(ISecureRandom::class);
/** @var Defaults | \PHPUnit_Framework_MockObject_MockObject $defaults */
$defaults = $this->createMock(Defaults::class);
- $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, 'user123');
+ if ($expectsMail) {
+ $random->expects($this->once())
+ ->method('generate')
+ ->with(60, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
+ ->will($this->returnValue('random_token'));
+
+ $queryBuilder = $this->createMock(IQueryBuilder::class);
+
+ $db->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(0))
+ ->method('insert')
+ ->with('calendar_invitation_tokens')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(8))
+ ->method('values')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(9))
+ ->method('execute');
+ }
+
+ $plugin = new IMipPlugin($config, $mailer, $logger, $timeFactory, $l10nFactory, $urlGenerator, $defaults, $random, $db, 'user123');
$message = new Message();
$message->method = 'REQUEST';
$message->message = new VCalendar();
diff --git a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
new file mode 100644
index 00000000000..333737e2262
--- /dev/null
+++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php
@@ -0,0 +1,455 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.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\DAV\Controller;
+
+use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
+use OCA\DAV\CalDAV\Schedule\Plugin;
+use OCA\DAV\Controller\InvitationResponseController;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+use OCP\IRequest;
+use Sabre\VObject\ITip\Message;
+use Test\TestCase;
+
+class InvitationResponseControllerTest extends TestCase {
+
+ /** @var InvitationResponseController */
+ private $controller;
+
+ /** @var IDBConnection|\PHPUnit_Framework_MockObject_MockObject */
+ private $dbConnection;
+
+ /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
+ private $request;
+
+ /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $timeFactory;
+
+ /** @var InvitationResponseServer|\PHPUnit_Framework_MockObject_MockObject */
+ private $responseServer;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->dbConnection = $this->createMock(IDBConnection::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
+ $this->responseServer = $this->getMockBuilder(InvitationResponseServer::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->controller = new InvitationResponseController(
+ 'appName',
+ $this->request,
+ $this->dbConnection,
+ $this->timeFactory,
+ $this->responseServer
+ );
+ }
+
+ public function testAccept() {
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => null,
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => null,
+ 'token' => 'TOKEN123',
+ 'expiration' => 420000,
+ ], 1337);
+
+ $expected = <<<EOF
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:attendee@foo.bar
+ORGANIZER:mailto:organizer@foo.bar
+UID:this-is-the-events-uid
+SEQUENCE:0
+REQUEST-STATUS:2.0;Success
+DTSTAMP:19700101T002217Z
+END:VEVENT
+END:VCALENDAR
+
+EOF;
+ $expected = preg_replace('~\R~u', "\r\n", $expected);
+
+ $called = false;
+ $this->responseServer->expects($this->once())
+ ->method('handleITipMessage')
+ ->will($this->returnCallback(function(Message $iTipMessage) use (&$called, $expected) {
+ $called = true;
+ $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
+ $this->assertEquals('VEVENT', $iTipMessage->component);
+ $this->assertEquals('REPLY', $iTipMessage->method);
+ $this->assertEquals(null, $iTipMessage->sequence);
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+ $this->assertEquals($expected, $iTipMessage->message->serialize());
+ }));
+
+
+
+ $response = $this->controller->accept('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-success', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ $this->assertTrue($called);
+ }
+
+ public function testAcceptSequence() {
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => null,
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => 1337,
+ 'token' => 'TOKEN123',
+ 'expiration' => 420000,
+ ], 1337);
+
+ $expected = <<<EOF
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:attendee@foo.bar
+ORGANIZER:mailto:organizer@foo.bar
+UID:this-is-the-events-uid
+SEQUENCE:1337
+REQUEST-STATUS:2.0;Success
+DTSTAMP:19700101T002217Z
+END:VEVENT
+END:VCALENDAR
+
+EOF;
+ $expected = preg_replace('~\R~u', "\r\n", $expected);
+
+ $called = false;
+ $this->responseServer->expects($this->once())
+ ->method('handleITipMessage')
+ ->will($this->returnCallback(function(Message $iTipMessage) use (&$called, $expected) {
+ $called = true;
+ $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
+ $this->assertEquals('VEVENT', $iTipMessage->component);
+ $this->assertEquals('REPLY', $iTipMessage->method);
+ $this->assertEquals(1337, $iTipMessage->sequence);
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+ $this->assertEquals($expected, $iTipMessage->message->serialize());
+ }));
+
+
+
+ $response = $this->controller->accept('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-success', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ $this->assertTrue($called);
+ }
+
+ public function testAcceptRecurrenceId() {
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => "RECURRENCE-ID;TZID=Europe/Berlin:20180726T150000\n",
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => null,
+ 'token' => 'TOKEN123',
+ 'expiration' => 420000,
+ ], 1337);
+
+ $expected = <<<EOF
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=ACCEPTED:mailto:attendee@foo.bar
+ORGANIZER:mailto:organizer@foo.bar
+UID:this-is-the-events-uid
+SEQUENCE:0
+REQUEST-STATUS:2.0;Success
+RECURRENCE-ID;TZID=Europe/Berlin:20180726T150000
+DTSTAMP:19700101T002217Z
+END:VEVENT
+END:VCALENDAR
+
+EOF;
+ $expected = preg_replace('~\R~u', "\r\n", $expected);
+
+ $called = false;
+ $this->responseServer->expects($this->once())
+ ->method('handleITipMessage')
+ ->will($this->returnCallback(function(Message $iTipMessage) use (&$called, $expected) {
+ $called = true;
+ $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
+ $this->assertEquals('VEVENT', $iTipMessage->component);
+ $this->assertEquals('REPLY', $iTipMessage->method);
+ $this->assertEquals(0, $iTipMessage->sequence);
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+ $this->assertEquals($expected, $iTipMessage->message->serialize());
+ }));
+
+
+
+ $response = $this->controller->accept('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-success', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ $this->assertTrue($called);
+ }
+
+ public function testAcceptTokenNotFound() {
+ $this->buildQueryExpects('TOKEN123', null, 1337);
+
+ $response = $this->controller->accept('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-error', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ }
+
+ public function testAcceptExpiredToken() {
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => null,
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => null,
+ 'token' => 'TOKEN123',
+ 'expiration' => 42,
+ ], 1337);
+
+ $response = $this->controller->accept('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-error', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ }
+
+ public function testDecline() {
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => null,
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => null,
+ 'token' => 'TOKEN123',
+ 'expiration' => 420000,
+ ], 1337);
+
+ $expected = <<<EOF
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=DECLINED:mailto:attendee@foo.bar
+ORGANIZER:mailto:organizer@foo.bar
+UID:this-is-the-events-uid
+SEQUENCE:0
+REQUEST-STATUS:2.0;Success
+DTSTAMP:19700101T002217Z
+END:VEVENT
+END:VCALENDAR
+
+EOF;
+ $expected = preg_replace('~\R~u', "\r\n", $expected);
+
+ $called = false;
+ $this->responseServer->expects($this->once())
+ ->method('handleITipMessage')
+ ->will($this->returnCallback(function(Message $iTipMessage) use (&$called, $expected) {
+ $called = true;
+ $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
+ $this->assertEquals('VEVENT', $iTipMessage->component);
+ $this->assertEquals('REPLY', $iTipMessage->method);
+ $this->assertEquals(null, $iTipMessage->sequence);
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+ $this->assertEquals($expected, $iTipMessage->message->serialize());
+ }));
+
+
+
+ $response = $this->controller->decline('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-success', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ $this->assertTrue($called);
+ }
+
+ public function testOptions() {
+ $response = $this->controller->options('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-options', $response->getTemplateName());
+ $this->assertEquals(['token' => 'TOKEN123'], $response->getParams());
+ }
+
+ public function testProcessMoreOptionsResult() {
+ $this->request->expects($this->at(0))
+ ->method('getParam')
+ ->with('partStat')
+ ->will($this->returnValue('TENTATIVE'));
+ $this->request->expects($this->at(1))
+ ->method('getParam')
+ ->with('guests')
+ ->will($this->returnValue('7'));
+ $this->request->expects($this->at(2))
+ ->method('getParam')
+ ->with('comment')
+ ->will($this->returnValue('Foo bar Bli blub'));
+
+ $this->buildQueryExpects('TOKEN123', [
+ 'id' => 0,
+ 'uid' => 'this-is-the-events-uid',
+ 'recurrenceid' => null,
+ 'attendee' => 'mailto:attendee@foo.bar',
+ 'organizer' => 'mailto:organizer@foo.bar',
+ 'sequence' => null,
+ 'token' => 'TOKEN123',
+ 'expiration' => 420000,
+ ], 1337);
+
+ $expected = <<<EOF
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
+METHOD:REPLY
+BEGIN:VEVENT
+ATTENDEE;PARTSTAT=TENTATIVE;X-RESPONSE-COMMENT=Foo bar Bli blub;X-NUM-GUEST
+ S=7:mailto:attendee@foo.bar
+ORGANIZER:mailto:organizer@foo.bar
+UID:this-is-the-events-uid
+SEQUENCE:0
+REQUEST-STATUS:2.0;Success
+DTSTAMP:19700101T002217Z
+COMMENT:Foo bar Bli blub
+END:VEVENT
+END:VCALENDAR
+
+EOF;
+ $expected = preg_replace('~\R~u', "\r\n", $expected);
+
+ $called = false;
+ $this->responseServer->expects($this->once())
+ ->method('handleITipMessage')
+ ->will($this->returnCallback(function(Message $iTipMessage) use (&$called, $expected) {
+ $called = true;
+ $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid);
+ $this->assertEquals('VEVENT', $iTipMessage->component);
+ $this->assertEquals('REPLY', $iTipMessage->method);
+ $this->assertEquals(null, $iTipMessage->sequence);
+ $this->assertEquals('mailto:attendee@foo.bar', $iTipMessage->sender);
+ $this->assertEquals('mailto:organizer@foo.bar', $iTipMessage->recipient);
+
+ $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
+
+ $this->assertEquals($expected, $iTipMessage->message->serialize());
+ }));
+
+
+
+ $response = $this->controller->processMoreOptionsResult('TOKEN123');
+ $this->assertInstanceOf(TemplateResponse::class, $response);
+ $this->assertEquals('schedule-response-success', $response->getTemplateName());
+ $this->assertEquals([], $response->getParams());
+ $this->assertTrue($called);
+ }
+
+ private function buildQueryExpects($token, $return, $time) {
+ $queryBuilder = $this->createMock(IQueryBuilder::class);
+ $stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
+ $expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
+
+ $this->dbConnection->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->method('expr')
+ ->will($this->returnValue($expr));
+ $queryBuilder->method('createNamedParameter')
+ ->will($this->returnValueMap([
+ [$token, \PDO::PARAM_STR, null, 'namedParameterToken']
+ ]));
+
+ $stmt->expects($this->once())
+ ->method('fetch')
+ ->with(\PDO::FETCH_ASSOC)
+ ->will($this->returnValue($return));
+
+ $expr->expects($this->once())
+ ->method('eq')
+ ->with('token', 'namedParameterToken')
+ ->will($this->returnValue('EQ STATEMENT'));
+
+ $this->dbConnection->expects($this->once())
+ ->method('getQueryBuilder')
+ ->with()
+ ->will($this->returnValue($queryBuilder));
+
+ $queryBuilder->expects($this->at(0))
+ ->method('select')
+ ->with('*')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(1))
+ ->method('from')
+ ->with('calendar_invitation_tokens')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(4))
+ ->method('where')
+ ->with('EQ STATEMENT')
+ ->will($this->returnValue($queryBuilder));
+ $queryBuilder->expects($this->at(5))
+ ->method('execute')
+ ->with()
+ ->will($this->returnValue($stmt));
+
+ $this->timeFactory->method('getTime')
+ ->will($this->returnValue($time));
+ }
+} \ No newline at end of file