CalendarImplTest.php 3.4 KB

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