1
0

EntryTest.php 3.2 KB

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