1
0

PublicTemplateResponseTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\AppFramework\Http;
  7. use OCP\AppFramework\Http;
  8. use OCP\AppFramework\Http\Template\PublicTemplateResponse;
  9. use Test\TestCase;
  10. class PublicTemplateResponseTest extends TestCase {
  11. public function testSetParamsConstructor() {
  12. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  13. $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
  14. $this->assertEquals(['key' => 'value'], $template->getParams());
  15. }
  16. public function testAdditionalElements() {
  17. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  18. $template->setHeaderTitle('Header');
  19. $template->setHeaderDetails('Details');
  20. $this->assertEquals(['key' => 'value'], $template->getParams());
  21. $this->assertEquals('Header', $template->getHeaderTitle());
  22. $this->assertEquals('Details', $template->getHeaderDetails());
  23. }
  24. public function testActionSingle() {
  25. $actions = [
  26. new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
  27. ];
  28. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  29. $template->setHeaderActions($actions);
  30. $this->assertEquals(['key' => 'value'], $template->getParams());
  31. $this->assertEquals($actions[0], $template->getPrimaryAction());
  32. $this->assertEquals(1, $template->getActionCount());
  33. $this->assertEquals([], $template->getOtherActions());
  34. }
  35. public function testActionMultiple() {
  36. $actions = [
  37. new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
  38. new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
  39. new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
  40. ];
  41. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  42. $template->setHeaderActions($actions);
  43. $this->assertEquals(['key' => 'value'], $template->getParams());
  44. $this->assertEquals($actions[2], $template->getPrimaryAction());
  45. $this->assertEquals(3, $template->getActionCount());
  46. $this->assertEquals([$actions[1], $actions[0]], $template->getOtherActions());
  47. }
  48. public function testGetRenderAs() {
  49. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  50. $this->assertContains('core/js/public/publicpage', \OC_Util::$scripts);
  51. $this->assertEquals(['key' => 'value'], $template->getParams());
  52. $this->assertEquals('public', $template->getRenderAs());
  53. }
  54. }