TemplateResponseTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\Http;
  8. use OCP\AppFramework\Http;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. class TemplateResponseTest extends \Test\TestCase {
  11. /**
  12. * @var \OCP\AppFramework\Http\TemplateResponse
  13. */
  14. private $tpl;
  15. protected function setUp(): void {
  16. parent::setUp();
  17. $this->tpl = new TemplateResponse('app', 'home');
  18. }
  19. public function testSetParamsConstructor() {
  20. $params = ['hi' => 'yo'];
  21. $this->tpl = new TemplateResponse('app', 'home', $params);
  22. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  23. }
  24. public function testSetRenderAsConstructor() {
  25. $renderAs = 'myrender';
  26. $this->tpl = new TemplateResponse('app', 'home', [], $renderAs);
  27. $this->assertEquals($renderAs, $this->tpl->getRenderAs());
  28. }
  29. public function testSetParams() {
  30. $params = ['hi' => 'yo'];
  31. $this->tpl->setParams($params);
  32. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  33. }
  34. public function testGetTemplateName() {
  35. $this->assertEquals('home', $this->tpl->getTemplateName());
  36. }
  37. public function testGetRenderAs() {
  38. $render = 'myrender';
  39. $this->tpl->renderAs($render);
  40. $this->assertEquals($render, $this->tpl->getRenderAs());
  41. }
  42. public function testChainability() {
  43. $params = ['hi' => 'yo'];
  44. $this->tpl->setParams($params)
  45. ->setStatus(Http::STATUS_NOT_FOUND);
  46. $this->assertEquals(Http::STATUS_NOT_FOUND, $this->tpl->getStatus());
  47. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  48. }
  49. }