JrdResponseTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Test\Http\WellKnown;
  24. use OCP\AppFramework\Http\JSONResponse;
  25. use OCP\Http\WellKnown\JrdResponse;
  26. use Test\TestCase;
  27. class JrdResponseTest extends TestCase {
  28. public function testEmptyToHttpResponse(): void {
  29. $response = new JrdResponse("subject");
  30. $httpResponse = $response->toHttpResponse();
  31. self::assertTrue($response->isEmpty());
  32. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  33. /** @var JSONResponse $httpResponse */
  34. self::assertEquals(
  35. [
  36. 'subject' => 'subject',
  37. ],
  38. $httpResponse->getData()
  39. );
  40. }
  41. public function testComplexToHttpResponse(): void {
  42. $response = new JrdResponse("subject");
  43. $response->addAlias('alias');
  44. $response->addAlias('blias');
  45. $response->addProperty('propa', 'a');
  46. $response->addProperty('propb', null);
  47. $response->setExpires('tomorrow');
  48. $response->addLink('rel', null, null);
  49. $response->addLink('rel', 'type', null);
  50. $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue']);
  51. $response->addLink('rel', 'type', 'href', ['title' => 'titlevalue'], ['propx' => 'valx']);
  52. $httpResponse = $response->toHttpResponse();
  53. self::assertFalse($response->isEmpty());
  54. self::assertInstanceOf(JSONResponse::class, $httpResponse);
  55. /** @var JSONResponse $httpResponse */
  56. self::assertEquals(
  57. [
  58. 'subject' => 'subject',
  59. 'aliases' => [
  60. 'alias',
  61. 'blias',
  62. ],
  63. 'properties' => [
  64. 'propa' => 'a',
  65. 'propb' => null,
  66. ],
  67. 'expires' => 'tomorrow',
  68. 'links' => [
  69. [
  70. 'rel' => 'rel',
  71. ],
  72. [
  73. 'rel' => 'rel',
  74. 'type' => 'type',
  75. ],
  76. [
  77. 'rel' => 'rel',
  78. 'type' => 'type',
  79. 'href' => 'href',
  80. 'titles' => [
  81. 'title' => 'titlevalue',
  82. ],
  83. ],
  84. [
  85. 'rel' => 'rel',
  86. 'type' => 'type',
  87. 'href' => 'href',
  88. 'titles' => [
  89. 'title' => 'titlevalue',
  90. ],
  91. 'properties' => [
  92. 'propx' => 'valx',
  93. ],
  94. ],
  95. ]
  96. ],
  97. $httpResponse->getData()
  98. );
  99. }
  100. }