aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV/Validation/CalDavValidatePluginTest.php
blob: 384ddec2804ace51e07916fe2d1a1d5229ea7c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php

declare(strict_types=1);

/*
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\DAV\Tests\unit\CalDAV\Validation;

use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Exception\Forbidden;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Test\TestCase;

class CalDavValidatePluginTest extends TestCase {

	private CalDavValidatePlugin $plugin;
	private IConfig|MockObject $config;
	private RequestInterface|MockObject $request;
	private ResponseInterface|MockObject $response;

	protected function setUp(): void {
		parent::setUp();
		// construct mock objects
		$this->config = $this->createMock(IConfig::class);
		$this->request = $this->createMock(RequestInterface::class);
		$this->response = $this->createMock(ResponseInterface::class);
		$this->plugin = new CalDavValidatePlugin(
			$this->config,
		);
	}

	public function testPutSizeLessThenLimit(): void {
		
		// construct method responses
		$this->config
			->method('getAppValue')
			->with('dav', 'event_size_limit', '10485760')
			->willReturn(10485760);
		$this->request
			->method('getRawServerValue')
			->with('CONTENT_LENGTH')
			->willReturn('1024');
		// test condition
		$this->assertTrue(
			$this->plugin->beforePut($this->request, $this->response)
		);
		
	}

	public function testPutSizeMoreThenLimit(): void {
		
		// construct method responses
		$this->config
			->method('getAppValue')
			->with('dav', 'event_size_limit', '10485760')
			->willReturn(10485760);
		$this->request
			->method('getRawServerValue')
			->with('CONTENT_LENGTH')
			->willReturn('16242880');
		$this->expectException(Forbidden::class);
		// test condition
		$this->plugin->beforePut($this->request, $this->response);
		
	}

}