2017-11-07 03:31:28 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
*
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-07 03:31:28 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-11-07 03:31:28 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
|
|
|
use OCA\DAV\CalDAV\Calendar;
|
|
|
|
use OCA\DAV\CalDAV\CalendarImpl;
|
|
|
|
|
|
|
|
class CalendarImplTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/** @var CalendarImpl */
|
|
|
|
private $calendarImpl;
|
|
|
|
|
|
|
|
/** @var Calendar | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $calendar;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $calendarInfo;
|
|
|
|
|
|
|
|
/** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $backend;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2017-11-07 03:31:28 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->calendar = $this->createMock(Calendar::class);
|
|
|
|
$this->calendarInfo = [
|
|
|
|
'id' => 'fancy_id_123',
|
|
|
|
'{DAV:}displayname' => 'user readable name 123',
|
|
|
|
'{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
|
|
|
|
];
|
|
|
|
$this->backend = $this->createMock(CalDavBackend::class);
|
|
|
|
|
|
|
|
$this->calendarImpl = new CalendarImpl($this->calendar,
|
|
|
|
$this->calendarInfo, $this->backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetKey() {
|
|
|
|
$this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDisplayname() {
|
|
|
|
$this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDisplayColor() {
|
|
|
|
$this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearch() {
|
|
|
|
$this->backend->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['SEARCHRESULTS']);
|
2017-11-07 03:31:28 +03:00
|
|
|
|
|
|
|
$result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337);
|
|
|
|
$this->assertEquals($result, ['SEARCHRESULTS']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPermissionRead() {
|
|
|
|
$this->calendar->expects($this->once())
|
|
|
|
->method('getACL')
|
|
|
|
->with()
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2017-11-07 03:31:28 +03:00
|
|
|
['privilege' => '{DAV:}read']
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2017-11-07 03:31:28 +03:00
|
|
|
|
|
|
|
$this->assertEquals(1, $this->calendarImpl->getPermissions());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPermissionWrite() {
|
|
|
|
$this->calendar->expects($this->once())
|
|
|
|
->method('getACL')
|
|
|
|
->with()
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2017-11-07 03:31:28 +03:00
|
|
|
['privilege' => '{DAV:}write']
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2017-11-07 03:31:28 +03:00
|
|
|
|
|
|
|
$this->assertEquals(6, $this->calendarImpl->getPermissions());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPermissionReadWrite() {
|
|
|
|
$this->calendar->expects($this->once())
|
|
|
|
->method('getACL')
|
|
|
|
->with()
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2017-11-07 03:31:28 +03:00
|
|
|
['privilege' => '{DAV:}read'],
|
|
|
|
['privilege' => '{DAV:}write']
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2017-11-07 03:31:28 +03:00
|
|
|
|
|
|
|
$this->assertEquals(7, $this->calendarImpl->getPermissions());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetPermissionAll() {
|
|
|
|
$this->calendar->expects($this->once())
|
|
|
|
->method('getACL')
|
|
|
|
->with()
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([
|
2017-11-07 03:31:28 +03:00
|
|
|
['privilege' => '{DAV:}all']
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2017-11-07 03:31:28 +03:00
|
|
|
|
|
|
|
$this->assertEquals(31, $this->calendarImpl->getPermissions());
|
|
|
|
}
|
|
|
|
}
|