diff options
Diffstat (limited to 'apps/dav/tests/unit/CalDAV/CalendarTest.php')
-rw-r--r-- | apps/dav/tests/unit/CalDAV/CalendarTest.php | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index 4b89e35e81a..95cedb6da6a 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -33,6 +33,8 @@ use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; use OCP\IConfig; use OCP\IL10N; +use PHPUnit\Framework\MockObject\MockObject; +use Psr\Log\LoggerInterface; use Sabre\DAV\PropPatch; use Sabre\VObject\Reader; use Test\TestCase; @@ -45,11 +47,15 @@ class CalendarTest extends TestCase { /** @var IConfig */ protected $config; + /** @var MockObject|LoggerInterface */ + protected $logger; + protected function setUp(): void { parent::setUp(); $this->l10n = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor()->getMock(); $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(LoggerInterface::class); $this->l10n ->expects($this->any()) ->method('t') @@ -59,7 +65,7 @@ class CalendarTest extends TestCase { } public function testDelete() { - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->once())->method('updateShares'); $backend->expects($this->any())->method('getShares')->willReturn([ @@ -71,7 +77,7 @@ class CalendarTest extends TestCase { 'id' => 666, 'uri' => 'cal', ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $c->delete(); } @@ -79,7 +85,7 @@ class CalendarTest extends TestCase { public function testDeleteFromGroup() { $this->expectException(\Sabre\DAV\Exception\Forbidden::class); - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->never())->method('updateShares'); $backend->expects($this->any())->method('getShares')->willReturn([ @@ -91,12 +97,12 @@ class CalendarTest extends TestCase { 'id' => 666, 'uri' => 'cal', ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $c->delete(); } public function testDeleteOwn() { - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->never())->method('updateShares'); $backend->expects($this->never())->method('getShares'); @@ -112,12 +118,12 @@ class CalendarTest extends TestCase { 'id' => 666, 'uri' => 'cal', ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $c->delete(); } public function testDeleteBirthdayCalendar() { - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->once())->method('deleteCalendar') ->with(666); @@ -133,7 +139,7 @@ class CalendarTest extends TestCase { 'uri' => 'contact_birthdays', ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $c->delete(); } @@ -168,7 +174,7 @@ class CalendarTest extends TestCase { * @dataProvider dataPropPatch */ public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared) { - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, @@ -176,7 +182,7 @@ class CalendarTest extends TestCase { 'id' => 666, 'uri' => 'default' ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $propPatch = new PropPatch($mutations); if (!$shared) { @@ -192,7 +198,7 @@ class CalendarTest extends TestCase { * @dataProvider providesReadOnlyInfo */ public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default') { - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); $calendarInfo = [ @@ -206,7 +212,7 @@ class CalendarTest extends TestCase { if ($hasOwnerSet) { $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; } - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $acl = $c->getACL(); $childAcl = $c->getChildACL(); @@ -299,7 +305,7 @@ class CalendarTest extends TestCase { $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 @@ -322,7 +328,7 @@ class CalendarTest extends TestCase { if ($isShared) { $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; } - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $children = $c->getChildren(); $this->assertEquals($expectedChildren, count($children)); $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); @@ -386,7 +392,7 @@ EOD; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 @@ -406,7 +412,7 @@ EOD; 'id' => 666, 'uri' => 'cal', ]; - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); $this->assertEquals(count($c->getChildren()), $expectedChildren); @@ -439,7 +445,7 @@ EOD; $l10n->expects($this->never()) ->method('t'); } - $c = new Calendar($backend, $calendarInfo, $l10n, $this->config); + $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger); $calData = $c->getChild('event-1')->get(); $event = Reader::read($calData); @@ -554,7 +560,7 @@ EOD; 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $confidentialObjectData]; - /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */ + /** @var MockObject | CalDavBackend $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->any()) ->method('getCalendarObjects') @@ -604,13 +610,13 @@ EOD; 'uri' => 'cal', ]; - $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config); - $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config); - $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config); + $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger); + $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger); + $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger); - $this->assertEquals(count($ownerCalendar->getChildren()), 2); - $this->assertEquals(count($rwCalendar->getChildren()), 2); - $this->assertEquals(count($roCalendar->getChildren()), 2); + $this->assertCount(2, $ownerCalendar->getChildren()); + $this->assertCount(2, $rwCalendar->getChildren()); + $this->assertCount(2, $roCalendar->getChildren()); // calendar data shall not be altered for the owner $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); |