|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @license GNU AGPL version 3 or any later version |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Affero General Public License as |
| 7 | + * published by the Free Software Foundation, either version 3 of the |
| 8 | + * License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Affero General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Affero General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + */ |
| 19 | +namespace OCA\DAV\Tests\unit\CalDAV\BirthdayCalendar; |
| 20 | + |
| 21 | +use OCA\DAV\CalDAV\AppCalendar\AppCalendar; |
| 22 | +use OCP\Calendar\ICalendar; |
| 23 | +use OCP\Calendar\ICreateFromString; |
| 24 | +use OCP\Constants; |
| 25 | +use Test\TestCase; |
| 26 | + |
| 27 | +class AppCalendarTest extends TestCase { |
| 28 | + private AppCalendar $appCalendar; |
| 29 | + private AppCalendar $writeableAppCalendar; |
| 30 | + |
| 31 | + private $principal = 'principals/users/foo'; |
| 32 | + |
| 33 | + protected function setUp(): void { |
| 34 | + parent::setUp(); |
| 35 | + |
| 36 | + $calendar = $this->getMock(ICalendar::class); |
| 37 | + $writeableCalendar = $this->getMock(ICreateFromString::class); |
| 38 | + $writeableCalendar->method('getPermissions') |
| 39 | + ->will($this->returnArgument(Constants::PERMISSION_READ | Constants::PERMISSION_CREATE)); |
| 40 | + $this->appCalendar = $this->createMock(AppCalendar::class, ['dav-wrapper', $calendar, $this->principal]); |
| 41 | + $this->writeableAppCalendar = $this->createMock(AppCalendar::class, ['dav-wrapper', $writeableCalendar, $this->principal]); |
| 42 | + } |
| 43 | + |
| 44 | + public function testGetPrincipal():void { |
| 45 | + // Check that the correct name is returned |
| 46 | + $this->assertEquals($this->principal, $this->appCalendar->getOwner()); |
| 47 | + $this->assertEquals($this->principal, $this->writeableAppCalendar->getOwner()); |
| 48 | + } |
| 49 | + |
| 50 | + public function testSetACL(): void { |
| 51 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
| 52 | + $this->expectExceptionMessage('Setting ACL is not supported on this node'); |
| 53 | + |
| 54 | + $this->appCalendar->setACL([]); |
| 55 | + } |
| 56 | + |
| 57 | + public function testDelete(): void { |
| 58 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
| 59 | + $this->expectExceptionMessage('Deleting an entry is not implemented'); |
| 60 | + |
| 61 | + $this->appCalendar->delete(); |
| 62 | + } |
| 63 | + |
| 64 | + public function testCreateFile() { |
| 65 | + // If writing is not supported |
| 66 | + $this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
| 67 | + $this->expectExceptionMessage('Creating a new entry is not implemented'); |
| 68 | + |
| 69 | + $this->appCalendar->createFile('some-name', 'data'); |
| 70 | + |
| 71 | + // If write is supported |
| 72 | + $this->assertNull($this->writeableAppCalendar->createFile('some-name', 'data')); |
| 73 | + } |
| 74 | + |
| 75 | + public function testGetACL():void { |
| 76 | + $expectedRO = [ |
| 77 | + [ |
| 78 | + 'privilege' => '{DAV:}read', |
| 79 | + 'principal' => $this->principal, |
| 80 | + 'protected' => true, |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'privilege' => '{DAV:}write-properties', |
| 84 | + 'principal' => $this->principal, |
| 85 | + 'protected' => true, |
| 86 | + ] |
| 87 | + ]; |
| 88 | + $expectedRW = $expectedRO; |
| 89 | + $expectedRW[] = [ |
| 90 | + 'privilege' => '{DAV:}write', |
| 91 | + 'principal' => $this->principal, |
| 92 | + 'protected' => true, |
| 93 | + ]; |
| 94 | + |
| 95 | + // Check that the correct ACL is returned (default be only readable) |
| 96 | + $this->assertEquals($expectedRO, $this->appCalendar->getACL()); |
| 97 | + $this->assertEquals($expectedRW, $this->writeableAppCalendar->getACL()); |
| 98 | + } |
| 99 | +} |
0 commit comments