TemplateResponseTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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\TemplateResponse;
  24. use OCP\AppFramework\Http;
  25. class TemplateResponseTest extends \Test\TestCase {
  26. /**
  27. * @var \OCP\AppFramework\Http\TemplateResponse
  28. */
  29. private $tpl;
  30. /**
  31. * @var \OCP\AppFramework\IApi
  32. */
  33. private $api;
  34. protected function setUp() {
  35. parent::setUp();
  36. $this->api = $this->getMockBuilder('OC\AppFramework\Core\API')
  37. ->setMethods(['getAppName'])
  38. ->setConstructorArgs(['test'])
  39. ->getMock();
  40. $this->api->expects($this->any())
  41. ->method('getAppName')
  42. ->will($this->returnValue('app'));
  43. $this->tpl = new TemplateResponse($this->api, 'home');
  44. }
  45. public function testSetParamsConstructor(){
  46. $params = array('hi' => 'yo');
  47. $this->tpl = new TemplateResponse($this->api, 'home', $params);
  48. $this->assertEquals(array('hi' => 'yo'), $this->tpl->getParams());
  49. }
  50. public function testSetRenderAsConstructor(){
  51. $renderAs = 'myrender';
  52. $this->tpl = new TemplateResponse($this->api, 'home', array(), $renderAs);
  53. $this->assertEquals($renderAs, $this->tpl->getRenderAs());
  54. }
  55. public function testSetParams(){
  56. $params = array('hi' => 'yo');
  57. $this->tpl->setParams($params);
  58. $this->assertEquals(array('hi' => 'yo'), $this->tpl->getParams());
  59. }
  60. public function testGetTemplateName(){
  61. $this->assertEquals('home', $this->tpl->getTemplateName());
  62. }
  63. public function testGetRenderAs(){
  64. $render = 'myrender';
  65. $this->tpl->renderAs($render);
  66. $this->assertEquals($render, $this->tpl->getRenderAs());
  67. }
  68. public function testChainability() {
  69. $params = array('hi' => 'yo');
  70. $this->tpl->setParams($params)
  71. ->setStatus(Http::STATUS_NOT_FOUND);
  72. $this->assertEquals(Http::STATUS_NOT_FOUND, $this->tpl->getStatus());
  73. $this->assertEquals(array('hi' => 'yo'), $this->tpl->getParams());
  74. }
  75. }