WellKnownControllerTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Tests\Core\Controller;
  8. use OC\Core\Controller\WellKnownController;
  9. use OC\Http\WellKnown\RequestManager;
  10. use OCP\AppFramework\Http\JSONResponse;
  11. use OCP\Http\WellKnown\IResponse;
  12. use OCP\IRequest;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use Test\TestCase;
  15. class WellKnownControllerTest extends TestCase {
  16. /** @var IRequest|MockObject */
  17. private $request;
  18. /** @var RequestManager|MockObject */
  19. private $manager;
  20. /** @var WellKnownController */
  21. private $controller;
  22. protected function setUp(): void {
  23. parent::setUp();
  24. $this->request = $this->createMock(IRequest::class);
  25. $this->manager = $this->createMock(RequestManager::class);
  26. $this->controller = new WellKnownController(
  27. $this->request,
  28. $this->manager,
  29. );
  30. }
  31. public function testHandleNotProcessed(): void {
  32. $httpResponse = $this->controller->handle("nodeinfo");
  33. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  34. self::assertArrayHasKey('X-NEXTCLOUD-WELL-KNOWN', $httpResponse->getHeaders());
  35. }
  36. public function testHandle(): void {
  37. $response = $this->createMock(IResponse::class);
  38. $jsonResponse = $this->createMock(JSONResponse::class);
  39. $response->expects(self::once())
  40. ->method('toHttpResponse')
  41. ->willReturn($jsonResponse);
  42. $this->manager->expects(self::once())
  43. ->method('process')
  44. ->with(
  45. "nodeinfo",
  46. $this->request
  47. )->willReturn($response);
  48. $jsonResponse->expects(self::once())
  49. ->method('addHeader')
  50. ->willReturnSelf();
  51. $httpResponse = $this->controller->handle("nodeinfo");
  52. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  53. }
  54. }