From d0dda99d12e2526c264eba4f606ff6baf9719ac4 Mon Sep 17 00:00:00 2001 From: Torben Hansen Date: Fri, 6 Sep 2024 19:07:42 +0200 Subject: [PATCH] [TASK] Migrate OnlineCalendarViewHelperTest test to functional --- .../Uri/OnlineCalendarViewHelperTest.php | 113 ++++++++++++++++ .../Uri/OnlineCalendarViewHelperTest.php | 126 ------------------ 2 files changed, 113 insertions(+), 126 deletions(-) create mode 100644 Tests/Functional/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php delete mode 100644 Tests/Unit/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php diff --git a/Tests/Functional/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php b/Tests/Functional/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php new file mode 100644 index 000000000..c4311e1e3 --- /dev/null +++ b/Tests/Functional/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php @@ -0,0 +1,113 @@ + [ + 'google', + 'https://www.google.com/calendar/render?action=TEMPLATE&text=A%20test%20event&dates=20210101T180000Z%2B0200%2F20210101T200000Z%2B0200&details=A%20description%20for%20the%20event', + ], + 'outlook' => [ + 'outlook', + 'https://outlook.live.com/calendar/0/deeplink/compose?subject=A%20test%20event&startdt=2021-01-01T18%3A00%3A00%2B0200&enddt=2021-01-01T20%3A00%3A00%2B0200&body=A%20description%20for%20the%20event&path=%2Fcalendar%2Faction%2Fcompose%26rru%3Daddevent', + ], + 'office365' => [ + 'office365', + 'https://outlook.office.com/calendar/0/deeplink/compose?subject=A%20test%20event&startdt=2021-01-01T18%3A00%3A00%2B0200&enddt=2021-01-01T20%3A00%3A00%2B0200&body=A%20description%20for%20the%20event&path=%2Fcalendar%2Faction%2Fcompose%26rru%3Daddevent', + ], + 'yahoo' => [ + 'yahoo', + 'https://calendar.yahoo.com/?title=A%20test%20event&st=20210101T180000Z%2B0200&et=20210101T200000Z%2B0200&desc=A%20description%20for%20the%20event&v=60', + ], + ]; + } + + #[DataProvider('onlineCalendarViewHelperReturnsExpectedResultsDataProvider')] + #[Test] + public function onlineCalendarViewHelperReturnsExpectedResults(string $type, string $expected): void + { + $location = new Location(); + $location->setTitle('A location'); + $location->setAddress('Street 123'); + $location->setZip('12345'); + $location->setCity('A City'); + $location->setCountry('A Country'); + + $event = new Event(); + $event->setTitle('A test event'); + $event->setDescription('A description for the event'); + $event->setStartdate(new DateTime('01.01.2021 18:00:00 CEST')); + $event->setEnddate(new DateTime('01.01.2021 20:00:00 CEST')); + + $extbaseRequestParameters = new ExtbaseRequestParameters(); + $serverRequest = new ServerRequest(); + $serverRequest = $serverRequest->withAttribute('extbase', $extbaseRequestParameters) + ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $extbaseRequest = (new Request($serverRequest)); + $context = $this->get(RenderingContextFactory::class)->create([], $extbaseRequest); + $context->getViewHelperResolver()->addNamespace('e', 'DERHANSEN\\SfEventMgt\\ViewHelpers'); + $context->getTemplatePaths()->setTemplateSource(''); + $context->getVariableProvider()->add('event', $event); + $context->getVariableProvider()->add('type', $type); + + self::assertEquals($expected, (new TemplateView($context))->render()); + } + + #[Test] + public function defaultEnddateIsSetToEventsWithNoEnddate(): void + { + $location = new Location(); + $location->setTitle('A location'); + $location->setAddress('Street 123'); + $location->setZip('12345'); + $location->setCity('A City'); + $location->setCountry('A Country'); + + $event = new Event(); + $event->setTitle('A test event'); + $event->setDescription('A description for the event'); + $event->setStartdate(new DateTime('01.01.2021 19:00:00 CEST')); + + $extbaseRequestParameters = new ExtbaseRequestParameters(); + $serverRequest = new ServerRequest(); + $serverRequest = $serverRequest->withAttribute('extbase', $extbaseRequestParameters) + ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE); + $extbaseRequest = (new Request($serverRequest)); + $context = $this->get(RenderingContextFactory::class)->create([], $extbaseRequest); + $context->getViewHelperResolver()->addNamespace('e', 'DERHANSEN\\SfEventMgt\\ViewHelpers'); + $context->getTemplatePaths()->setTemplateSource(''); + $context->getVariableProvider()->add('event', $event); + $context->getVariableProvider()->add('type', 'google'); + + $expected = 'https://www.google.com/calendar/render?action=TEMPLATE&text=A%20test%20event&dates=20210101T190000Z%2B0200%2F20210101T200000Z%2B0200&details=A%20description%20for%20the%20event'; + self::assertEquals($expected, (new TemplateView($context))->render()); + } +} diff --git a/Tests/Unit/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php b/Tests/Unit/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php deleted file mode 100644 index daf07c8e0..000000000 --- a/Tests/Unit/ViewHelpers/Uri/OnlineCalendarViewHelperTest.php +++ /dev/null @@ -1,126 +0,0 @@ -viewHelper = new OnlineCalendarViewHelper(); - $this->viewHelper->initializeArguments(); - } - - /** - * Teardown - */ - protected function tearDown(): void - { - unset($this->viewHelper); - } - - public static function onlineCalendarViewHelperReturnsExpectedResultsDataProvider(): array - { - return [ - 'google' => [ - 'google', - 'https://www.google.com/calendar/render?action=TEMPLATE&text=A%20test%20event&dates=20210101T180000Z%2B0200%2F20210101T200000Z%2B0200&details=A%20description%20for%20the%20event', - ], - 'outlook' => [ - 'outlook', - 'https://outlook.live.com/calendar/0/deeplink/compose?subject=A%20test%20event&startdt=2021-01-01T18%3A00%3A00%2B0200&enddt=2021-01-01T20%3A00%3A00%2B0200&body=A%20description%20for%20the%20event&path=%2Fcalendar%2Faction%2Fcompose%26rru%3Daddevent', - ], - 'office365' => [ - 'office365', - 'https://outlook.office.com/calendar/0/deeplink/compose?subject=A%20test%20event&startdt=2021-01-01T18%3A00%3A00%2B0200&enddt=2021-01-01T20%3A00%3A00%2B0200&body=A%20description%20for%20the%20event&path=%2Fcalendar%2Faction%2Fcompose%26rru%3Daddevent', - ], - 'yahoo' => [ - 'yahoo', - 'https://calendar.yahoo.com/?title=A%20test%20event&st=20210101T180000Z%2B0200&et=20210101T200000Z%2B0200&desc=A%20description%20for%20the%20event&v=60', - ], - ]; - } - - #[DataProvider('onlineCalendarViewHelperReturnsExpectedResultsDataProvider')] - #[Test] - public function onlineCalendarViewHelperReturnsExpectedResults(string $type, string $expected): void - { - $location = new Location(); - $location->setTitle('A location'); - $location->setAddress('Street 123'); - $location->setZip('12345'); - $location->setCity('A City'); - $location->setCountry('A Country'); - - $event = new Event(); - $event->setTitle('A test event'); - $event->setDescription('A description for the event'); - $event->setStartdate(new DateTime('01.01.2021 18:00:00 CEST')); - $event->setEnddate(new DateTime('01.01.2021 20:00:00 CEST')); - - $result = $this->viewHelper::renderStatic( - [ - 'event' => $event, - 'type' => $type, - ], - function () { - }, - $this->getMockBuilder(RenderingContextInterface::class)->disableOriginalConstructor()->getMock() - ); - self::assertEquals($expected, $result); - } - - #[Test] - public function defaultEnddateIsSetToEventsWithNoEnddate(): void - { - $location = new Location(); - $location->setTitle('A location'); - $location->setAddress('Street 123'); - $location->setZip('12345'); - $location->setCity('A City'); - $location->setCountry('A Country'); - - $event = new Event(); - $event->setTitle('A test event'); - $event->setDescription('A description for the event'); - $event->setStartdate(new DateTime('01.01.2021 19:00:00 CEST')); - - $result = $this->viewHelper::renderStatic( - [ - 'event' => $event, - 'type' => 'google', - ], - function () { - }, - $this->getMockBuilder(RenderingContextInterface::class)->disableOriginalConstructor()->getMock() - ); - $expected = 'https://www.google.com/calendar/render?action=TEMPLATE&text=A%20test%20event&dates=20210101T190000Z%2B0200%2F20210101T200000Z%2B0200&details=A%20description%20for%20the%20event'; - self::assertEquals($expected, $result); - } -}