1
0

ApiControllerTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\AppFramework\Controller;
  8. use OC\AppFramework\Http\Request;
  9. use OCP\AppFramework\ApiController;
  10. use OCP\IConfig;
  11. use OCP\IRequestId;
  12. class ChildApiController extends ApiController {
  13. };
  14. class ApiControllerTest extends \Test\TestCase {
  15. /** @var ChildApiController */
  16. protected $controller;
  17. public function testCors() {
  18. $request = new Request(
  19. ['server' => ['HTTP_ORIGIN' => 'test']],
  20. $this->createMock(IRequestId::class),
  21. $this->createMock(IConfig::class)
  22. );
  23. $this->controller = new ChildApiController('app', $request, 'verbs',
  24. 'headers', 100);
  25. $response = $this->controller->preflightedCors();
  26. $headers = $response->getHeaders();
  27. $this->assertEquals('test', $headers['Access-Control-Allow-Origin']);
  28. $this->assertEquals('verbs', $headers['Access-Control-Allow-Methods']);
  29. $this->assertEquals('headers', $headers['Access-Control-Allow-Headers']);
  30. $this->assertEquals('false', $headers['Access-Control-Allow-Credentials']);
  31. $this->assertEquals(100, $headers['Access-Control-Max-Age']);
  32. }
  33. }