|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\DAV\Tests\unit\CalDAV\Validation; |
| 11 | + |
| 12 | +use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin; |
| 13 | +use OCP\IConfig; |
| 14 | +use PHPUnit\Framework\MockObject\MockObject; |
| 15 | +use Sabre\DAV\Exception\Forbidden; |
| 16 | +use Sabre\HTTP\RequestInterface; |
| 17 | +use Sabre\HTTP\ResponseInterface; |
| 18 | +use Test\TestCase; |
| 19 | + |
| 20 | +class CalDavValidatePluginTest extends TestCase { |
| 21 | + |
| 22 | + private CalDavValidatePlugin $plugin; |
| 23 | + private IConfig|MockObject $config; |
| 24 | + private RequestInterface|MockObject $request; |
| 25 | + private ResponseInterface|MockObject $response; |
| 26 | + |
| 27 | + protected function setUp(): void { |
| 28 | + parent::setUp(); |
| 29 | + // construct mock objects |
| 30 | + $this->config = $this->createMock(IConfig::class); |
| 31 | + $this->request = $this->createMock(RequestInterface::class); |
| 32 | + $this->response = $this->createMock(ResponseInterface::class); |
| 33 | + $this->plugin = new CalDavValidatePlugin( |
| 34 | + $this->config, |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + public function testPutSizeLessThenLimit(): void { |
| 39 | + |
| 40 | + // construct method responses |
| 41 | + $this->config |
| 42 | + ->method('getAppValue') |
| 43 | + ->with('dav', 'event_size_limit', 10485760) |
| 44 | + ->willReturn(10485760); |
| 45 | + $this->request |
| 46 | + ->method('getRawServerValue') |
| 47 | + ->with('CONTENT_LENGTH') |
| 48 | + ->willReturn('1024'); |
| 49 | + // test condition |
| 50 | + $this->assertTrue( |
| 51 | + $this->plugin->beforePut($this->request, $this->response) |
| 52 | + ); |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + public function testPutSizeMoreThenLimit(): void { |
| 57 | + |
| 58 | + // construct method responses |
| 59 | + $this->config |
| 60 | + ->method('getAppValue') |
| 61 | + ->with('dav', 'event_size_limit', 10485760) |
| 62 | + ->willReturn(10485760); |
| 63 | + $this->request |
| 64 | + ->method('getRawServerValue') |
| 65 | + ->with('CONTENT_LENGTH') |
| 66 | + ->willReturn('16242880'); |
| 67 | + $this->expectException(Forbidden::class); |
| 68 | + // test condition |
| 69 | + $this->plugin->beforePut($this->request, $this->response); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments