1
0

LinkActionTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
  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 Tests\Contacts\ContactsMenu\Actions;
  24. use OC\Contacts\ContactsMenu\Actions\LinkAction;
  25. use Test\TestCase;
  26. class LinkActionTest extends TestCase {
  27. private LinkAction $action;
  28. protected function setUp(): void {
  29. parent::setUp();
  30. $this->action = new LinkAction();
  31. }
  32. public function testSetIcon() {
  33. $icon = 'icon-test';
  34. $this->action->setIcon($icon);
  35. $json = $this->action->jsonSerialize();
  36. $this->assertArrayHasKey('icon', $json);
  37. $this->assertEquals($json['icon'], $icon);
  38. }
  39. public function testGetSetName() {
  40. $name = 'Jane Doe';
  41. $this->assertEmpty($this->action->getName());
  42. $this->action->setName($name);
  43. $this->assertEquals($name, $this->action->getName());
  44. }
  45. public function testGetSetPriority() {
  46. $prio = 50;
  47. $this->assertEquals(10, $this->action->getPriority());
  48. $this->action->setPriority($prio);
  49. $this->assertEquals($prio, $this->action->getPriority());
  50. }
  51. public function testSetHref() {
  52. $this->action->setHref('/some/url');
  53. $json = $this->action->jsonSerialize();
  54. $this->assertArrayHasKey('hyperlink', $json);
  55. $this->assertEquals('/some/url', $json['hyperlink']);
  56. }
  57. public function testJsonSerialize() {
  58. $this->action->setIcon('icon-contacts');
  59. $this->action->setName('Nickie Works');
  60. $this->action->setPriority(33);
  61. $this->action->setHref('example.com');
  62. $this->action->setAppId('contacts');
  63. $expected = [
  64. 'title' => 'Nickie Works',
  65. 'icon' => 'icon-contacts',
  66. 'hyperlink' => 'example.com',
  67. 'appId' => 'contacts',
  68. ];
  69. $json = $this->action->jsonSerialize();
  70. $this->assertEquals($expected, $json);
  71. }
  72. public function testJsonSerializeNoAppName() {
  73. $this->action->setIcon('icon-contacts');
  74. $this->action->setName('Nickie Works');
  75. $this->action->setPriority(33);
  76. $this->action->setHref('example.com');
  77. $expected = [
  78. 'title' => 'Nickie Works',
  79. 'icon' => 'icon-contacts',
  80. 'hyperlink' => 'example.com',
  81. 'appId' => '',
  82. ];
  83. $json = $this->action->jsonSerialize();
  84. $this->assertEquals($expected, $json);
  85. }
  86. }