LinkActionTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Tests\Contacts\ContactsMenu\Actions;
  7. use OC\Contacts\ContactsMenu\Actions\LinkAction;
  8. use Test\TestCase;
  9. class LinkActionTest extends TestCase {
  10. private LinkAction $action;
  11. protected function setUp(): void {
  12. parent::setUp();
  13. $this->action = new LinkAction();
  14. }
  15. public function testSetIcon() {
  16. $icon = 'icon-test';
  17. $this->action->setIcon($icon);
  18. $json = $this->action->jsonSerialize();
  19. $this->assertArrayHasKey('icon', $json);
  20. $this->assertEquals($json['icon'], $icon);
  21. }
  22. public function testGetSetName() {
  23. $name = 'Jane Doe';
  24. $this->assertEmpty($this->action->getName());
  25. $this->action->setName($name);
  26. $this->assertEquals($name, $this->action->getName());
  27. }
  28. public function testGetSetPriority() {
  29. $prio = 50;
  30. $this->assertEquals(10, $this->action->getPriority());
  31. $this->action->setPriority($prio);
  32. $this->assertEquals($prio, $this->action->getPriority());
  33. }
  34. public function testSetHref() {
  35. $this->action->setHref('/some/url');
  36. $json = $this->action->jsonSerialize();
  37. $this->assertArrayHasKey('hyperlink', $json);
  38. $this->assertEquals('/some/url', $json['hyperlink']);
  39. }
  40. public function testJsonSerialize() {
  41. $this->action->setIcon('icon-contacts');
  42. $this->action->setName('Nickie Works');
  43. $this->action->setPriority(33);
  44. $this->action->setHref('example.com');
  45. $this->action->setAppId('contacts');
  46. $expected = [
  47. 'title' => 'Nickie Works',
  48. 'icon' => 'icon-contacts',
  49. 'hyperlink' => 'example.com',
  50. 'appId' => 'contacts',
  51. ];
  52. $json = $this->action->jsonSerialize();
  53. $this->assertEquals($expected, $json);
  54. }
  55. public function testJsonSerializeNoAppName() {
  56. $this->action->setIcon('icon-contacts');
  57. $this->action->setName('Nickie Works');
  58. $this->action->setPriority(33);
  59. $this->action->setHref('example.com');
  60. $expected = [
  61. 'title' => 'Nickie Works',
  62. 'icon' => 'icon-contacts',
  63. 'hyperlink' => 'example.com',
  64. 'appId' => '',
  65. ];
  66. $json = $this->action->jsonSerialize();
  67. $this->assertEquals($expected, $json);
  68. }
  69. }