You are here

public function DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceDifferentDay in Recurring Dates Field 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceDifferentDay()
  2. 3.0.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceDifferentDay()
  3. 3.1.x tests/src/Kernel/DateRecurBasicFormatterTest.php \Drupal\Tests\date_recur\Kernel\DateRecurBasicFormatterTest::testFormatterSettingsSummarySampleOccurrenceDifferentDay()

Tests setting summary occurrence sample for different day.

File

tests/src/Kernel/DateRecurBasicFormatterTest.php, line 323

Class

DateRecurBasicFormatterTest
Tests date recur formatter.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testFormatterSettingsSummarySampleOccurrenceDifferentDay() {

  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $efm */
  $efm = $this->container
    ->get('entity_field.manager');
  $definitions = $efm
    ->getBaseFieldDefinitions('dr_entity_test');
  $dateFormatId = $this->dateFormat
    ->id();
  $options = [
    'configuration' => [
      'label' => 'above',
      'type' => 'date_recur_basic_formatter',
      'settings' => [
        'format_type' => $dateFormatId,
        'occurrence_format_type' => $dateFormatId,
        'same_end_date_format_type' => $dateFormatId,
        'interpreter' => $this->interpreter
          ->id(),
        'count_per_item' => FALSE,
        'separator' => '-',
        'show_next' => 10,
      ],
    ],
    'field_definition' => $definitions['dr'],
    'prepare' => TRUE,
    'view_mode' => 'full',
  ];

  /** @var \Drupal\Core\Field\FormatterPluginManager $fieldFormatterManager */
  $fieldFormatterManager = $this->container
    ->get('plugin.manager.field.formatter');
  $instance = $fieldFormatterManager
    ->getInstance($options);
  $summary = $instance
    ->settingsSummary();
  $start = new \DateTime('today 9am');
  $endDifferentDay = clone $start;
  $endDifferentDay
    ->setTime(17, 0, 0);
  $endDifferentDay
    ->modify('+1 day');

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = $this->container
    ->get('renderer');
  $rendered = $renderer
    ->renderRoot($summary['sample_different_day']);

  // Remove newlines from Twig templates.
  $rendered = preg_replace('/\\n/', '', $rendered);
  $this
    ->setRawContent($rendered);
  $this
    ->removeWhiteSpace();
  $pattern = $this->dateFormat
    ->getPattern();
  $this
    ->assertEquals(sprintf('Different day range: %s-%s', $start
    ->format($pattern), $endDifferentDay
    ->format($pattern)), $this
    ->getTextContent());
}