diff options
Diffstat (limited to 'apps/dav/tests/unit/CalDAV')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php | 43 |
3 files changed, 34 insertions, 19 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php index 589c00c377a..2559ecbbf89 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackendTest.php @@ -29,6 +29,7 @@ use OCA\DAV\CalDAV\Calendar; use OCA\DAV\Connector\Sabre\Principal; use OCP\IL10N; use OCP\IConfig; +use OCP\Security\ISecureRandom; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\DAV\PropPatch; use Sabre\DAV\Xml\Property\Href; @@ -56,6 +57,9 @@ abstract class AbstractCalDavBackendTest extends TestCase { /** var OCP\IConfig */ protected $config; + /** @var ISecureRandom */ + private $random; + const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; @@ -80,8 +84,8 @@ abstract class AbstractCalDavBackendTest extends TestCase { $db = \OC::$server->getDatabaseConnection(); $this->config = \OC::$server->getConfig(); - $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->config); - + $this->random = \OC::$server->getSecureRandom(); + $this->backend = new CalDavBackend($db, $this->principal, $this->userManager, $this->config, $this->random); $this->tearDown(); } diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 0c07ed7c292..6f846515d8e 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -350,7 +350,7 @@ EOD; $this->assertEquals(1, count($publicCalendars)); $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); - $publicCalendarURI = md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId()); + $publicCalendarURI = $publicCalendars[0]['uri']; $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI); $this->assertEquals(true, $publicCalendar['{http://owncloud.org/ns}public']); diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index 85aad24d368..6dfec6d7e1f 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -5,12 +5,11 @@ namespace OCA\DAV\Tests\unit\CalDAV; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\Connector\Sabre\Principal; use OCP\IL10N; -use OCP\IConfig; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\PublicCalendarRoot; use OCP\IUserManager; +use OCP\Security\ISecureRandom; use Test\TestCase; -use Sabre\Uri; /** * Class PublicCalendarRootTest @@ -22,13 +21,10 @@ use Sabre\Uri; class PublicCalendarRootTest extends TestCase { const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; - /** @var CalDavBackend */ private $backend; - /** @var PublicCalendarRoot */ private $publicCalendarRoot; - /** @var IL10N */ private $l10n; /** @var IUserManager */ @@ -37,6 +33,8 @@ class PublicCalendarRootTest extends TestCase { private $principal; /** var IConfig */ protected $config; + /** @var ISecureRandom */ + private $random; public function setUp() { parent::setUp(); @@ -47,12 +45,14 @@ class PublicCalendarRootTest extends TestCase { ->getMock(); $this->config = \OC::$server->getConfig(); $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->random = \OC::$server->getSecureRandom(); $this->backend = new CalDavBackend( $db, $this->principal, $this->userManager, - $this->config + $this->config, + $this->random ); $this->publicCalendarRoot = new PublicCalendarRoot($this->backend); @@ -61,6 +61,18 @@ class PublicCalendarRootTest extends TestCase { ->disableOriginalConstructor()->getMock(); } + public function tearDown() { + parent::tearDown(); + + if (is_null($this->backend)) { + return; + } + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); + foreach ($books as $book) { + $this->backend->deleteCalendar($book['id']); + } + } + public function testGetName() { $name = $this->publicCalendarRoot->getName(); $this->assertEquals('public-calendars', $name); @@ -70,13 +82,18 @@ class PublicCalendarRootTest extends TestCase { $calendar = $this->createPublicCalendar(); - $publicCalendarURI = md5($this->config->getSystemValue('secret', '') . $calendar->getResourceId()); + $publicCalendars = $this->backend->getPublicCalendars(); + $this->assertEquals(1, count($publicCalendars)); + $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']); + + $publicCalendarURI = $publicCalendars[0]['uri']; $calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI); $this->assertEquals($calendar, $calendarResult); } public function testGetChildren() { + $this->createPublicCalendar(); $publicCalendars = $this->backend->getPublicCalendars(); @@ -84,7 +101,6 @@ class PublicCalendarRootTest extends TestCase { $this->assertEquals(1, count($calendarResults)); $this->assertEquals(new Calendar($this->backend, $publicCalendars[0], $this->l10n), $calendarResults[0]); - } /** @@ -94,16 +110,11 @@ class PublicCalendarRootTest extends TestCase { $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; + $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); + $publicUri = $calendar->setPublishStatus(true); - $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; - + $calendarInfo = $this->backend->getPublicCalendar($publicUri); $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n); - $calendar->setPublishStatus(true); return $calendar; } |