From ff67cbc6af144c92d4b1e69d6c606c1fdbf177d4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 18 Aug 2016 17:04:04 +0200 Subject: [PATCH] Add test for PublicCalendarRoot --- .../unit/CalDAV/PublicCalendarRootTest.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php new file mode 100644 index 0000000000..9ce558ad34 --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -0,0 +1,103 @@ +getDatabaseConnection(); + $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') + ->disableOriginalConstructor() + ->getMock(); + $this->config = \OC::$server->getConfig(); + + $this->backend = new CalDavBackend($db, $this->principal, $this->config); + + $this->publicCalendarRoot = new PublicCalendarRoot($this->backend); + + $this->l10n = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor()->getMock(); + } + + public function testGetName() { + $name = $this->publicCalendarRoot->getName(); + $this->assertEquals('public-calendars', $name); + } + + public function testGetChild() { + + $calendar = $this->createPublicCalendar(); + + $publicCalendarURI = md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId()); + + $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); + $this->assertEquals($calendar, $calendarResult); + } + + public function testGetChildren() { + + $publicCalendars = $this->backend->getPublicCalendars(); + + $calendarResults = $this->publicCalendarRoot->getChildren(); + + $this->assertEquals(1, count($calendarResults)); + $this->assertEquals(new Calendar($this->backend, $publicCalendars[0], $this->l10n), $calendarResults[0]); + + } + + /** + * @return Calendar + */ + protected function createPublicCalendar() { + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); + + $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; + + $calendarInfo['uri'] = md5($this->config->getSystemValue('secret', '') . $calendarInfo['id']); + list(, $name) = Uri\split($calendarInfo['principaluri']); + $calendarInfo['{DAV:}displayname'] = $calendarInfo['{DAV:}displayname'] . ' (' . $name . ')'; + $calendarInfo['{http://owncloud.org/ns}owner-principal'] = $calendarInfo['principaluri']; + $calendarInfo['{http://owncloud.org/ns}read-only'] = false; + $calendarInfo['{http://owncloud.org/ns}public'] = true; + + $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); + $calendar->setPublishStatus(true); + + return $calendar; + } + + +}