1
0

PublicTemplateResponseTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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(): void {
  12. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  13. $this->assertEquals(['key' => 'value'], $template->getParams());
  14. }
  15. public function testAdditionalElements(): void {
  16. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  17. $template->setHeaderTitle('Header');
  18. $template->setHeaderDetails('Details');
  19. $this->assertEquals(['key' => 'value'], $template->getParams());
  20. $this->assertEquals('Header', $template->getHeaderTitle());
  21. $this->assertEquals('Details', $template->getHeaderDetails());
  22. }
  23. public function testActionSingle(): void {
  24. $actions = [
  25. new Http\Template\SimpleMenuAction('link', 'Download', 'download', 'downloadLink', 0)
  26. ];
  27. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  28. $template->setHeaderActions($actions);
  29. $this->assertEquals(['key' => 'value'], $template->getParams());
  30. $this->assertEquals($actions[0], $template->getPrimaryAction());
  31. $this->assertEquals(1, $template->getActionCount());
  32. $this->assertEquals([], $template->getOtherActions());
  33. }
  34. public function testActionMultiple(): void {
  35. $actions = [
  36. new Http\Template\SimpleMenuAction('link1', 'Download1', 'download1', 'downloadLink1', 100),
  37. new Http\Template\SimpleMenuAction('link2', 'Download2', 'download2', 'downloadLink2', 20),
  38. new Http\Template\SimpleMenuAction('link3', 'Download3', 'download3', 'downloadLink3', 0)
  39. ];
  40. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  41. $template->setHeaderActions($actions);
  42. $this->assertEquals(['key' => 'value'], $template->getParams());
  43. $this->assertEquals($actions[2], $template->getPrimaryAction());
  44. $this->assertEquals(3, $template->getActionCount());
  45. $this->assertEquals([$actions[1], $actions[0]], $template->getOtherActions());
  46. }
  47. public function testGetRenderAs(): void {
  48. $template = new PublicTemplateResponse('app', 'home', ['key' => 'value']);
  49. $this->assertEquals(['key' => 'value'], $template->getParams());
  50. $this->assertEquals('public', $template->getRenderAs());
  51. }
  52. }