2016-08-18 18:04:04 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV;
|
|
|
|
|
2016-10-13 12:04:22 +03:00
|
|
|
use OCA\DAV\CalDAV\Activity\Backend as ActivityBackend;
|
2016-08-18 18:04:04 +03:00
|
|
|
use OCA\DAV\CalDAV\Calendar;
|
2016-08-30 20:21:32 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
2016-10-13 12:04:22 +03:00
|
|
|
use OCP\Activity\IManager as IActivityManager;
|
|
|
|
use OCP\IGroupManager;
|
2016-08-18 18:04:04 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
|
|
|
use OCA\DAV\CalDAV\PublicCalendarRoot;
|
2016-08-30 20:21:32 +03:00
|
|
|
use OCP\IUserManager;
|
2016-10-13 12:04:22 +03:00
|
|
|
use OCP\IUserSession;
|
2016-09-03 11:52:05 +03:00
|
|
|
use OCP\Security\ISecureRandom;
|
2016-08-18 18:04:04 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PublicCalendarRootTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\Tests\unit\CalDAV
|
|
|
|
*/
|
|
|
|
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;
|
2016-10-13 12:04:22 +03:00
|
|
|
/** @var Principal|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-30 20:21:32 +03:00
|
|
|
private $principal;
|
2016-10-13 12:04:22 +03:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $userManager;
|
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $groupManager;
|
|
|
|
/** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $activityManager;
|
|
|
|
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $userSession;
|
|
|
|
/** @var ActivityBackend|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $activityBackend;
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
/** @var ISecureRandom */
|
|
|
|
private $random;
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$db = \OC::$server->getDatabaseConnection();
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
$activityManager = $this->createMock(IActivityManager::class);
|
|
|
|
$userSession = $this->createMock(IUserSession::class);
|
2016-09-03 11:52:05 +03:00
|
|
|
$this->random = \OC::$server->getSecureRandom();
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2016-08-30 20:21:32 +03:00
|
|
|
$this->backend = new CalDavBackend(
|
|
|
|
$db,
|
|
|
|
$this->principal,
|
|
|
|
$this->userManager,
|
2016-10-13 12:04:22 +03:00
|
|
|
$groupManager,
|
|
|
|
$this->random,
|
|
|
|
$activityManager,
|
|
|
|
$userSession
|
2016-08-30 20:21:32 +03:00
|
|
|
);
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityBackend = $this->createMock(ActivityBackend::class);
|
|
|
|
$this->invokePrivate($this->backend, 'activityBackend', [$this->activityBackend]);
|
|
|
|
|
2016-08-18 18:04:04 +03:00
|
|
|
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend);
|
|
|
|
|
|
|
|
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
}
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 18:04:04 +03:00
|
|
|
public function testGetName() {
|
|
|
|
$name = $this->publicCalendarRoot->getName();
|
|
|
|
$this->assertEquals('public-calendars', $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetChild() {
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityBackend->expects($this->exactly(1))
|
|
|
|
->method('addCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('updateCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('deleteCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('updateCalendarShares');
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
$calendar = $this->createPublicCalendar();
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$publicCalendars = $this->backend->getPublicCalendars();
|
|
|
|
$this->assertEquals(1, count($publicCalendars));
|
|
|
|
$this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']);
|
|
|
|
|
|
|
|
$publicCalendarURI = $publicCalendars[0]['uri'];
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
$calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI);
|
|
|
|
$this->assertEquals($calendar, $calendarResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetChildren() {
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->activityBackend->expects($this->exactly(1))
|
|
|
|
->method('addCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('updateCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('deleteCalendar');
|
|
|
|
$this->activityBackend->expects($this->never())
|
|
|
|
->method('updateCalendarShares');
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$this->createPublicCalendar();
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
$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];
|
2016-09-03 11:52:05 +03:00
|
|
|
$calendar = new Calendar($this->backend, $calendarInfo, $this->l10n);
|
|
|
|
$publicUri = $calendar->setPublishStatus(true);
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$calendarInfo = $this->backend->getPublicCalendar($publicUri);
|
2016-08-18 18:04:04 +03:00
|
|
|
$calendar = new Calendar($this->backend, $calendarInfo, $this->l10n);
|
|
|
|
|
|
|
|
return $calendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|