1
0

TemplateResponseTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * ownCloud - App Framework
  4. *
  5. * @author Bernhard Posselt
  6. * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace Test\AppFramework\Http;
  23. use OCP\AppFramework\Http;
  24. use OCP\AppFramework\Http\TemplateResponse;
  25. class TemplateResponseTest extends \Test\TestCase {
  26. /**
  27. * @var \OCP\AppFramework\Http\TemplateResponse
  28. */
  29. private $tpl;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->tpl = new TemplateResponse('app', 'home');
  33. }
  34. public function testSetParamsConstructor() {
  35. $params = ['hi' => 'yo'];
  36. $this->tpl = new TemplateResponse('app', 'home', $params);
  37. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  38. }
  39. public function testSetRenderAsConstructor() {
  40. $renderAs = 'myrender';
  41. $this->tpl = new TemplateResponse('app', 'home', [], $renderAs);
  42. $this->assertEquals($renderAs, $this->tpl->getRenderAs());
  43. }
  44. public function testSetParams() {
  45. $params = ['hi' => 'yo'];
  46. $this->tpl->setParams($params);
  47. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  48. }
  49. public function testGetTemplateName() {
  50. $this->assertEquals('home', $this->tpl->getTemplateName());
  51. }
  52. public function testGetRenderAs() {
  53. $render = 'myrender';
  54. $this->tpl->renderAs($render);
  55. $this->assertEquals($render, $this->tpl->getRenderAs());
  56. }
  57. public function testChainability() {
  58. $params = ['hi' => 'yo'];
  59. $this->tpl->setParams($params)
  60. ->setStatus(Http::STATUS_NOT_FOUND);
  61. $this->assertEquals(Http::STATUS_NOT_FOUND, $this->tpl->getStatus());
  62. $this->assertEquals(['hi' => 'yo'], $this->tpl->getParams());
  63. }
  64. }