1
0

EntryTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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;
  7. use OC\Contacts\ContactsMenu\Actions\LinkAction;
  8. use OC\Contacts\ContactsMenu\Entry;
  9. use Test\TestCase;
  10. class EntryTest extends TestCase {
  11. private Entry $entry;
  12. protected function setUp(): void {
  13. parent::setUp();
  14. $this->entry = new Entry();
  15. }
  16. public function testSetId() {
  17. $this->entry->setId(123);
  18. $this->addToAssertionCount(1);
  19. }
  20. public function testSetGetFullName() {
  21. $fn = 'Danette Chaille';
  22. $this->assertEquals('', $this->entry->getFullName());
  23. $this->entry->setFullName($fn);
  24. $this->assertEquals($fn, $this->entry->getFullName());
  25. }
  26. public function testAddGetEMailAddresses() {
  27. $this->assertEmpty($this->entry->getEMailAddresses());
  28. $this->entry->addEMailAddress('user@example.com');
  29. $this->assertEquals(['user@example.com'], $this->entry->getEMailAddresses());
  30. }
  31. public function testAddAndSortAction() {
  32. // Three actions, two with equal priority
  33. $action1 = new LinkAction();
  34. $action2 = new LinkAction();
  35. $action3 = new LinkAction();
  36. $action1->setPriority(10);
  37. $action1->setName('Bravo');
  38. $action2->setPriority(0);
  39. $action2->setName('Batman');
  40. $action3->setPriority(10);
  41. $action3->setName('Alfa');
  42. $this->entry->addAction($action1);
  43. $this->entry->addAction($action2);
  44. $this->entry->addAction($action3);
  45. $sorted = $this->entry->getActions();
  46. $this->assertSame($action3, $sorted[0]);
  47. $this->assertSame($action1, $sorted[1]);
  48. $this->assertSame($action2, $sorted[2]);
  49. }
  50. public function testSetGetProperties() {
  51. $props = [
  52. 'prop1' => 123,
  53. 'prop2' => 'string',
  54. ];
  55. $this->entry->setProperties($props);
  56. $this->assertNull($this->entry->getProperty('doesntexist'));
  57. $this->assertEquals(123, $this->entry->getProperty('prop1'));
  58. $this->assertEquals('string', $this->entry->getProperty('prop2'));
  59. }
  60. public function testJsonSerialize() {
  61. $expectedJson = [
  62. 'id' => '123',
  63. 'fullName' => 'Guadalupe Frisbey',
  64. 'topAction' => null,
  65. 'actions' => [],
  66. 'lastMessage' => '',
  67. 'avatar' => null,
  68. 'emailAddresses' => ['user@example.com'],
  69. 'profileTitle' => null,
  70. 'profileUrl' => null,
  71. 'status' => null,
  72. 'statusMessage' => null,
  73. 'statusMessageTimestamp' => null,
  74. 'statusIcon' => null,
  75. 'isUser' => false,
  76. 'uid' => null,
  77. ];
  78. $this->entry->setId(123);
  79. $this->entry->setFullName('Guadalupe Frisbey');
  80. $this->entry->addEMailAddress('user@example.com');
  81. $json = $this->entry->jsonSerialize();
  82. $this->assertEquals($expectedJson, $json);
  83. }
  84. }