CardDavValidatePluginTest.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\CardDAV\Validation;
  8. use OCA\DAV\CardDAV\Validation\CardDavValidatePlugin;
  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 CardDavValidatePluginTest extends TestCase {
  16. private CardDavValidatePlugin $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 CardDavValidatePlugin(
  27. $this->config,
  28. );
  29. }
  30. public function testPutSizeLessThenLimit(): void {
  31. // construct method responses
  32. $this->config
  33. ->method('getValueInt')
  34. ->with('dav', 'card_size_limit', 5242880)
  35. ->willReturn(5242880);
  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', 'card_size_limit', 5242880)
  50. ->willReturn(5242880);
  51. $this->request
  52. ->method('getRawServerValue')
  53. ->with('CONTENT_LENGTH')
  54. ->willReturn('6242880');
  55. $this->expectException(Forbidden::class);
  56. // test condition
  57. $this->plugin->beforePut($this->request, $this->response);
  58. }
  59. }