You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarImplTest.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\CalDAV;
  27. use OCA\DAV\CalDAV\CalDavBackend;
  28. use OCA\DAV\CalDAV\Calendar;
  29. use OCA\DAV\CalDAV\CalendarImpl;
  30. class CalendarImplTest extends \Test\TestCase {
  31. /** @var CalendarImpl */
  32. private $calendarImpl;
  33. /** @var Calendar | \PHPUnit\Framework\MockObject\MockObject */
  34. private $calendar;
  35. /** @var array */
  36. private $calendarInfo;
  37. /** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject */
  38. private $backend;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. $this->calendar = $this->createMock(Calendar::class);
  42. $this->calendarInfo = [
  43. 'id' => 'fancy_id_123',
  44. '{DAV:}displayname' => 'user readable name 123',
  45. '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
  46. ];
  47. $this->backend = $this->createMock(CalDavBackend::class);
  48. $this->calendarImpl = new CalendarImpl($this->calendar,
  49. $this->calendarInfo, $this->backend);
  50. }
  51. public function testGetKey() {
  52. $this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123');
  53. }
  54. public function testGetDisplayname() {
  55. $this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123');
  56. }
  57. public function testGetDisplayColor() {
  58. $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC');
  59. }
  60. public function testSearch() {
  61. $this->backend->expects($this->once())
  62. ->method('search')
  63. ->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337)
  64. ->willReturn(['SEARCHRESULTS']);
  65. $result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337);
  66. $this->assertEquals($result, ['SEARCHRESULTS']);
  67. }
  68. public function testGetPermissionRead() {
  69. $this->calendar->expects($this->once())
  70. ->method('getACL')
  71. ->with()
  72. ->willReturn([
  73. ['privilege' => '{DAV:}read']
  74. ]);
  75. $this->assertEquals(1, $this->calendarImpl->getPermissions());
  76. }
  77. public function testGetPermissionWrite() {
  78. $this->calendar->expects($this->once())
  79. ->method('getACL')
  80. ->with()
  81. ->willReturn([
  82. ['privilege' => '{DAV:}write']
  83. ]);
  84. $this->assertEquals(6, $this->calendarImpl->getPermissions());
  85. }
  86. public function testGetPermissionReadWrite() {
  87. $this->calendar->expects($this->once())
  88. ->method('getACL')
  89. ->with()
  90. ->willReturn([
  91. ['privilege' => '{DAV:}read'],
  92. ['privilege' => '{DAV:}write']
  93. ]);
  94. $this->assertEquals(7, $this->calendarImpl->getPermissions());
  95. }
  96. public function testGetPermissionAll() {
  97. $this->calendar->expects($this->once())
  98. ->method('getACL')
  99. ->with()
  100. ->willReturn([
  101. ['privilege' => '{DAV:}all']
  102. ]);
  103. $this->assertEquals(31, $this->calendarImpl->getPermissions());
  104. }
  105. }