|
9 | 9 | namespace OCA\DAV\Tests\unit\CalDAV; |
10 | 10 |
|
11 | 11 | use OCA\DAV\CalDAV\Plugin; |
| 12 | +use OCP\IConfig; |
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use Sabre\DAV\Exception\UnsupportedMediaType; |
| 15 | +use Sabre\DAV\Server as SabreServer; |
| 16 | +use Sabre\HTTP\RequestInterface; |
| 17 | +use Sabre\HTTP\ResponseInterface; |
12 | 18 | use Test\TestCase; |
13 | 19 |
|
14 | 20 | class PluginTest extends TestCase { |
@@ -45,4 +51,56 @@ public function testGetCalendarHomeForPrincipal(string $input, string $expected) |
45 | 51 | public function testGetCalendarHomeForUnknownPrincipal(): void { |
46 | 52 | $this->assertNull($this->plugin->getCalendarHomeForPrincipal('FOO/BAR/BLUB')); |
47 | 53 | } |
| 54 | + |
| 55 | + private const ICS_ENTOURAGE = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Test//Test//EN\r\nBEGIN:VEVENT\r\nDTSTART:20260715T100000Z\r\nDTEND:20260715T110000Z\r\nSUMMARY:Test\r\nUID:test-uid-123\r\nX-ENTOURAGE_UUID:test-uid-123\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; |
| 56 | + |
| 57 | + private function makePlugin(bool $forgiving): Plugin { |
| 58 | + /** @var IConfig&MockObject $config */ |
| 59 | + $config = $this->createMock(IConfig::class); |
| 60 | + $config->method('getSystemValueBool') |
| 61 | + ->with('dav.forgiving_ical_parser', false) |
| 62 | + ->willReturn($forgiving); |
| 63 | + |
| 64 | + $plugin = new class($config) extends Plugin { |
| 65 | + public function exposeValidateICalendar(string &$data, string $path, bool &$modified, RequestInterface $request, ResponseInterface $response, bool $isNew): void { |
| 66 | + $this->validateICalendar($data, $path, $modified, $request, $response, $isNew); |
| 67 | + } |
| 68 | + }; |
| 69 | + |
| 70 | + /** @var SabreServer&MockObject $server */ |
| 71 | + $server = $this->createMock(SabreServer::class); |
| 72 | + $server->method('getProperties')->willReturn([]); |
| 73 | + $server->method('getHTTPPrefer')->willReturn(['handling' => 'lenient']); |
| 74 | + $server->method('emit')->willReturn(true); |
| 75 | + |
| 76 | + // Inject server without calling initialize() to avoid its side effects on xml/resourceTypeMapping |
| 77 | + $prop = new \ReflectionProperty(\Sabre\CalDAV\Plugin::class, 'server'); |
| 78 | + $prop->setValue($plugin, $server); |
| 79 | + |
| 80 | + return $plugin; |
| 81 | + } |
| 82 | + |
| 83 | + public function testValidateICalendarRejectsNonStandardPropertyWhenFlagDisabled(): void { |
| 84 | + $plugin = $this->makePlugin(false); |
| 85 | + $data = self::ICS_ENTOURAGE; |
| 86 | + $modified = false; |
| 87 | + $request = $this->createMock(RequestInterface::class); |
| 88 | + $response = $this->createMock(ResponseInterface::class); |
| 89 | + |
| 90 | + $this->expectException(UnsupportedMediaType::class); |
| 91 | + $plugin->exposeValidateICalendar($data, 'calendars/admin/personal/test.ics', $modified, $request, $response, true); |
| 92 | + } |
| 93 | + |
| 94 | + public function testValidateICalendarAcceptsNonStandardPropertyWhenFlagEnabled(): void { |
| 95 | + $plugin = $this->makePlugin(true); |
| 96 | + $data = self::ICS_ENTOURAGE; |
| 97 | + $modified = false; |
| 98 | + $request = $this->createMock(RequestInterface::class); |
| 99 | + $response = $this->createMock(ResponseInterface::class); |
| 100 | + $response->expects($this->once()) |
| 101 | + ->method('setHeader') |
| 102 | + ->with('X-Sabre-Ew-Gross', $this->stringContains('X-ENTOURAGE_UUID')); |
| 103 | + |
| 104 | + $plugin->exposeValidateICalendar($data, 'calendars/admin/personal/test.ics', $modified, $request, $response, true); |
| 105 | + } |
48 | 106 | } |
0 commit comments