JrdResponseTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Test\Http\WellKnown;
  8. use OCP\AppFramework\Http\JSONResponse;
  9. use OCP\Http\WellKnown\JrdResponse;
  10. use Test\TestCase;
  11. class JrdResponseTest extends TestCase {
  12. public function testEmptyToHttpResponse(): void {
  13. $response = new JrdResponse('subject');
  14. $httpResponse = $response->toHttpResponse();
  15. self::assertTrue($response->isEmpty());
  16. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  17. /** @var JSONResponse $httpResponse */
  18. self::assertEquals(
  19. [
  20. 'subject' => 'subject',
  21. ],
  22. $httpResponse->getData()
  23. );
  24. }
  25. public function testComplexToHttpResponse(): void {
  26. $response = new JrdResponse('subject');
  27. $response->addAlias('alias');
  28. $response->addAlias('blias');
  29. $response->addProperty('propa', 'a');
  30. $response->addProperty('propb', null);
  31. $response->setExpires('tomorrow');
  32. $response->addLink('rel', null, null);
  33. $response->addLink('rel', 'type', null);
  34. $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue']);
  35. $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue'], ['propx' => 'valx']);
  36. $httpResponse = $response->toHttpResponse();
  37. self::assertFalse($response->isEmpty());
  38. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  39. /** @var JSONResponse $httpResponse */
  40. self::assertEquals(
  41. [
  42. 'subject' => 'subject',
  43. 'aliases' => [
  44. 'alias',
  45. 'blias',
  46. ],
  47. 'properties' => [
  48. 'propa' => 'a',
  49. 'propb' => null,
  50. ],
  51. 'expires' => 'tomorrow',
  52. 'links' => [
  53. [
  54. 'rel' => 'rel',
  55. ],
  56. [
  57. 'rel' => 'rel',
  58. 'type' => 'type',
  59. ],
  60. [
  61. 'rel' => 'rel',
  62. 'type' => 'type',
  63. 'href' => 'href',
  64. 'titles' => [
  65. 'title' => 'titlevalue',
  66. ],
  67. ],
  68. [
  69. 'rel' => 'rel',
  70. 'type' => 'type',
  71. 'href' => 'href',
  72. 'titles' => [
  73. 'title' => 'titlevalue',
  74. ],
  75. 'properties' => [
  76. 'propx' => 'valx',
  77. ],
  78. ],
  79. ]
  80. ],
  81. $httpResponse->getData()
  82. );
  83. }
  84. }