-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33906 from nextcloud/fix/fix-calendar-tests-getTi…
…mestamp Fix Calendar tests mocking a non-existant method.
- Loading branch information
Showing
2 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,7 @@ public function testHandleImipReplyWrongMethod(): void { | |
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
$this->time->expects(self::never()) | ||
->method('getTimestamp'); | ||
->method('getTime'); | ||
|
||
$result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
|
@@ -266,7 +266,7 @@ public function testHandleImipReplyOrganizerNotRecipient(): void { | |
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
$this->time->expects(self::never()) | ||
->method('getTimestamp'); | ||
->method('getTime'); | ||
|
||
$result = $this->manager->handleIMipReply($principalUri, $sender, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
|
@@ -280,7 +280,7 @@ public function testHandleImipReplyDateInThePast(): void { | |
$calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07'); // set to in the past | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->method('getTime') | ||
->willReturn(time()); | ||
|
||
$this->logger->expects(self::once()) | ||
|
@@ -301,15 +301,16 @@ public function testHandleImipReplyNoCalendars(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$principalUri = 'principals/user/linus'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$calendarData = $this->getVCalendarReply(); | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->willReturn([]); | ||
|
@@ -331,16 +332,17 @@ public function testHandleImipReplyEventNotFound(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$calendar = $this->createMock(ICreateFromString::class); | ||
$principalUri = 'principals/user/linus'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$calendarData = $this->getVCalendarReply(); | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->willReturn([$calendar]); | ||
|
@@ -367,16 +369,17 @@ public function testHandleImipReply(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$calendar = $this->createMock(ICreateFromString::class); | ||
$principalUri = 'principals/user/linus'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$calendarData = $this->getVCalendarReply(); | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->willReturn([$calendar]); | ||
|
@@ -397,12 +400,12 @@ public function testHandleImipCancelWrongMethod(): void { | |
$recipient = '[email protected]'; | ||
$replyTo = null; | ||
$calendarData = $this->getVCalendarCancel(); | ||
$calendarData->VEVENT->METHOD = 'REQUEST'; | ||
$calendarData->METHOD = 'REQUEST'; | ||
|
||
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
$this->time->expects(self::never()) | ||
->method('getTimestamp'); | ||
->method('getTime'); | ||
|
||
$result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
|
@@ -414,12 +417,11 @@ public function testHandleImipCancelAttendeeNotRecipient(): void { | |
$recipient = '[email protected]'; | ||
$replyTo = null; | ||
$calendarData = $this->getVCalendarCancel(); | ||
$calendarData->VEVENT->METHOD = 'CANCEL'; | ||
|
||
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
$this->time->expects(self::never()) | ||
->method('getTimestamp'); | ||
->method('getTime'); | ||
|
||
$result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
|
@@ -434,7 +436,7 @@ public function testHandleImipCancelDateInThePast(): void { | |
$calendarData->VEVENT->DTSTART = new \DateTime('2013-04-07'); // set to in the past | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->method('getTime') | ||
->willReturn(time()); | ||
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
|
@@ -454,25 +456,26 @@ public function testHandleImipCancelNoCalendars(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$principalUri = 'principals/user/pierre'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$replyTo = null; | ||
$calendarData = $this->getVCalendarCancel(); | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->with($principalUri) | ||
->willReturn([]); | ||
$this->logger->expects(self::once()) | ||
->method('warning'); | ||
|
||
$result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertTrue($result); | ||
$result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
} | ||
|
||
public function testHandleImipCancelOrganiserInReplyTo(): void { | ||
|
@@ -486,18 +489,18 @@ public function testHandleImipCancelOrganiserInReplyTo(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$principalUri = 'principals/user/pierre'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$replyTo = '[email protected]'; | ||
$calendar = $this->createMock(ICreateFromString::class); | ||
$calendarData = $this->getVCalendarCancel(); | ||
$calendarData->VEVENT->METHOD = 'CANCEL'; | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->with($principalUri) | ||
|
@@ -508,8 +511,8 @@ public function testHandleImipCancelOrganiserInReplyTo(): void { | |
$calendar->expects(self::once()) | ||
->method('handleIMipMessage') | ||
->with('testname.ics', $calendarData->serialize()); | ||
$result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
$result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testHandleImipCancel(): void { | ||
|
@@ -523,18 +526,18 @@ public function testHandleImipCancel(): void { | |
]) | ||
->setMethods([ | ||
'getCalendarsForPrincipal' | ||
]); | ||
]) | ||
->getMock(); | ||
$principalUri = 'principals/user/pierre'; | ||
$sender = '[email protected]'; | ||
$recipient = '[email protected]'; | ||
$replyTo = null; | ||
$calendar = $this->createMock(ICreateFromString::class); | ||
$calendarData = $this->getVCalendarCancel(); | ||
$calendarData->VEVENT->METHOD = 'CANCEL'; | ||
|
||
$this->time->expects(self::once()) | ||
->method('getTimestamp') | ||
->willReturn(202208219); | ||
->method('getTime') | ||
->willReturn(1628374233); | ||
$manager->expects(self::once()) | ||
->method('getCalendarsForPrincipal') | ||
->with($principalUri) | ||
|
@@ -545,8 +548,8 @@ public function testHandleImipCancel(): void { | |
$calendar->expects(self::once()) | ||
->method('handleIMipMessage') | ||
->with('testname.ics', $calendarData->serialize()); | ||
$result = $this->manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertFalse($result); | ||
$result = $manager->handleIMipCancel($principalUri, $sender, $replyTo, $recipient, $calendarData->serialize()); | ||
$this->assertTrue($result); | ||
} | ||
|
||
private function getVCalendarReply(): Document { | ||
|