You are here

public function CalendarLinkTwigExtensionTest::testCalendarLinkFunction 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::testCalendarLinkFunction()

Tests the "calendar_link" Twig function.

File

tests/src/Kernel/CalendarLinkTwigExtensionTest.php, line 56

Class

CalendarLinkTwigExtensionTest
Tests Twig extensions.

Namespace

Drupal\Tests\calendar_link\Kernel

Code

public function testCalendarLinkFunction() {
  $template = "{% set startDate = date('2019-02-24 10:00', 'Etc/UTC') %}{% set endDate = date('2019-02-24 12:00', 'Etc/UTC') %}{% set link = calendar_link('ics', 'title', startDate, endDate, false, 'description', 'location') %}<a href=\"{{ link }}\">Add to calendar</a>";
  $expected_template_output = '<a href="data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0d%0aVERSION:2.0%0d%0aBEGIN:VEVENT%0d%0aUID:a78d4c3cc707c4cde760bad3fbff8ea1%0d%0aSUMMARY:title%0d%0aDTSTART;TZID=Etc/UTC:20190223T230000%0d%0aDTEND;TZID=Etc/UTC:20190224T010000%0d%0aDESCRIPTION:description%0d%0aLOCATION:location%0d%0aEND:VEVENT%0d%0aEND:VCALENDAR">Add to calendar</a>';

  /** @var \Drupal\Core\Template\TwigEnvironment $environment */
  $environment = \Drupal::service('twig');
  $output = (string) $environment
    ->renderInline($template);
  $this
    ->assertEquals($expected_template_output, $output);
}