public function CalendarLinkTwigExtensionTest::testCalendarLinksFunction in Calendar Link 8
Same name and namespace in other branches
- 2.x tests/src/Kernel/CalendarLinkTwigExtensionTest.php \Drupal\Tests\calendar_link\Kernel\CalendarLinkTwigExtensionTest::testCalendarLinksFunction()
Tests the "calendar_links" Twig function.
File
- tests/
src/ Kernel/ CalendarLinkTwigExtensionTest.php, line 70
Class
- CalendarLinkTwigExtensionTest
- Tests Twig extensions.
Namespace
Drupal\Tests\calendar_link\KernelCode
public function testCalendarLinksFunction() {
$template = "{% set startDate = date('2019-02-24 10:00', 'Etc/UTC') %}{% set endDate = date('2019-02-24 12:00', 'Etc/UTC') %}{% set links = calendar_links('title', startDate, endDate, false, 'description', 'address') %}{% for link in links %}<a href=\"{{ link.url }}\" class=\"calendar-type-{{ link.type_key }}\">Add to {{ link.type_name }}</a>{% endfor %}";
$expected_template_output = '<a href="https://calendar.google.com/calendar/render?action=TEMPLATE&text=title&dates=20190223T230000/20190224T010000&ctz=Etc/UTC&details=description&location=address&sprop=&sprop=name:" class="calendar-type-google">Add to Google</a><a href="data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0d%0aVERSION:2.0%0d%0aBEGIN:VEVENT%0d%0aUID:87b8e999e653acdfff7f6c782d4aa90e%0d%0aSUMMARY:title%0d%0aDTSTART;TZID=Etc/UTC:20190223T230000%0d%0aDTEND;TZID=Etc/UTC:20190224T010000%0d%0aDESCRIPTION:description%0d%0aLOCATION:address%0d%0aEND:VEVENT%0d%0aEND:VCALENDAR" class="calendar-type-ics">Add to iCal</a><a href="https://calendar.yahoo.com/?v=60&view=d&type=20&title=title&st=20190223T230000Z&et=20190224T010000Z&desc=description&in_loc=address" class="calendar-type-yahoo">Add to Yahoo!</a><a href="https://outlook.live.com/owa/?path=/calendar/action/compose&rru=addevent&startdt=20190223T230000&enddt=20190224T010000&subject=title&body=description&location=address" class="calendar-type-webOutlook">Add to Outlook.com</a>';
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
$environment = \Drupal::service('twig');
$output = (string) $environment
->renderInline($template);
$this
->assertEquals($expected_template_output, $output);
}