CalendarImplTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  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 OCA\DAV\Tests\unit\CalDAV;
  24. use OCA\DAV\CalDAV\CalDavBackend;
  25. use OCA\DAV\CalDAV\Calendar;
  26. use OCA\DAV\CalDAV\CalendarImpl;
  27. class CalendarImplTest extends \Test\TestCase {
  28. /** @var CalendarImpl */
  29. private $calendarImpl;
  30. /** @var Calendar | \PHPUnit_Framework_MockObject_MockObject */
  31. private $calendar;
  32. /** @var array */
  33. private $calendarInfo;
  34. /** @var CalDavBackend | \PHPUnit_Framework_MockObject_MockObject */
  35. private $backend;
  36. protected function setUp() {
  37. parent::setUp();
  38. $this->calendar = $this->createMock(Calendar::class);
  39. $this->calendarInfo = [
  40. 'id' => 'fancy_id_123',
  41. '{DAV:}displayname' => 'user readable name 123',
  42. '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
  43. ];
  44. $this->backend = $this->createMock(CalDavBackend::class);
  45. $this->calendarImpl = new CalendarImpl($this->calendar,
  46. $this->calendarInfo, $this->backend);
  47. }
  48. public function testGetKey() {
  49. $this->assertEquals($this->calendarImpl->getKey(), 'fancy_id_123');
  50. }
  51. public function testGetDisplayname() {
  52. $this->assertEquals($this->calendarImpl->getDisplayName(),'user readable name 123');
  53. }
  54. public function testGetDisplayColor() {
  55. $this->assertEquals($this->calendarImpl->getDisplayColor(), '#AABBCC');
  56. }
  57. public function testSearch() {
  58. $this->backend->expects($this->once())
  59. ->method('search')
  60. ->with($this->calendarInfo, 'abc', ['def'], ['ghi'], 42, 1337)
  61. ->will($this->returnValue(['SEARCHRESULTS']));
  62. $result = $this->calendarImpl->search('abc', ['def'], ['ghi'], 42, 1337);
  63. $this->assertEquals($result, ['SEARCHRESULTS']);
  64. }
  65. public function testGetPermissionRead() {
  66. $this->calendar->expects($this->once())
  67. ->method('getACL')
  68. ->with()
  69. ->will($this->returnValue([
  70. ['privilege' => '{DAV:}read']
  71. ]));
  72. $this->assertEquals(1, $this->calendarImpl->getPermissions());
  73. }
  74. public function testGetPermissionWrite() {
  75. $this->calendar->expects($this->once())
  76. ->method('getACL')
  77. ->with()
  78. ->will($this->returnValue([
  79. ['privilege' => '{DAV:}write']
  80. ]));
  81. $this->assertEquals(6, $this->calendarImpl->getPermissions());
  82. }
  83. public function testGetPermissionReadWrite() {
  84. $this->calendar->expects($this->once())
  85. ->method('getACL')
  86. ->with()
  87. ->will($this->returnValue([
  88. ['privilege' => '{DAV:}read'],
  89. ['privilege' => '{DAV:}write']
  90. ]));
  91. $this->assertEquals(7, $this->calendarImpl->getPermissions());
  92. }
  93. public function testGetPermissionAll() {
  94. $this->calendar->expects($this->once())
  95. ->method('getACL')
  96. ->with()
  97. ->will($this->returnValue([
  98. ['privilege' => '{DAV:}all']
  99. ]));
  100. $this->assertEquals(31, $this->calendarImpl->getPermissions());
  101. }
  102. }