You are here

public function CalendarLinkTwigExtensionTest::testCalendarLinksFunction in Calendar Link 8

Same name and namespace in other branches
  1. 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\Kernel

Code

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&amp;text=title&amp;dates=20190223T230000/20190224T010000&amp;ctz=Etc/UTC&amp;details=description&amp;location=address&amp;sprop=&amp;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&amp;view=d&amp;type=20&amp;title=title&amp;st=20190223T230000Z&amp;et=20190224T010000Z&amp;desc=description&amp;in_loc=address" class="calendar-type-yahoo">Add to Yahoo!</a><a href="https://outlook.live.com/owa/?path=/calendar/action/compose&amp;rru=addevent&amp;startdt=20190223T230000&amp;enddt=20190224T010000&amp;subject=title&amp;body=description&amp;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);
}