1
0

PublicTemplateResponseTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\AppFramework\Http;
  24. use OCP\AppFramework\Http\Template\PublicTemplateResponse;
  25. use OCP\AppFramework\Http;
  26. use Test\TestCase;
  27. class PublicTemplateResponseTest extends TestCase {
  28. public function testSetParamsConstructor() {
  29. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  30. $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
  31. $this->assertEquals(['key' => 'value'], $template->getParams());
  32. }
  33. public function testAdditionalElements() {
  34. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  35. $template->setHeaderTitle('Header');
  36. $template->setHeaderDetails('Details');
  37. $this->assertEquals(['key' => 'value'], $template->getParams());
  38. $this->assertEquals('Header', $template->getHeaderTitle());
  39. $this->assertEquals('Details', $template->getHeaderDetails());
  40. }
  41. public function testActionSingle() {
  42. $actions = [
  43. new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
  44. ];
  45. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  46. $template->setHeaderActions($actions);
  47. $this->assertEquals(['key' => 'value'], $template->getParams());
  48. $this->assertEquals($actions[0], $template->getPrimaryAction());
  49. $this->assertEquals(1, $template->getActionCount());
  50. $this->assertEquals([], $template->getOtherActions());
  51. }
  52. public function testActionMultiple() {
  53. $actions = [
  54. new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
  55. new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
  56. new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
  57. ];
  58. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  59. $template->setHeaderActions($actions);
  60. $this->assertEquals(['key' => 'value'], $template->getParams());
  61. $this->assertEquals($actions[2], $template->getPrimaryAction());
  62. $this->assertEquals(3, $template->getActionCount());
  63. $this->assertEquals([$actions[1], $actions[0]], $template->getOtherActions());
  64. }
  65. public function testGetRenderAs() {
  66. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  67. $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
  68. $this->assertEquals(['key' => 'value'], $template->getParams());
  69. $this->assertEquals('public', $template->getRenderAs());
  70. }
  71. }