Add tests for dispatching of the events

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-11-03 12:28:12 +01:00
parent 52dd27892b
commit e8f82c6b61
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
2 changed files with 66 additions and 5 deletions

View File

@ -46,6 +46,8 @@ abstract class AbstractCalDavBackendTest extends TestCase {
protected $principal; protected $principal;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
protected $userManager; protected $userManager;
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $dispatcher;
/** @var ISecureRandom */ /** @var ISecureRandom */
private $random; private $random;
@ -58,7 +60,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
parent::setUp(); parent::setUp();
$this->userManager = $this->createMock(IUserManager::class); $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') $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->setMethods(['getPrincipalByPath', 'getGroupMembership'])
@ -73,7 +75,7 @@ abstract class AbstractCalDavBackendTest extends TestCase {
$db = \OC::$server->getDatabaseConnection(); $db = \OC::$server->getDatabaseConnection();
$this->random = \OC::$server->getSecureRandom(); $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(); $this->cleanUpBackend();
} }
@ -87,9 +89,13 @@ abstract class AbstractCalDavBackendTest extends TestCase {
if (is_null($this->backend)) { if (is_null($this->backend)) {
return; return;
} }
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
foreach ($books as $book) { foreach ($calendars as $calendar) {
$this->backend->deleteCalendar($book['id']); $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); $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
foreach ($subscriptions as $subscription) { foreach ($subscriptions as $subscription) {
@ -98,6 +104,10 @@ abstract class AbstractCalDavBackendTest extends TestCase {
} }
protected function createTestCalendar() { 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', [ $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [
'{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF'
]); ]);
@ -135,6 +145,11 @@ END:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
$uri0 = $this->getUniqueID('event'); $uri0 = $this->getUniqueID('event');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri0, $calData); $this->backend->createCalendarObject($calendarId, $uri0, $calData);
return $uri0; return $uri0;

View File

@ -51,6 +51,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
'{DAV:}displayname' => 'Unit test', '{DAV:}displayname' => 'Unit test',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing' '{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); $this->backend->updateCalendar($calendarId, $patch);
$patch->commit(); $patch->commit();
$this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER)); $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']); $this->assertEquals('Calendar used for unit testing', $books[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
// delete the address book // delete the address book
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']); $this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books)); $this->assertEquals(0, count($books));
@ -106,6 +112,9 @@ class CalDavBackendTest extends AbstractCalDavBackendTest {
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(1, count($books)); $this->assertEquals(1, count($books));
$calendar = new Calendar($this->backend, $books[0], $l10n); $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, []); $this->backend->updateShares($calendar, $add, []);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertEquals(1, count($books)); $this->assertEquals(1, count($books));
@ -138,6 +147,9 @@ END:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData); $this->backend->createCalendarObject($calendarId, $uri, $calData);
/** @var IACL $child */ /** @var IACL $child */
@ -151,6 +163,9 @@ EOD;
$this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl); $this->assertAccess($groupCanWrite, self::UNIT_TEST_GROUP, '{DAV:}write', $acl);
// delete the address book // delete the address book
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
$this->backend->deleteCalendar($books[0]['id']); $this->backend->deleteCalendar($books[0]['id']);
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertEquals(0, count($books)); $this->assertEquals(0, count($books));
@ -179,6 +194,9 @@ END:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri, $calData); $this->backend->createCalendarObject($calendarId, $uri, $calData);
// get all the cards // get all the cards
@ -214,11 +232,17 @@ DTEND;VALUE=DATE-TIME:20130912T140000Z
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject');
$this->backend->updateCalendarObject($calendarId, $uri, $calData); $this->backend->updateCalendarObject($calendarId, $uri, $calData);
$calendarObject = $this->backend->getCalendarObject($calendarId, $uri); $calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
$this->assertEquals($calData, $calendarObject['calendardata']); $this->assertEquals($calData, $calendarObject['calendardata']);
// delete the card // delete the card
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri); $this->backend->deleteCalendarObject($calendarId, $uri);
$calendarObjects = $this->backend->getCalendarObjects($calendarId); $calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects)); $this->assertEquals(0, count($calendarObjects));
@ -246,10 +270,19 @@ END:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
$uri0 = $this->getUniqueID('card'); $uri0 = $this->getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri0, $calData); $this->backend->createCalendarObject($calendarId, $uri0, $calData);
$uri1 = $this->getUniqueID('card'); $uri1 = $this->getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri1, $calData); $this->backend->createCalendarObject($calendarId, $uri1, $calData);
$uri2 = $this->getUniqueID('card'); $uri2 = $this->getUniqueID('card');
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
$this->backend->createCalendarObject($calendarId, $uri2, $calData); $this->backend->createCalendarObject($calendarId, $uri2, $calData);
// get all the cards // get all the cards
@ -270,8 +303,17 @@ EOD;
} }
// delete the card // delete the card
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri0); $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->backend->deleteCalendarObject($calendarId, $uri1);
$this->dispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
$this->backend->deleteCalendarObject($calendarId, $uri2); $this->backend->deleteCalendarObject($calendarId, $uri2);
$calendarObjects = $this->backend->getCalendarObjects($calendarId); $calendarObjects = $this->backend->getCalendarObjects($calendarId);
$this->assertEquals(0, count($calendarObjects)); $this->assertEquals(0, count($calendarObjects));
@ -335,6 +377,10 @@ EOD;
} }
public function testPublications() { 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', []); $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];