1
0

CalendarImplTest.php 3.5 KB

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