diff options
Diffstat (limited to 'apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php')
-rw-r--r-- | apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php | 123 |
1 files changed, 37 insertions, 86 deletions
diff --git a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php index cd3269d657c..15b18d6c1b1 100644 --- a/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php +++ b/apps/dav/tests/unit/Controller/InvitationResponseControllerTest.php @@ -3,32 +3,11 @@ declare(strict_types=1); /** - * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Georg Ehrke <oc.list@georgehrke.com> - * @author Joas Schilling <coding@schilljs.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\DAV\Tests\Unit\DAV\Controller; +namespace OCA\DAV\Tests\unit\DAV\Controller; use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; use OCA\DAV\Controller\InvitationResponseController; @@ -39,25 +18,16 @@ use OCP\DB\QueryBuilder\IExpressionBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; use Sabre\VObject\ITip\Message; use Test\TestCase; class InvitationResponseControllerTest extends TestCase { - - /** @var InvitationResponseController */ - private $controller; - - /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */ - private $dbConnection; - - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ - private $request; - - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ - private $timeFactory; - - /** @var InvitationResponseServer|\PHPUnit\Framework\MockObject\MockObject */ - private $responseServer; + private IDBConnection&MockObject $dbConnection; + private IRequest&MockObject $request; + private ITimeFactory&MockObject $timeFactory; + private InvitationResponseServer&MockObject $responseServer; + private InvitationResponseController $controller; protected function setUp(): void { parent::setUp(); @@ -65,9 +35,7 @@ class InvitationResponseControllerTest extends TestCase { $this->dbConnection = $this->createMock(IDBConnection::class); $this->request = $this->createMock(IRequest::class); $this->timeFactory = $this->createMock(ITimeFactory::class); - $this->responseServer = $this->getMockBuilder(InvitationResponseServer::class) - ->disableOriginalConstructor() - ->getMock(); + $this->responseServer = $this->createMock(InvitationResponseServer::class); $this->controller = new InvitationResponseController( 'appName', @@ -78,16 +46,14 @@ class InvitationResponseControllerTest extends TestCase { ); } - public function attendeeProvider(): array { + public static function attendeeProvider(): array { return [ 'local attendee' => [false], 'external attendee' => [true] ]; } - /** - * @dataProvider attendeeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('attendeeProvider')] public function testAccept(bool $isExternalAttendee): void { $this->buildQueryExpects('TOKEN123', [ 'id' => 0, @@ -121,7 +87,7 @@ EOF; $called = false; $this->responseServer->expects($this->once()) ->method('handleITipMessage') - ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) { + ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void { $called = true; $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid); $this->assertEquals('VEVENT', $iTipMessage->component); @@ -149,9 +115,7 @@ EOF; $this->assertTrue($called); } - /** - * @dataProvider attendeeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('attendeeProvider')] public function testAcceptSequence(bool $isExternalAttendee): void { $this->buildQueryExpects('TOKEN123', [ 'id' => 0, @@ -185,7 +149,7 @@ EOF; $called = false; $this->responseServer->expects($this->once()) ->method('handleITipMessage') - ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) { + ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void { $called = true; $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid); $this->assertEquals('VEVENT', $iTipMessage->component); @@ -213,9 +177,7 @@ EOF; $this->assertTrue($called); } - /** - * @dataProvider attendeeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('attendeeProvider')] public function testAcceptRecurrenceId(bool $isExternalAttendee): void { $this->buildQueryExpects('TOKEN123', [ 'id' => 0, @@ -250,7 +212,7 @@ EOF; $called = false; $this->responseServer->expects($this->once()) ->method('handleITipMessage') - ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) { + ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void { $called = true; $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid); $this->assertEquals('VEVENT', $iTipMessage->component); @@ -278,7 +240,7 @@ EOF; $this->assertTrue($called); } - public function testAcceptTokenNotFound() { + public function testAcceptTokenNotFound(): void { $this->buildQueryExpects('TOKEN123', null, 1337); $response = $this->controller->accept('TOKEN123'); @@ -287,7 +249,7 @@ EOF; $this->assertEquals([], $response->getParams()); } - public function testAcceptExpiredToken() { + public function testAcceptExpiredToken(): void { $this->buildQueryExpects('TOKEN123', [ 'id' => 0, 'uid' => 'this-is-the-events-uid', @@ -305,9 +267,7 @@ EOF; $this->assertEquals([], $response->getParams()); } - /** - * @dataProvider attendeeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('attendeeProvider')] public function testDecline(bool $isExternalAttendee): void { $this->buildQueryExpects('TOKEN123', [ 'id' => 0, @@ -341,7 +301,7 @@ EOF; $called = false; $this->responseServer->expects($this->once()) ->method('handleITipMessage') - ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) { + ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void { $called = true; $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid); $this->assertEquals('VEVENT', $iTipMessage->component); @@ -369,29 +329,19 @@ EOF; $this->assertTrue($called); } - public function testOptions() { + public function testOptions(): void { $response = $this->controller->options('TOKEN123'); $this->assertInstanceOf(TemplateResponse::class, $response); $this->assertEquals('schedule-response-options', $response->getTemplateName()); $this->assertEquals(['token' => 'TOKEN123'], $response->getParams()); } - /** - * @dataProvider attendeeProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('attendeeProvider')] public function testProcessMoreOptionsResult(bool $isExternalAttendee): void { - $this->request->expects($this->at(0)) + $this->request->expects($this->once()) ->method('getParam') ->with('partStat') ->willReturn('TENTATIVE'); - $this->request->expects($this->at(1)) - ->method('getParam') - ->with('guests') - ->willReturn('7'); - $this->request->expects($this->at(2)) - ->method('getParam') - ->with('comment') - ->willReturn('Foo bar Bli blub'); $this->buildQueryExpects('TOKEN123', [ 'id' => 0, @@ -410,14 +360,12 @@ VERSION:2.0 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN METHOD:REPLY BEGIN:VEVENT -ATTENDEE;PARTSTAT=TENTATIVE;X-RESPONSE-COMMENT=Foo bar Bli blub;X-NUM-GUEST - S=7:mailto:attendee@foo.bar +ATTENDEE;PARTSTAT=TENTATIVE:mailto:attendee@foo.bar ORGANIZER:mailto:organizer@foo.bar UID:this-is-the-events-uid SEQUENCE:0 REQUEST-STATUS:2.0;Success DTSTAMP:19700101T002217Z -COMMENT:Foo bar Bli blub END:VEVENT END:VCALENDAR @@ -427,7 +375,7 @@ EOF; $called = false; $this->responseServer->expects($this->once()) ->method('handleITipMessage') - ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected) { + ->willReturnCallback(function (Message $iTipMessage) use (&$called, $isExternalAttendee, $expected): void { $called = true; $this->assertEquals('this-is-the-events-uid', $iTipMessage->uid); $this->assertEquals('VEVENT', $iTipMessage->component); @@ -456,7 +404,7 @@ EOF; $this->assertTrue($called); } - private function buildQueryExpects($token, $return, $time) { + private function buildQueryExpects(string $token, ?array $return, int $time): void { $queryBuilder = $this->createMock(IQueryBuilder::class); $stmt = $this->createMock(IResult::class); $expr = $this->createMock(IExpressionBuilder::class); @@ -476,31 +424,34 @@ EOF; ->method('fetch') ->with(\PDO::FETCH_ASSOC) ->willReturn($return); + $stmt->expects($this->once()) + ->method('closeCursor'); + $function = 'functionToken'; $expr->expects($this->once()) ->method('eq') ->with('token', 'namedParameterToken') - ->willReturn('EQ STATEMENT'); + ->willReturn((string)$function); $this->dbConnection->expects($this->once()) ->method('getQueryBuilder') ->with() ->willReturn($queryBuilder); - $queryBuilder->expects($this->at(0)) + $queryBuilder->expects($this->once()) ->method('select') ->with('*') ->willReturn($queryBuilder); - $queryBuilder->expects($this->at(1)) + $queryBuilder->expects($this->once()) ->method('from') ->with('calendar_invitations') ->willReturn($queryBuilder); - $queryBuilder->expects($this->at(4)) + $queryBuilder->expects($this->once()) ->method('where') - ->with('EQ STATEMENT') + ->with($function) ->willReturn($queryBuilder); - $queryBuilder->expects($this->at(5)) - ->method('execute') + $queryBuilder->expects($this->once()) + ->method('executeQuery') ->with() ->willReturn($stmt); |