CalDavValidatePluginTest.php 1.8 KB

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