WellKnownControllerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. namespace Tests\Core\Controller;
  24. use OC\Core\Controller\WellKnownController;
  25. use OC\Http\WellKnown\RequestManager;
  26. use OCP\AppFramework\Http\JSONResponse;
  27. use OCP\Http\WellKnown\IResponse;
  28. use OCP\IRequest;
  29. use PHPUnit\Framework\MockObject\MockObject;
  30. use Test\TestCase;
  31. class WellKnownControllerTest extends TestCase {
  32. /** @var IRequest|MockObject */
  33. private $request;
  34. /** @var RequestManager|MockObject */
  35. private $manager;
  36. /** @var WellKnownController */
  37. private $controller;
  38. protected function setUp(): void {
  39. parent::setUp();
  40. $this->request = $this->createMock(IRequest::class);
  41. $this->manager = $this->createMock(RequestManager::class);
  42. $this->controller = new WellKnownController(
  43. $this->request,
  44. $this->manager,
  45. );
  46. }
  47. public function testHandleNotProcessed(): void {
  48. $httpResponse = $this->controller->handle("nodeinfo");
  49. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  50. self::assertArrayHasKey('X-NEXTCLOUD-WELL-KNOWN', $httpResponse->getHeaders());
  51. }
  52. public function testHandle(): void {
  53. $response = $this->createMock(IResponse::class);
  54. $jsonResponse = $this->createMock(JSONResponse::class);
  55. $response->expects(self::once())
  56. ->method('toHttpResponse')
  57. ->willReturn($jsonResponse);
  58. $this->manager->expects(self::once())
  59. ->method('process')
  60. ->with(
  61. "nodeinfo",
  62. $this->request
  63. )->willReturn($response);
  64. $jsonResponse->expects(self::once())
  65. ->method('addHeader')
  66. ->willReturnSelf();
  67. $httpResponse = $this->controller->handle("nodeinfo");
  68. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  69. }
  70. }