summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-11-03 12:28:12 +0100
committerJoas Schilling <coding@schilljs.com>2016-11-03 12:28:12 +0100
commite8f82c6b61ec293c354c417762d4279a877372a4 (patch)
tree89d0c79f12ba9ced2fa038ccb1b6e03199d2b887 /apps
parent52dd27892b80ab91d0776c45d05d8447ac24b76e (diff)
downloadnextcloud-server-e8f82c6b61ec293c354c417762d4279a877372a4.tar.gz
nextcloud-server-e8f82c6b61ec293c354c417762d4279a877372a4.zip
Add tests for dispatching of the events
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php25
-rw-r--r--apps/dav/tests/unit/CalDAV/CalDavBackendTest.php46
2 files changed, 66 insertions, 5 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
index 7d2e033e0b1..d15be72c77b 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php
@@ -46,6 +46,8 @@ abstract class AbstractCalDavBackendTest extends TestCase {
protected $principal;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager;
+ /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
+ protected $dispatcher;
/** @var ISecureRandom */
private $random;
@@ -58,7 +60,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
parent::setUp();
$this->userManager = $this->createMock(IUserManager::class);
- $dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
$this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
@@ -73,7 +75,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
$db = \OC::$server->getDatabaseConnection();
$this->random = \OC::$server->getSecureRandom();
- $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->random, $dispatcher);
+ $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->random, $this->dispatcher);
$this->cleanUpBackend();
}
@@ -87,9 +89,13 @@ abstract class AbstractCalDavBackendTest extends TestCase {
if (is_null($this->backend)) {
return;
}
- $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
- foreach ($books as $book) {
- $this->backend->deleteCalendar($book['id']);
+ $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
+ foreach ($calendars as $calendar) {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
+
+ $this->backend->deleteCalendar($calendar['id']);
}
$subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
foreach ($subscriptions as $subscription) {
@@ -98,6 +104,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
}
protected function createTestCalendar() {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
+
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
]);
@@ -135,6 +145,11 @@ END:VEVENT
END:VCALENDAR
EOD;
$uri0 = $this->getUniqueID('event');
+
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
+
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
return $uri0;
diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
index 4d60e983b13..b5e700e8bc4 100644
--- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
+++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php
@@ -51,6 +51,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
'{DAV:}displayname' => 'Unit test',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
]);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar');
$this->backend->updateCalendar($calendarId, $patch);
$patch->commit();
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
@@ -60,6 +63,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$this->assertEquals('Calendar used for unit testing', $books[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
// delete the address book
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books));
@@ -106,6 +112,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0], $l10n);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
$this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books));
@@ -138,6 +147,9 @@ END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData);
/** @var IACL $child */
@@ -151,6 +163,9 @@ EOD;
$this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl);
// delete the address book
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books));
@@ -179,6 +194,9 @@ END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData);
// get all the cards
@@ -214,11 +232,17 @@ DTEND;VALUE=DATE-TIME:20130912T140000Z
END:VEVENT
END:VCALENDAR
EOD;
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject');
$this->backend->updateCalendarObject($calendarId, $uri, $calData);
$calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
$this->assertEquals($calData, $calendarObject['calendardata']);
// delete the card
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects));
@@ -246,10 +270,19 @@ END:VEVENT
END:VCALENDAR
EOD;
$uri0 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri0, $calData);
$uri1 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri1, $calData);
$uri2 = $this->getUniqueID('card');
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri2, $calData);
// get all the cards
@@ -270,8 +303,17 @@ EOD;
}
// delete the card
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri0);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri1);
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri2);
$calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects));
@@ -335,6 +377,10 @@ EOD;
}
public function testPublications() {
+ $this->dispatcher->expects($this->at(0))
+ ->method('dispatch')
+ ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
+
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];