EntryTest.php 3.0 KB

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